2016-05-31 132 views
3

在使用Tensorflow时,我试图使用检查点文件恢复CIFAR10培训。参考一些其他文章,我尝试了tf.train.Saver()。恢复没有成功。有人能告诉我如何继续?从Tensorflow CIFAR10tensorflow cifar10从检查点文件恢复培训

def train(): 
    # methods to build graph from the cifar10_train.py 
    global_step = tf.Variable(0, trainable=False) 
    images, labels = cifar10.distorted_inputs() 
    logits = cifar10.inference(images) 
    loss = cifar10.loss(logits, labels) 
    train_op = cifar10.train(loss, global_step) 
    saver = tf.train.Saver(tf.all_variables()) 
    summary_op = tf.merge_all_summaries() 

    init = tf.initialize_all_variables() 
    sess = tf.Session(config=tf.ConfigProto(log_device_placement=FLAGS.log_device_placement)) 
    sess.run(init) 


    print("FLAGS.checkpoint_dir is %s" % FLAGS.checkpoint_dir) 

    if FLAGS.checkpoint_dir is None: 
    # Start the queue runners. 
    tf.train.start_queue_runners(sess=sess) 
    summary_writer = tf.train.SummaryWriter(FLAGS.train_dir, sess.graph) 
    else: 
    # restoring from the checkpoint file 
    ckpt = tf.train.get_checkpoint_state(FLAGS.checkpoint_dir) 
    tf.train.Saver().restore(sess, ckpt.model_checkpoint_path) 

    # cur_step prints out well with the checkpointed variable value 
    cur_step = sess.run(global_step); 
    print("current step is %s" % cur_step) 

    for step in xrange(cur_step, FLAGS.max_steps): 
    start_time = time.time() 
    # **It stucks at this call ** 
    _, loss_value = sess.run([train_op, loss]) 
    # below same as original 

回答

2

问题

代码片段似乎是这条线:

tf.train.start_queue_runners(sess=sess) 

...只有当FLAGS.checkpoint_dir is None执行。如果您要从检查点恢复,您仍然需要启动队列运行程序。

注意,我建议你开始排队参赛者创建tf.train.Saver(由于代码的发布版本中的竞争条件),所以更好的结构将是:

if FLAGS.checkpoint_dir is not None: 
    # restoring from the checkpoint file 
    ckpt = tf.train.get_checkpoint_state(FLAGS.checkpoint_dir) 
    tf.train.Saver().restore(sess, ckpt.model_checkpoint_path) 

# Start the queue runners. 
tf.train.start_queue_runners(sess=sess) 

# ... 

for step in xrange(cur_step, FLAGS.max_steps): 
    start_time = time.time() 
    _, loss_value = sess.run([train_op, loss]) 
    # ... 
+0

谢谢你为了答案!它解决了这个问题。我认为queue_runner负责创建输入图像(通过失真),并且这不是从检查点文件还原的必要步骤。 – emerson