Restoring a tensorflow model for finetuning, with "slim.learning.train"
<p>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 
<code>Init operations did not make model ready.</code></p>

<p>I do the training with:</p>

<pre><code>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)
</code></pre>

<p>I tried 3 alternatives:</p>

<h3>#1</h3>

<p>Following <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/training/session_manager.py#L183" rel="nofollow">this doc</a></p>

<pre><code>model.init_fn = None
</code></pre>

<h3>#2</h3>

<pre><code>with g.as_default():
    model_path = tf.train.latest_checkpoint(train_dir)
    if model_path:
        def restore_fn(sess):
            tf.logging.info(
                "Restoring SA&amp;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
</code></pre>

<h3>#3</h3>

<pre><code>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
</code></pre>