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)
請幫我
你可以嘗試在會話之外啓動隊列跑步者嗎? – drpng
不,它給出以下錯誤。 ValueError:無法啓動隊列運行程序:未註冊默認會話。使用'with sess.as_default()'或將明確的會話傳遞給tf.start_queue_runners(sess = sess)。 –
對不起,我不得不問 - 你需要至少32張圖像才能擁有完整的32批次。目錄中是否有足夠的圖像? – drpng