【问题标题】:OutOfRangeError: RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 1, current size 0)OutOfRangeError: RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' 已关闭且元素不足(请求 1,当前大小 0)
【发布时间】:2017-09-07 14:36:29
【问题描述】:

尝试将数据提供给模型时出现 outOfRange 错误。我猜数据永远不会到达队列,因此会出错。只是为了测试,我用一个元组(图像,ground_truth)向它提供 tfrecord。 我也尝试了 tensorflow 调试器(tfdbg),但它也会抛出同样的错误,我看不到任何 tensoeflow 值。

Tensorflow 版本:1.3

Python 版本:3.5.3

操作系统:Windows10

filename_queue = tf.train.string_input_producer([tfrecord_filename],num_epochs=1)

image_batch, annotation_batch = tf.train.shuffle_batch([resized_image, resized_annotation],
                                                       batch_size=1,
                                                       capacity=10,
                                                       num_threads=1,
                                                       min_after_dequeue=1)

堆栈跟踪:

Traceback (most recent call last):
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1327, in _do_call
    return fn(*args)
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1306, in _run_fn
    status, run_metadata)
  File "C:\Program Files\Python35\lib\contextlib.py", line 66, in __exit__
    next(self.gen)
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 466, in raise_exception_on_not_ok_status
    pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.OutOfRangeError: RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 1, current size 0)
     [[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_UINT8, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/supriya.godge/PycharmProjects/tf-image-segmentation/tf_image_segmentation/recipes/pascal_voc/DeepLab/resnet_v1_101_8s_train.py", line 160, in <module>
    train_step])
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\client\session.py", line 895, in run
    run_metadata_ptr)
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1124, in _run
    feed_dict_tensor, options, run_metadata)
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1321, in _do_run
    options, run_metadata)
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1340, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.OutOfRangeError: RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 1, current size 0)
     [[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_UINT8, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]

Caused by op 'shuffle_batch', defined at:
  File "C:/Users/supriya.godge/PycharmProjects/tf-image-segmentation/tf_image_segmentation/recipes/pascal_voc/DeepLab/resnet_v1_101_8s_train.py", line 68, in <module>
    min_after_dequeue=1)
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\training\input.py", line 1220, in shuffle_batch
    name=name)
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\training\input.py", line 791, in _shuffle_batch
    dequeued = queue.dequeue_many(batch_size, name=name)
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\ops\data_flow_ops.py", line 457, in dequeue_many
    self._queue_ref, n=n, component_types=self._dtypes, name=name)
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\ops\gen_data_flow_ops.py", line 1342, in _queue_dequeue_many_v2
    timeout_ms=timeout_ms, name=name)
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 767, in apply_op
    op_def=op_def)
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 2630, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 1204, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

OutOfRangeError (see above for traceback): RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 1, current size 0)
     [[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_UINT8, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]

对于相同的错误,我尝试了在 stackoverflow 上发布的不同解决方案。不幸的是,没有什么对我有用。如果我应该提供任何其他信息,请告诉我。 任何建议表示赞赏。 提前致谢。

【问题讨论】:

  • tfrecord_filename的内容是什么?
  • 移除 tf.train.string_input_producer 中的 num_epochs ?
  • @GPh tfrecord 有 4 对 (image, ground_truth_image)。
  • @Tianjin yah 谢谢你的建议,但我试过了,它对我不起作用。
  • 有什么方法可以调试它并查看张量值吗?我尝试了 tfdbg,但找不到任何放置断点的方法,因此在调试时也遇到了上述相同的错误。 (tfdbg 中只有一个条件断点,但它用于 nan 和 inf)

标签: debugging tensorflow


【解决方案1】:

请使用此网址创建注释图像。完成标注图像后,请查看标注图像的矩阵值。
网址:https://github.com/kyamagu/js-segment-annotator

Example:
Originale Annotation Image Matrix Value [1,1,1] but
Your Annotation image have [0,0,1] or [1,0,0] or [0,1,0].

所以你使用我的 python 脚本和 opencv 从 [0,0,1] 转换为相同的值[1,1,1]

def biggest(a, y, z):
    Max = a
    if y > Max:
        Max = y
    if z > Max:
        Max = z
        if y > z:
            Max = y
    return Max
#Input Image
outdir = "sampleimages/sample2.png"
cnt = 0
image = cv2.imread(outdir)

for i in range(0,360):
  for j in range(0,480):
    newvalue = biggest(image[i,j,0],image[i,j,1],image[i,j,2])
    image[i,j,0] = newvalue
    image[i,j,1] = newvalue
    image[i,j,2] = newvalue
    #if image[i,j] == 8:
    #  cnt += 1
#Output Image
cv2.imwrite("sampleimages/sample-gray-2.png",image)

请参考: https://github.com/tkuanlun350/Tensorflow-SegNet/issues/6

【讨论】:

  • 感谢您提供的信息,它绝对有用。
【解决方案2】:

我正在为我的机器学习项目创建一个数据集,结果发现,每当我从 python 以 png 格式保存图像文件时,我都会遇到上述错误。 我使用 mat-lab 生成了数据集并且错误消失了。我仍在对此进行调查并尽快发布更新的答案。同时我希望这对某人有所帮助。

【讨论】:

  • 你用上面的方法解决了错误吗?我仍然遇到问题。
  • 嗨 Moondra,是的,我能够通过使用 matlab 保存 png 文件来解决此错误。
  • 谢谢。我实际上删除了 .png 文件,但我仍然遇到问题。我想我会写一个关于它的新线程。
【解决方案3】:

如果注释图像错误,则会显示此错误。请参见 注释图像矩阵值。应该是不同的。例如 注释图像矩阵值具有灰色(矩阵值[1 1 1]) 但您的图像不是灰色的(矩阵值 [1 3 6])。所以检查矩阵值 您的注释图像

如果注释图像不是灰色的,则队列未填充。这是 错误。

在 CamVid_reader_seq def 内的 Inputs.py 第 68 行尝试此代码

label_bytes = tf.image.decode_png(labelValue,1)

注意:1 表示将彩色图像转换为灰度图像

【讨论】:

【解决方案4】:

对于任何这可能会有所帮助的人,我遇到了同样的错误,这显然是第一个在不同上下文中讨论错误的链接。

由于 Tensorflow 的错误消息很差,此错误可能是由于以下原因造成的:

  1. TF 记录文件路径错误
  2. 图像形状不匹配
  3. 图像文件格式不匹配

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多