gpt4 book ai didi

tensorflow 错误: restore checkpoint file

转载 作者:行者123 更新时间:2023-12-03 00:36:27 24 4
gpt4 key购买 nike

我建立了自己的卷积神经网络,在其中跟踪所有可训练变量的移动平均值(tensorflow 1.0):

variable_averages = tf.train.ExponentialMovingAverage(
0.9999, global_step)
variables_averages_op = variable_averages.apply(tf.trainable_variables())
train_op = tf.group(apply_gradient_op, variables_averages_op)
saver = tf.train.Saver(tf.global_variables(), max_to_keep=10)
summary_op = tf.summary.merge(summaries)
init = tf.global_variables_initializer()
sess = tf.Session(config=tf.ConfigProto(
allow_soft_placement=True,
log_device_placement=False))
sess.run(init)
# start queue runners
tf.train.start_queue_runners(sess=sess)

summary_writer = tf.summary.FileWriter(FLAGS.train_dir, sess.graph)

# training loop
start_time = time.time()
for step in range(FLAGS.max_steps):
_, loss_value = sess.run([train_op, loss])
duration = time.time() - start_time
start_time = time.time()
assert not np.isnan(loss_value), 'Model diverged with loss = NaN'

if step % 1 == 0:
# print current model status
num_examples_per_step = FLAGS.batch_size * FLAGS.num_gpus
examples_per_sec = num_examples_per_step/duration
sec_per_batch = duration/FLAGS.num_gpus
format_str = '{} step{}, loss {}, {} examples/sec, {} sec/batch'
print(format_str.format(datetime.now(), step, loss_value, examples_per_sec, sec_per_batch))
if step % 50 == 0:
summary_str = sess.run(summary_op)
summary_writer.add_summary(summary_str, step)
if step % 10 == 0 or step == FLAGS.max_steps:
print('save checkpoint')
# save checkpoint file
checkpoint_file = os.path.join(FLAGS.train_dir, 'model.ckpt')
saver.save(sess, checkpoint_file, global_step=step)

这工作正常并且检查点文件已保存(保护程序版本 V2)。然后我尝试在另一个脚本中恢复检查点以评估模型。我有这段代码

# Restore the moving average version of the learned variables for eval.
variable_averages = tf.train.ExponentialMovingAverage(
MOVING_AVERAGE_DECAY)
variables_to_restore = variable_averages.variables_to_restore()
saver = tf.train.Saver(variables_to_restore)

我收到错误“NotFoundError(请参阅上面的回溯):在检查点中找不到 key conv1/Variable/ExponentialMovingAverage”,其中 conv1/variable/是变量范围。

甚至在我尝试恢复变量之前就会发生此错误。能帮忙解决一下吗?

提前致谢

犹大

最佳答案

我是这样解决的:
在图表中创建第二个 ExponentialMovingAverage(...) 之前调用 tf.reset_default_graph()

# reset the graph before create a new ema
tf.reset_default_graph()
# Restore the moving average version of the learned variables for eval.
variable_averages = tf.train.ExponentialMovingAverage(MOVING_AVERAGE_DECAY)
variables_to_restore = variable_averages.variables_to_restore()
saver = tf.train.Saver(variables_to_restore)

我花了两个小时...

关于 tensorflow 错误: restore checkpoint file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42697800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com