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

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.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 26 (3 by maintainers)

Most upvoted comments

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.

Solved it by upgrading Tensorflow 1.0 to 1.1.0.

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

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

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 1de4bf1b5989f76e377f0b8022b41773a354ba99 which is already published under Keras 1.2.2

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