【问题标题】:OutOfRangeError (see above for traceback): FIFOQueue '_1_batch/fifo_queue' is closed and has insufficient elements (requested 32, current size 0)OutOfRangeError(参见上面的回溯):FIFOQueue '_1_batch/fifo_queue' 已关闭且元素不足(请求 32,当前大小 0)
【发布时间】:2017-02-14 10:55:50
【问题描述】:

我在使用队列时遇到 tensorflow 读取图像的问题。请让我知道我在做什么错误。下面是代码。

import tensorflow as tf
slim = tf.contrib.slim
from tensorflow.python.framework import ops

import glob
filelist = glob.glob("/*.png")
filelist[0]

imagelist = ops.convert_to_tensor(filelist)

#Makes an input queue 
input_queue = tf.train.slice_input_producer([imagelist],num_epochs = 2, shuffle = True, capacity = 64*3072)

我使用了不同的容量值,但没有一个有效

def read_images_from_disk(input_queue):
    file_contents = tf.read_file(input_queue[0])
    example = tf.image.decode_png(file_contents, channels=3)
    return example

image = read_images_from_disk(input_queue)

image.set_shape([28,28,3])
image_batch = tf.train.batch([image],batch_size = 32)

with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)

for i in range(20):
    print (sess.run(image_batch))

coord.request_stop()
coord.join(threads)
sess.close()


OutOfRangeError (see above for traceback): FIFOQueue '_1_batch/fifo_queue'
is closed and has insufficient elements (requested 32, current size 0)       

请帮帮我

【问题讨论】:

  • 您可以尝试在会话之外启动队列运行器吗?
  • 没有。它给出了以下错误。 ValueError:无法启动队列运行器:未注册默认会话。使用with sess.as_default() 或将显式会话传递给 tf.start_queue_runners(sess=sess)。
  • 对不起,我不得不问 - 您至少需要 32 张图像才能拥有完整的 32 批次。那个目录里有足够的图片吗?
  • 目录有49000张图片

标签: python tensorflow queue


【解决方案1】:

您可以添加一个文件名队列,例如string_input_producer,以替换文件夹中的所有文件。并尝试注释掉shuffle_batch 并查看文件名队列是否正在获取任何数据。如果您将 num_epoch 留空,此方法可能会运行多次。

【讨论】:

  • 谢谢,我已从 train.batch 更改为 train.shuffle_batch 并将图像位置作为标签。它奏效了
猜你喜欢
  • 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
相关资源
最近更新 更多