Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tensorflow only: TypeError: Expected int32, got list containing Tensors of type '_Message' instead. #3548

Closed
easyrider opened this issue Aug 23, 2016 · 26 comments
Labels
To investigate Looks like a bug. It needs someone to investigate.

Comments

@easyrider
Copy link

easyrider commented Aug 23, 2016

This occurs only when using TF:

graph = Graph()
graph.add_input(name='input', input_shape=(3, 40, 40))
graph.add_node(Convolution2D(32, 9, 9, activation='relu'), name='conv1', input='input')
graph.add_node(Convolution2D(32, 9, 9, activation='relu'), name='conv2', input='conv1')
graph.add_node(MaxPooling2D(pool_size=(2, 2)), name='pool', input='conv2')
graph.add_node(Dropout(0.25), name='drop', input='pool')
graph.add_node(Flatten(), name='flatten', input='drop')
graph.add_node(Dense(640, activation='relu'), name='ip', input='flatten')
graph.add_node(Dropout(0.5), name='drop_out', input='ip')
graph.add_node(Dense(19, activation='softmax'), name='result', input='drop_out')

I get: TypeError: Expected int32, got list containing Tensors of type '_Message' instead.
Theano version works fine

Traceback (most recent call last):
  File ".py", line 38, in <module>
    graph.add_node(Flatten(), name='flatten', input='drop')
  File "/usr/local/lib/python2.7/dist-packages/keras/legacy/models.py", line 169, in add_node
    layer.add_inbound_node(self._graph_nodes[input])
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 569, in add_inbound_node
    Node.create_node(self, inbound_layers, node_indices, tensor_indices)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 150, in create_node
    output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
  File "/usr/local/lib/python2.7/dist-packages/keras/layers/core.py", line 311, in call
    return K.batch_flatten(x)
  File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 776, in batch_flatten
    x = tf.reshape(x, [-1, prod(shape(x)[1:])])
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 1092, in reshape
    name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/op_def_library.py", line 411, in apply_op
    as_ref=input_arg.is_ref)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 566, in convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/constant_op.py", line 179, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/constant_op.py", line 162, in constant
    tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape))
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_util.py", line 332, in make_tensor_proto
    _AssertCompatible(values, dtype)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_util.py", line 272, in _AssertCompatible
    (dtype.name, repr(mismatch), type(mismatch).__name__))
TypeError: Expected int32, got list containing Tensors of type '_Message' instead.

@jurim0301
Copy link
Contributor

I struggled with the same problem, and solved it.
Change the code of keras/backend/tensorflow_backend.py
from
x = tf.reshape(x, [-1, prod(shape(x)[1:])])
to
x = tf.reshape(x, tf.pack([-1, prod(shape(x)[1:])]))

http://stackoverflow.com/questions/35374958/reshape-tensor-using-placeholder-value

@mongoose54
Copy link

Same problem here. Running Tensorflow-gpu 1.0.0 . Any plans for fixing this on Keras backend?

@dopetard
Copy link

Same problem

@shubhamjain0594
Copy link

Same problem. I suppose it broke again due to some TF update.

@Jeronymous
Copy link

Same problem (different line in the tensorflow_backend.py)
Did anyone find a solution?

Traceback (most recent call last):
File "/home/jlouradour/anaconda/lib/python2.7/site-packages/keras/models.py", line 299, in add
layer.create_input_layer(batch_input_shape, input_dtype)
File "/home/jlouradour/anaconda/lib/python2.7/site-packages/keras/engine/topology.py", line 401, in create_input_layer
self(x)
File "/home/jlouradour/anaconda/lib/python2.7/site-packages/keras/engine/topology.py", line 572, in call
self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
File "/home/jlouradour/anaconda/lib/python2.7/site-packages/keras/engine/topology.py", line 635, in add_inbound_node
Node.create_node(self, inbound_layers, node_indices, tensor_indices)
File "/home/jlouradour/anaconda/lib/python2.7/site-packages/keras/engine/topology.py", line 166, in create_node
output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
File "/home/jlouradour/anaconda/lib/python2.7/site-packages/keras/layers/wrappers.py", line 126, in call
y = self.layer.call(inputs) # (nb_samples * timesteps, ...)
File "/home/jlouradour/anaconda/lib/python2.7/site-packages/keras/layers/core.py", line 814, in call
output = K.dot(x, self.W)
File "/home/jlouradour/anaconda/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 823, in dot
x_shape[:-1] + y_shape[:-2] + y_shape[-1:])
File "/home/jlouradour/src/tensorflow_models/syntaxnet/bazel-bin/syntaxnet/parser_eval.runfiles/external/tf/tensorflow/python/ops/gen_array_ops.py", line 1339, in reshape
name=name)
File "/home/jlouradour/src/tensorflow_models/syntaxnet/bazel-bin/syntaxnet/parser_eval.runfiles/external/tf/tensorflow/python/ops/op_def_library.py", line 444, in apply_op
as_ref=input_arg.is_ref)
File "/home/jlouradour/src/tensorflow_models/syntaxnet/bazel-bin/syntaxnet/parser_eval.runfiles/external/tf/tensorflow/python/framework/ops.py", line 572, in convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/home/jlouradour/src/tensorflow_models/syntaxnet/bazel-bin/syntaxnet/parser_eval.runfiles/external/tf/tensorflow/python/ops/constant_op.py", line 179, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "/home/jlouradour/src/tensorflow_models/syntaxnet/bazel-bin/syntaxnet/parser_eval.runfiles/external/tf/tensorflow/python/ops/constant_op.py", line 162, in constant
tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape))
File "/home/jlouradour/src/tensorflow_models/syntaxnet/bazel-bin/syntaxnet/parser_eval.runfiles/external/tf/tensorflow/python/framework/tensor_util.py", line 354, in make_tensor_proto
_AssertCompatible(values, dtype)
File "/home/jlouradour/src/tensorflow_models/syntaxnet/bazel-bin/syntaxnet/parser_eval.runfiles/external/tf/tensorflow/python/framework/tensor_util.py", line 291, in _AssertCompatible
(dtype.name, repr(mismatch), type(mismatch).name))
TypeError: Expected int32, got list containing Tensors of type '_Message' instead.

@birnbaum
Copy link

The cause of the issue is an API change in tensorflow (tf.concat): https://groups.google.com/a/tensorflow.org/forum/#!msg/discuss/OePXmC9kJ7o/SRErOoYCDQAJ

I think the bug was fixed in 1de4bf1 which is already published under Keras 1.2.2

@mongoose54
Copy link

@birnbaum thanks for the update and helping out.

I just need to report: I uninstalled and reinstalled everything. I am running the latest Keras version 1.2.2 and the latest Tensorflow GPU 1.0.0 . Same issue.

@mayanksatnalika
Copy link

@mongoose54 It works in the keras 2. You will need to manually install it, no pip installation is available.

@mongoose54
Copy link

@mayanksatnalika I just upgraded to Keras 2 but i get errors at other places. Like this one:

inputs = Input((1, img_rows, img_cols))
conv1 = Convolution2D(num_filters, 3, 3, activation='relu', border_mode='same')(inputs)

TypeError: ('Keyword argument not understood:', 'border_mode')

I think that's because of the upcoming changed in the new API?

@AritzBi
Copy link

AritzBi commented Feb 28, 2017

Same probelm here with the latest Tensorflow GPU 1.0.0. Is there any way to fix it without upgrading keras to 2.0?

@MartinThoma
Copy link
Contributor

@rprasadn
Copy link

rprasadn commented Mar 21, 2017

Seeing the same error with TF-0.12.1 and Keras 2.0.1. I had upgraded to latest Keras using pip install.
Resolved the error by uninstalling Keras using pip uninstall Keras and downgrading to Keras 1.2.2. This can be done by downloading Keras-1.2.2.tar.gz from https://pypi.python.org/pypi/Keras/1.2.2 and typing pip install Keras-1.2.2.tar.gz .

Please let us know when the issue is fixed in latest version of Keras so that we can migrate to it.

@shidenggui
Copy link

shidenggui commented Apr 16, 2017

Seeing the same error with TF-0.12.1 and Keras 2.0.3. Someone can fix it?
updated: fix it by update tensorflow to 1.1.0

@OptimusCrime
Copy link

I'm having the same problem with Keras 2.0.3 and TF 1.0.1.

@fchollet
Copy link
Collaborator

Can someone post a simple standalone code snippet to reproduce this issue?

@fchollet fchollet added the To investigate Looks like a bug. It needs someone to investigate. label Apr 17, 2017
@OptimusCrime
Copy link

I got the error with this model:

self.model = Sequential([
    Embedding(
        Config.get('dataset.voc_size_input'),
        1024,
        input_length=self.dim_calculator.get(DimCalculator.INPUT_WIDTH),
        mask_zero=True,
        embeddings_initializer=RandomUniform(minval=math.sqrt(3), maxval=math.sqrt(3))
    ),
    LSTM(256),
    RepeatVector(self.dim_calculator.get(DimCalculator.LABELS_WIDTH))
])

However, I pip installed directly from master and the problem is gone.

@ghost
Copy link

ghost commented May 30, 2017

Solved it by upgrading Tensorflow 1.0 to 1.1.0.

@ndrmahmoudi
Copy link

I have same problem with tensorflow 1.1.0 and keras 2.0.4. Any suggestion?

@Anagha5
Copy link

Anagha5 commented Jul 5, 2017

I'm facing the same issue. Please let me know how to go about it. Keras and tensorflow versions are 1.2.0 and 1.0.0 respectively.

Error :

File "C:\Users\anagha\Anaconda3\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 302, in _AssertCompatible
(dtype.name, repr(mismatch), type(mismatch).name))

TypeError: Expected int32, got <tensorflow.python.ops.variables.Variable object at 0x000001E760125860> of type 'Variable' instead.

@ghost
Copy link

ghost commented Jul 5, 2017

upgrade Tensorflow 1.0 to 1.1.0.

@Anagha5
Copy link

Anagha5 commented Jul 5, 2017

Still facing the same issue, after upgrading from 1.0 to 1.1.0

@gv22ga
Copy link

gv22ga commented Jul 12, 2017

works with Tensorflow 1.1 and Keras 1.2.2

@haossr
Copy link

haossr commented Aug 3, 2017

Same issue for Keras 2.0.6. Resolved by updating TensorFlow to 1.2.1.

@ssd-556u
Copy link

ssd-556u commented Sep 5, 2017

@Anagha5 Please review your code if there still is the same problem —— the reverse about the parameter of tf.concat()

@Remorax
Copy link

Remorax commented Jul 17, 2018

I'm facing the same error, on python version 3.7.0, keras version 2.2.0 and tensorflow version 0.12.0. I've tried all the solutions listed above, I've uninstalled and reinstalled keras and tf, but I'm still facing the same error :(
Can someone please help me out?

@AritzBi
Copy link

AritzBi commented Jul 17, 2018

@Remorax have you tried upgrading tensorflow version? 0.12 it's a very old version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
To investigate Looks like a bug. It needs someone to investigate.
Projects
None yet
Development

No branches or pull requests