OutOfRangeError异常:tensorflow迭代器不运行之间重新初始化

问题描述 投票:0回答:1

我通过tensorflow微调的盗梦空间模型下面的设置,我喂批次tf.DatasetAPI。然而,每次我试图培养这种模式(之前成功地检索所有批次),我得到一个OutOfRangeError异常声称迭代器已耗尽:

Caught OutOfRangeError. Stopping Training. End of sequence
     [[node IteratorGetNext (defined at <ipython-input-8-c768436e70d8>:13)  = IteratorGetNext[output_shapes=[[?,224,224,3], [?,1]], output_types=[DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](OneShotIterator)]]
with tf.Graph().as_default():

我创建了一个功能硬编码批次饲料中作为get_batch的结果,而这种运行和收敛没有任何问题,导致我相信,图形和会话代码工作正常。我还测试了get_batch功能在会话进行迭代,这将导致没有任何错误。我期望的行为是重新开始训练(特别是与正在重置笔记本等)会产生在数据集新鲜迭代器。

代码火车模型:

with tf.Graph().as_default():

    tf.logging.set_verbosity(tf.logging.INFO)
    images, labels = get_batch(filenames=tf_train_record_path+train_file)
    # Create the model, use the default arg scope to configure the batch norm parameters.
    with slim.arg_scope(inception.inception_v1_arg_scope()):
        logits, ax = inception.inception_v1(images, num_classes=1, is_training=True)

    # Specify the loss function:
    tf.losses.mean_squared_error(labels,logits)
    total_loss = tf.losses.get_total_loss()
    tf.summary.scalar('losses/Total_Loss', total_loss)


     # Specify the optimizer and create the train op:
    optimizer = tf.train.AdamOptimizer(learning_rate=0.01)
    train_op = slim.learning.create_train_op(total_loss, optimizer)

    # Run the training:
    final_loss = slim.learning.train(
        train_op,
        logdir=train_dir,
        init_fn=get_init_fn(),
        number_of_steps=1)

代码来获得使用数据集批

def get_batch(filenames):
    dataset = tf.data.TFRecordDataset(filenames=filenames)

    dataset = dataset.map(parse)
    dataset = dataset.batch(2)

    iterator = dataset.make_one_shot_iterator()
    data_X, data_y = iterator.get_next()

    return data_X, data_y 

This以前问问题,就像我遇到的问题,但是,我没有使用batch_join电话。我不是,如果这是slim.learning.train一个问题,从检查点,或范围恢复。任何帮助,将不胜感激!

python tensorflow dataset slim
1个回答
0
投票

您的输入管道看起来确定。该问题可能与损坏TFRecords文件。你可以试试你的代码的随机数据,或使用你的作品与tf.data.Dataset.from_tensor_slices() numpy的阵列。此外,您的解析函数可能会引起问题。尝试使用sess.run打印图像/标签。

我会建议使用估算API作为train_op。这是更方便,更纤薄不久将被取消。

© www.soinside.com 2019 - 2024. All rights reserved.