TensorFlow:恢复模型
TensorFlow: Restoring a model
我试图在训练结束时保存我的模型,并在每次训练开始时恢复它。我只是按照 所做的。
saver = tf.train.Saver()
with tf.Session(graph=graph) as session:
# Initializate the weights and biases
tf.global_variables_initializer().run()
new_saver = tf.train.import_meta_graph('model.meta')
new_saver.restore(sess,tf.train.latest_checkpoint('./'))
W1 = session.run(W)
print(W1)
for curr_epoch in range(num_epochs):
train_cost = train_ler = 0
start = time.time()
for batch in range(num_batches_per_epoch):
...Some training...
W2 = session.run(W)
print(W2)
save_path = saver.save(session, "models/model")
但它给出以下错误:
---> new_saver.restore(session, tf.train.latest_checkpoint('./'))
SystemError: <built-in function TF_Run> returned a result with an error set
有人能帮帮我吗?非常感谢!
如果您要使用 ./ 加载,您必须确保您的控制台(用于启动 python 程序)实际上设置在该目录 (models/) 上。
但在那种情况下,它会将您的新数据保存在一个新目录中。所以加载 ./models/ 而不是
(此外,您不需要启动变量,恢复会为您完成。)
我试图在训练结束时保存我的模型,并在每次训练开始时恢复它。我只是按照
saver = tf.train.Saver()
with tf.Session(graph=graph) as session:
# Initializate the weights and biases
tf.global_variables_initializer().run()
new_saver = tf.train.import_meta_graph('model.meta')
new_saver.restore(sess,tf.train.latest_checkpoint('./'))
W1 = session.run(W)
print(W1)
for curr_epoch in range(num_epochs):
train_cost = train_ler = 0
start = time.time()
for batch in range(num_batches_per_epoch):
...Some training...
W2 = session.run(W)
print(W2)
save_path = saver.save(session, "models/model")
但它给出以下错误:
---> new_saver.restore(session, tf.train.latest_checkpoint('./'))
SystemError: <built-in function TF_Run> returned a result with an error set
有人能帮帮我吗?非常感谢!
如果您要使用 ./ 加载,您必须确保您的控制台(用于启动 python 程序)实际上设置在该目录 (models/) 上。 但在那种情况下,它会将您的新数据保存在一个新目录中。所以加载 ./models/ 而不是
(此外,您不需要启动变量,恢复会为您完成。)