使用“slim.learning.train"恢复用于微调的张量流模型 [英] Restoring a tensorflow model for finetuning, with "slim.learning.train"
问题描述
在 tensorflow 中,使用 slim.learning.train (TF 0.11),我想从检查点恢复模型并继续训练.该模型有一个成功的训练课程,我想对其进行微调.但是,当我这样做时,TF 会因错误而崩溃初始化操作没有使模型准备好.
In tensorflow, with slim.learning.train (TF 0.11), I would like to restore a model from a checkpoint and continue the training. The model had a successful training session, and I would like to fine tune it. However, when I do that, TF crash with an error
Init operations did not make model ready.
我进行培训:
tf.contrib.slim.learning.train(
train_op,
train_dir,
log_every_n_steps=FLAGS.log_every_n_steps,
graph=g,
global_step=model.global_step,
number_of_steps=FLAGS.number_of_steps,
init_fn=model.init_fn,
saver=model.saver,
session_config=session_config)
我尝试了 3 种选择:
I tried 3 alternatives:
遵循本文档
model.init_fn = None
#2
with g.as_default():
model_path = tf.train.latest_checkpoint(train_dir)
if model_path:
def restore_fn(sess):
tf.logging.info(
"Restoring SA&T variables from checkpoint file %s",
restore_fn.model_path)
model.saver.restore(sess, restore_fn.model_path)
restore_fn.model_path = model_path
model.init_fn = restore_fn
else:
model.init_fn = None
#3
with g.as_default():
model_path = tf.train.latest_checkpoint(train_dir)
if model_path:
variables_to_restore = tf.contrib.slim.get_variables_to_restore()
model.init_fn = tensorflow.contrib.framework.assign_from_checkpoint_fn(
model_path, variables_to_restore)
else:
model.init_fn = None
推荐答案
问题已解决.发生这种情况是因为在模型构建之后直接定义了保护程序 (tf.train.Saver).
Issue was solved. It happened because the saver (tf.train.Saver) was defined directly after the model build.
相反,按照 train op 定义来定义它,解决了这个问题.
Instead, defining it following the train op definition, solved the issue.
这篇关于使用“slim.learning.train"恢复用于微调的张量流模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!