BUPTLdy / Sentiment-Analysis

Chinese Shopping Reviews sentiment analysis
http://buptldy.github.io/2016/07/20/2016-07-20-sentiment%20analysis/
351 stars 168 forks source link

使用lstm时,出现dtype的错误 #8

Closed sichun closed 7 years ago

sichun commented 7 years ago

我用python2.7 出现一下错误 其他环境依照要求配置,若该用python3.5 也是类似dtype的问题 File "predict.py", line 23, in lstm_predict(sentence) File "code/Sentiment_lstm.py", line 179, in lstm_predict model = model_from_yaml(yaml_string) File "/Users/gt/Downloads/enter/envs/py27/lib/python2.7/site-packages/keras/models.py", line 200, in model_from_yaml return layer_from_config(config, custom_objects=custom_objects) File "/Users/gt/Downloads/enter/envs/py27/lib/python2.7/site-packages/keras/utils/layer_utils.py", line 40, in layer_from_config return layer_class.from_config(config['config']) File "/Users/gt/Downloads/enter/envs/py27/lib/python2.7/site-packages/keras/models.py", line 1080, in from_config model.add(layer) File "/Users/gt/Downloads/enter/envs/py27/lib/python2.7/site-packages/keras/models.py", line 327, in add output_tensor = layer(self.outputs[0]) File "/Users/gt/Downloads/enter/envs/py27/lib/python2.7/site-packages/keras/engine/topology.py", line 543, in call self.build(input_shapes[0]) File "/Users/gt/Downloads/enter/envs/py27/lib/python2.7/site-packages/keras/layers/recurrent.py", line 763, in build self.W = K.concatenate([self.W_i, self.W_f, self.W_c, self.W_o]) File "/Users/gt/Downloads/enter/envs/py27/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 1222, in concatenate return tf.concat(axis, [to_dense(x) for x in tensors]) File "/Users/gt/Downloads/enter/envs/py27/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 1043, in concat dtype=dtypes.int32).get_shape( File "/Users/gt/Downloads/enter/envs/py27/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 676, in convert_to_tensor as_ref=False) File "/Users/gt/Downloads/enter/envs/py27/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 741, in internal_convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "/Users/gt/Downloads/enter/envs/py27/lib/python2.7/site-packages/tensorflow/python/framework/constant_op.py", line 113, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name) File "/Users/gt/Downloads/enter/envs/py27/lib/python2.7/site-packages/tensorflow/python/framework/constant_op.py", line 102, in constant tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape)) File "/Users/gt/Downloads/enter/envs/py27/lib/python2.7/site-packages/tensorflow/python/framework/tensor_util.py", line 374, in make_tensor_proto _AssertCompatible(values, dtype) File "/Users/gt/Downloads/enter/envs/py27/lib/python2.7/site-packages/tensorflow/python/framework/tensor_util.py", line 302, in _AssertCompatible (dtype.name, repr(mismatch), type(mismatch).name)) TypeError: Expected int32, got <tf.Variable 'lstm_1_W_i:0' shape=(100, 50) dtype=float32_ref> of type 'Variable' instead.

guoliang1992 commented 6 years ago

我也遇到这个问题了 请问是什么原因呢?