【发布时间】:2017-02-05 15:21:42
【问题描述】:
我尝试保存我的模型,然后尝试恢复它,但似乎 tensorflow 无法找到匹配文件的位置:-
保存模型输出的代码:-
import tensorflow as tf
save_file = 'model.ckpt'
weights = tf.Variable(tf.truncated_normal([2, 3]))
bias = tf.Variable(tf.truncated_normal([3]))
saver = tf.train.Saver()
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
saver.save(sess, save_file)
恢复模型的代码
import tensorflow as tf
save_file = 'model.ckpt'
tf.reset_default_graph()
weights = tf.Variable(tf.truncated_normal([2, 3]))
bias = tf.Variable(tf.truncated_normal([3]))
saver = tf.train.Saver()
with tf.Session() as sess:
saver.restore(sess, 'model.ckpt')
我遇到以下错误:-
W tensorflow/core/framework/op_kernel.cc:975] 未找到:TensorSliceReader 构造函数不成功:找不到任何与 model.ckpt 匹配的文件
W tensorflow/core/framework/op_kernel.cc:975] 未找到:TensorSliceReader 构造函数不成功:找不到任何与 model.ckpt 匹配的文件
【问题讨论】:
-
如果将
'./model.ckpt'传递给saver.restore()是否有效? -
成功了!我猜张量流在加载时希望提供路径,但在保存时会保存到当前目录。
-
是的……这是一个很奇怪的不一致,我担心。 This issue 正在跟踪问题,但它在 TensorFlow 1.0 中仍然处于打开状态。
标签: tensorflow