Keras:“TypeError:期望的int32,得到的列表包含'_Message'类型的张量。”

时间:2017-05-16 23:42:35

标签: python python-3.x tensorflow keras

我正在尝试在Keras训练LSTM模型,并且我想出了上述错误。以下重现错误:

from keras.layers import  LSTM
from keras.models import Sequential

model = Sequential()
model.add(LSTM(128, input_shape=(1000,1000)))

我正在使用Python 3.4,Keras 2.0.4和TensorFlow后端,版本0.12.1

这是追溯:

  File "test.py", line 6, in <module>
    model.add(LSTM(128, input_shape=(1000,1000)))
  File "/usr/local/lib/python3.4/dist-packages/keras/models.py", line 433, in add
    layer(x)
  File "/usr/local/lib/python3.4/dist-packages/keras/layers/recurrent.py", line 243, in __call__
    return super(Recurrent, self).__call__(inputs, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/keras/engine/topology.py", line 558, in __call__
    self.build(input_shapes[0])
  File "/usr/local/lib/python3.4/dist-packages/keras/layers/recurrent.py", line 1012, in build
    constraint=self.bias_constraint)
  File "/usr/local/lib/python3.4/dist-packages/keras/legacy/interfaces.py", line 88, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/keras/engine/topology.py", line 391, in add_weight
    weight = K.variable(initializer(shape), dtype=dtype, name=name)
  File "/usr/local/lib/python3.4/dist-packages/keras/layers/recurrent.py", line 1004, in bias_initializer
    self.bias_initializer((self.units * 2,), *args, **kwargs),
  File "/usr/local/lib/python3.4/dist-packages/keras/backend/tensorflow_backend.py", line 1681, in concatenate
    return tf.concat([to_dense(x) for x in tensors], axis)
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/ops/array_ops.py", line 1075, in concat
    dtype=dtypes.int32).get_shape(
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/ops.py", line 669, in convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/constant_op.py", line 176, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/constant_op.py", line 165, in constant
    tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/tensor_util.py", line 367, in make_tensor_proto
    _AssertCompatible(values, dtype)
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/tensor_util.py", line 302, in _AssertCompatible
    (dtype.name, repr(mismatch), type(mismatch).__name__))
TypeError: Expected int32, got list containing Tensors of type '_Message' instead.

我见过一些人报告同样的问题,例如Tensorflow Slim: TypeError: Expected int32, got list containing Tensors of type '_Message' instead。似乎需要切换concat函数存在问题,但此处它已经是正确的形式。

知道原因是什么吗?

0 个答案:

没有答案