我似乎無法從保存的檢查點檢索global_step
。我的代碼:Tensorflow無法從檢查點恢復global_step
//(...)
checkpoint_file = tf.train.latest_checkpoint(checkpoint_dir)
saver = tf.train.import_meta_graph("{}.meta".format(checkpoint_file), clear_devices=True)
saver.restore(sess, checkpoint_file)
for v in tf.global_variables():
print(v)
test = tf.get_variable("global_step")
print(test)
結果:
//(...)
Tensor("global_step/read:0", shape=(), dtype=int32)
//(...)
Traceback (most recent call last):
File "train.py", line XXX, in <module>
test = tf.get_variable("global_step")
File "(...)/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 988, in get_variable
custom_getter=custom_getter)
File "(...)/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 890, in get_variable
custom_getter=custom_getter)
File "(...)/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 348, in get_variable
validate_shape=validate_shape)
File "(...)/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 333, in _true_getter
caching_device=caching_device, validate_shape=validate_shape)
File "(...)/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 660, in _get_single_variable
"but instead was +1ms." % (name, shape))
ValueError: Shape of a new variable (global_step) must be fully defined, but instead was <unknown>.
我也global_step:0
和但同樣的結果嘗試。有小費嗎?或者我不應該使用tf.get_variable
?
謝謝