我有两个模型文件model.ckpt-10 model.ckpt-10.meta 恢复图表这两个选项有什么区别? slim.assign_from_checkpoint_fn()和saver.restore(sess,ckptfile)
它们都会导致类似的未初始化变量异常。
这是片段和例外。
metafile = '/tmp/tfslim_model/model.ckpt-10.meta'
ckptfile = '/tmp/tfslim_model/model.ckpt-10'
def vars_from_ckpt(metafile, ckptfile, sess):
saver = tf.train.import_meta_graph(metafile) #
l = tf.get_collection(tf.GraphKeys.VARIABLES)
slim.assign_from_checkpoint_fn( ckptfile, l) #
for v in l: print v.name ,v.eval()
return l
#saver.restore(sess, ckptfile) #restores but bombs later do
with tf.Session() as sess:
l = vars_from_ckpt(metafile, ckptfile, sess)
sess.run(l)
Traceback (most recent call last):
File "test_wrk.py", line 26, in <module>
l = vars_from_ckpt(metafile, ckptfile, sess)
File "test_wrk.py", line 20, in vars_from_ckpt
slim.assign_from_checkpoint_fn( ckptfile, l) #
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/framework/python/ops/variables.py", line 573, in assign_from_checkpoint_fn
saver = tf_saver.Saver(var_list, reshape=reshape_variables)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 972, in __init__
self.build()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1001, in build
restore_sequentially=self._restore_sequentially)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 618, in build
assert restore_op.name.endswith("restore_all"), restore_op.name
AssertionError: save/restore_all_1
#exception happens here
with tf.Session() as sess:
l = vars_from_ckpt(metafile, ckptfile, sess)
sess.run(l)
saver.restore(sess, ckptfile)
似乎打印变量和值会导致以下内容。 tensorflow.python.framework.errors.FailedPreconditionError:尝试使用未初始化的值kaggle_test / conv1_7_7 / biases_1