我正在尝试保存和恢复张量流模型的参数。该代码确实将参数保存到给定的路径,但是当我尝试还原最后一个检查点,执行操作然后再次保存时,它不会返回最后一个检查点。我该怎么办?
import tensorflow as tf
import os
v1 = tf.Variable(1.32, name="v1")
v2 = tf.Variable(1.33, name="v2")
saver = tf.train.Saver()
init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
print (v2.eval(sess))
saver.save(sess, "/tmp/model")
print("Model restored.")
for i in range(10):
ckpt = tf.train.get_checkpoint_state(os.path.dirname('/tmp/'))
print(ckpt)
sess = tf.Session()
if(ckpt and ckpt.model_checkpoint_path):
saver.restore(sess, ckpt.model_checkpoint_path)
x = sess.run("v2:0")
x = x + 1
print(x)
saver.save(sess, "/tmp/model", global_step = i)
sess.close()