tensorflow random shuffle queue:元素不足

时间:2017-04-21 15:07:39

标签: python tensorflow

我正在通过在不同的图像上训练它来测试模型。我有不同的文件夹,其中包含不同数量的图像。当我从一个只有20个图像的文件夹更改为其中包含100或10'000个图像的文件夹时,程序会立即崩溃,抱怨随机混洗队列的元素数量不足。

我没有更改代码中的任何其他内容,只是将其指向不同的目录,这些目录绝对不是空的。有没有人知道为什么会这样,以及如何解决它?

错误消息

tensorflow/core/kernels/queue_base.cc:294] _0_READ_DATA/input_producer: Skipping cancelled enqueue attempt with queue not closed
Traceback (most recent call last):
  File "test_vgg19.py", line 102, in <module>
    images, labels = sess.run([imb_batch1,label_batch1])
  File "/home/ssoderli/.local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 766, in run
    run_metadata_ptr)
  File "/home/ssoderli/.local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 964, in _run
    feed_dict_string, options, run_metadata)
  File "/home/ssoderli/.local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1014, in _do_run
    target_list, options, run_metadata)
  File "/home/ssoderli/.local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1034, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.OutOfRangeError: RandomShuffleQueue '_3_READ_DATA/shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 30, current size 0)
     [[Node: READ_DATA/shuffle_batch = QueueDequeueMany[_class=["loc:@READ_DATA/shuffle_batch/random_shuffle_queue"], component_types=[DT_FLOAT, DT_STRING], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](READ_DATA/shuffle_batch/random_shuffle_queue, READ_DATA/shuffle_batch/n)]]

Caused by op u'READ_DATA/shuffle_batch', defined at:
  File "test_vgg19.py", line 56, in <module>
    imb_batch1,label_batch1 = input_pipeline()
  File "test_vgg19.py", line 53, in input_pipeline
    min_after_dequeue=min_after_dequeue)
  File "/home/ssoderli/.local/lib/python2.7/site-packages/tensorflow/python/training/input.py", line 917, in shuffle_batch
    dequeued = queue.dequeue_many(batch_size, name=name)
  File "/home/ssoderli/.local/lib/python2.7/site-packages/tensorflow/python/ops/data_flow_ops.py", line 458, in dequeue_many
    self._queue_ref, n=n, component_types=self._dtypes, name=name)
  File "/home/ssoderli/.local/lib/python2.7/site-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 1099, in _queue_dequeue_many
    timeout_ms=timeout_ms, name=name)
  File "/home/ssoderli/.local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 759, in apply_op
    op_def=op_def)
  File "/home/ssoderli/.local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2240, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/home/ssoderli/.local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1128, in __init__
    self._traceback = _extract_stack()

OutOfRangeError (see above for traceback): RandomShuffleQueue '_3_READ_DATA/shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 30, current size 0)
     [[Node: READ_DATA/shuffle_batch = QueueDequeueMany[_class=["loc:@READ_DATA/shuffle_batch/random_shuffle_queue"], component_types=[DT_FLOAT, DT_STRING], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](READ_DATA/shuffle_batch/random_shuffle_queue, READ_DATA/shuffle_batch/n)]]

输入管道 - 代码段

def read_my_file_format(filename_queue):
    reader = tf.WholeFileReader()
    key, record_string = reader.read(filename_queue)
    example = tf.image.decode_png(record_string)
    return example, key


def input_pipeline( bsize=30, num_epochs=None):
    filename_queue = tf.train.string_input_producer(
        tf.train.match_filenames_once("/home/20images/*.png"), num_epochs=num_epochs, shuffle=True)
    example, label = read_my_file_format(filename_queue)
    min_after_dequeue = bsize
    capacity = min_after_dequeue + 3 * 8
    example_batch, label_batch =  tf.train.shuffle_batch(
        [example, label], batch_size=bsize, capacity=capacity,
        min_after_dequeue=min_after_dequeue)
    return  example_batch, label_batch

修改

原来,有些图片的大小不同,从而引发了问题。虽然我很好奇如何产生错误信息。我不知道不同大小的图像如何产生错误。

1 个答案:

答案 0 :(得分:1)

事实证明,在发生错误的文件夹中有一些尺寸较大的图像。删除它们并且工作正常。