TypeError Expected int32 got tensorflow python ops variables Variable object at 0x117ea3a10 of t

网友投稿 1039 2022-08-23

TypeError Expected int32 got tensorflow python ops variables Variable object at 0x117ea3a10 of t

TypeError Expected int32 got tensorflow python ops variables Variable object at 0x117ea3a10 of t

今天在运行别人的demo程序的时候,发现了一个错误,百思不得其解,明明没干啥,运行别人的demo也出错,我的错误信息为

Traceback (most recent call last): File "model.py", line 23, in model.add(LSTM(100)) File "//anaconda/lib/python2.7/site-packages/keras/models.py", line 332, in add output_tensor = layer(self.outputs[0]) File "//anaconda/lib/python2.7/site-packages/keras/engine/topology.py", line 546, in __call__ self.build(input_shapes[0]) File "//anaconda/lib/python2.7/site-packages/keras/layers/recurrent.py", line 784, in build self.W = K.concatenate([self.W_i, self.W_f, self.W_c, self.W_o]) File "//anaconda/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 1427, in concatenate return tf.concat(axis, [to_dense(x) for x in tensors]) File "//anaconda/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 1029, in concat dtype=dtypes.int32).get_shape( File "//anaconda/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 637, in convert_to_tensor as_ref=False) File "//anaconda/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 702, in internal_convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "//anaconda/lib/python2.7/site-packages/tensorflow/python/framework/constant_op.py", line 110, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name) File "//anaconda/lib/python2.7/site-packages/tensorflow/python/framework/constant_op.py", line 99, in constant tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape)) File "//anaconda/lib/python2.7/site-packages/tensorflow/python/framework/tensor_util.py", line 367, in make_tensor_proto _AssertCompatible(values, dtype) File "//anaconda/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 of type 'Variable' instead.

我的代码为:

# LSTM for sequence classification in the IMDB datasetimport numpyfrom keras.datasets import imdbfrom keras.models import Sequentialfrom keras.layers import Densefrom keras.layers import LSTMfrom keras.layers.embeddings import Embeddingfrom keras.preprocessing import sequence# fix random seed for reproducibilitynumpy.random.seed(7)# load the dataset but only keep the top n words, zero the resttop_words = 5000(X_train, y_train), (X_test, y_test) = imdb.load_data(nb_words=top_words)# truncate and pad input sequencesmax_review_length = 500X_train = sequence.pad_sequences(X_train, maxlen=max_review_length)X_test = sequence.pad_sequences(X_test, maxlen=max_review_length)# create the modelembedding_vecor_length = 32model = Sequential()model.add(Embedding(top_words, embedding_vecor_length, input_length=max_review_length))model.add(LSTM(100))model.add(Dense(1, activation='sigmoid'))model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])print(model.summary())model.fit(X_train, y_train, nb_epoch=3, batch_size=64)# Final evaluation of the modelscores = model.evaluate(X_test, y_test, verbose=0)print("Accuracy: %.2f%%" % (scores[1]*100))

环境为

mac keras 1.2.2 tensorflow (1.0.1)

解决方法:

pip install keras --upgrade

升级到2.1.2,然后就运行成功了。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:ubuntu16.04 stgcn运行报错Did you forget to `#include <pybind11/stl.h>`? Or <pybind11/complex.h>, <pybind
下一篇:Swift3新特性(swift3参数)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~