我是Tensorflow的新手(实际上是机器学习),我跟随
https://github.com/seyedsaeidmasoumzadeh/Predict-next-word/blob/master/main.py中的代码,我对此代码所做的更改是将模型保存在末尾
saver.save(sess, 'C:\\Naresh\\SpecialProject\\MachineLearning-II\\Model\\RNN_WordPrediction\\Model')
现在我想使用保存的模型来预测新单词,但是我收到了错误:
pred = sess.run(Prediction, feed_dict={X:x})
TypeError: unhashable type: 'list'
下面是使用保存的模型预测下一个单词的代码,请你帮我。
with tf.Session() as sess:
x_ip = np.array(
[[38, 0, 1], [0, 1, 17], [1, 17, 18], [17, 18, 6], [18, 6, 19], [6, 19, 39], [19, 39, 4], [39, 4, 40],
[4, 40, 41], [40, 41, 42], [41, 42, 43], [42, 43, 7], [43, 7, 44], [7, 44, 4], [44, 4, 45], [4, 45, 46],
[45, 46, 47], [46, 47, 20], [47, 20, 0]])
x = np.array(x_ip.reshape(19, 3, 1))
model = tf.train.import_meta_graph('C:\\Naresh\\SpecialProject\\MachineLearning-II\\Model\\RNN_WordPrediction\\Model.meta')
model.restore(sess,
tf.train.latest_checkpoint('C:\\Naresh\\SpecialProject\\MachineLearning-II\\Model\\RNN_WordPrediction\\.'))
graph = tf.get_default_graph()
X = tf.get_collection('input:0')
Prediction = graph.get_tensor_by_name('prediction:0')
pred = sess.run(Prediction, feed_dict={X:x})
print(pred)
知道如何解决这个问题吗?
答案 0 :(得分:0)
如果将[below1]
更改为[below2]
,它将很好地工作。
[below1]
X = tf.get_collection('input:0')
[below2]
X = tf.get_collection('input:0')[0]