简体   繁体   English

Tensorflow不可散列类型:“列表”

[英]Tensorflow unhashable type: 'list'

I am new to Tensorflow (well actually to Machine Learning), I was following the code in https://github.com/seyedsaeidmasoumzadeh/Predict-next-word/blob/master/main.py , the change i made to this code is to save the model at the end 我是Tensorflow的新手(实际上是机器学习的人),我遵循https://github.com/seyedsaeidmasoumzadeh/Predict-next-word/blob/master/main.py中的代码,我对此代码进行了更改是最后保存模型
saver.save(sess, 'C:\\\\Naresh\\\\SpecialProject\\\\MachineLearning-II\\\\Model\\\\RNN_WordPrediction\\\\Model')

Now I would like to use the saved model to predict the new word, however I am getting the error: 现在,我想使用保存的模型来预测新单词,但是我遇到了错误:

pred = sess.run(Prediction, feed_dict={X:x})
TypeError: unhashable type: 'list' 

Below is the code to predict the next word using the saved model, could you please help me here. 下面是使用保存的模型预测下一个单词的代码,请您在这里帮助我。

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)

Any idea how to fix this? 任何想法如何解决这个问题?

If [below1] were changed to [below2] , it will work well. 如果[below1] [below2]更改为[below2] ,它将很好地工作。

[below1]
X = tf.get_collection('input:0')

[below2]
X = tf.get_collection('input:0')[0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM