我有一个具有3个隐藏层的基本模型,如下所示。我正在尝试使用tf.train.Saver()保存学习到的参数,然后使用恢复的模型进行恢复和预测。我能够成功保存模型。但是我无法恢复和预测。我正在尝试以这种方式恢复和预测:
with tf.Session() as sess:
model_saver = tf.train.import_meta_graph('./model4/model.ckpt.meta')
model_saver.restore(sess, './model4/model.ckpt')
X = tf.get_collection('X')[0] #dont know why index is needed, I took it from somewhere
Z7 = tf.get_collection("Z7")[0]
print("Model restored.")
#prediction!
prediction = sess.run(Z7, feed_dict={X: X_test})
print(prediction)
这就是我模型中的内容。
#Forward prop
Z4 = tf.contrib.layers.fully_connected(X, 250)
Z5 = tf.contrib.layers.fully_connected(Z4, 250)
Z6 = tf.contrib.layers.fully_connected(Z5, 25)
Z7 = tf.contrib.layers.fully_connected(Z6, 1, activation_fn=None)
#saving
saver = tf.train.Saver()
save_path = saver.save(sess, path)
我使用[0]的列表索引超出范围。删除它时,我得到“不可散列的类型:'列表'”。请帮助