2017-02-14 20 views
1

我在使用队列中的张量流读取图像时遇到问题。请让我知道我在做什么错误。以下是代码。OutOfRangeError(请参阅上面的回溯):FIFOQueue'_1_batch/fifo_queue'已关闭且元素不足(请求32,当前大小为0)

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)  

请帮我

+0

你可以尝试在会话之外启动队列跑步者吗? – drpng

+0

不,它给出以下错误。 ValueError:无法启动队列运行程序:未注册默认会话。使用'with sess.as_default()'或将明确的会话传递给tf.start_queue_runners(sess = sess)。 –

+0

对不起,我不得不问 - 你需要至少32张图像才能拥有完整的32批次。目录中是否有足够的图像? – drpng

回答

1

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

+0

谢谢,我已经从train.batch更改为train.shuffle_batch并将图片位置作为标签。有效 –

相关问题