【问题标题】:Restoring a tensorflow model for finetuning, with "slim.learning.train"使用“slim.learning.train”恢复用于微调的张量流模型
【发布时间】:2016-10-20 06:43:54
【问题描述】:

在张量流中,使用 slim.learning.train (TF 0.11),我想从检查点恢复模型并继续训练。该模型进行了成功的培训,我想对其进行微调。但是,当我这样做时,TF 崩溃并出现错误 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 种选择:

#1

关注this doc

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

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    问题已解决。发生这种情况是因为保护程序 (tf.train.Saver) 是在模型构建后直接定义的。

    相反,按照训练操作定义定义它,解决了这个问题。

    【讨论】:

    • 你能分享你的代码吗?我仍然有这个问题。非常感谢!
    • 我在火车操作之前定义了保护程序,它可以工作。你有证据证明这个说法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-10
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多