我在Tensorflow上的输入管道有问题>我不确定我是否正确理解队列。Tensorflow先进先出队列已关闭并且元素不足
我首先创建的两个独立slice_input_producer生成路径图像和标签
paths_queue_mines=tf.train.slice_input_producer([t_pathsMine,t_pathMask,t_labels],
shuffle=True)
paths_queue_bckg=tf.train.slice_input_producer((t_pathBckg,),
shuffle=True)
处理我在一个图像张量和一个标签张量相结合的一切,我添加到新的队列后
images_queue=tf.FIFOQueue(capacity=300,
dtypes=[tf.float32,tf.float32],
shapes=[(SHAPE,SHAPE,1),(SUBDIVISION,SUBDIVISION,5)],
name='images_queue')
enqueue_op=images_queue.enqueue((img_final,label_final))
N_threads=20
#create QueueRunner for filling images_queue
qr=tf.train.QueueRunner(images_queue,[enqueue_op]*N_threads)
tf.train.add_queue_runner(qr)
然后我可以启动使用images_queue.dequeueMany我的训练,但之后的培养了一批具备规模几步(4和160之间64)我得到以下错误:
FIFOQueue '_2_Preprocessing/images_queue' is closed and has insufficient elements (requested 64, current size 44)
[[Node: images_queue_DequeueMany = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_FLOAT], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](Preprocessing/images_queue, images_queue_DequeueMany/n)]]
Caused by op 'images_queue_DequeueMany', defined at:
File "main.py", line 194, in <module>
run_training()
File "main.py", line 114, in run_training
images,labels = images_queue.dequeue_many(FLAGS.batch_size)
File "/home/thales/anaconda3/lib/python3.5/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/thales/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 1328, in _queue_dequeue_many_v2
timeout_ms=timeout_ms, name=name)
File "/home/thales/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 768, in apply_op
op_def=op_def)
File "/home/thales/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2336, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/home/thales/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1228, in __init__
self._traceback = _extract_stack()
OutOfRangeError (see above for traceback): FIFOQueue '_2_Preprocessing/images_queue' is closed and has insufficient elements (requested 64, current size 44)
[[Node: images_queue_DequeueMany = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_FLOAT], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](Preprocessing/images_queue, images_queue_DequeueMany/n)]]
我不明白为什么队列被关闭。即使内部没有足够的图像,程序也应该等待它再次填充,但是当我捕捉到异常并在3秒后再次尝试时,同样的情况发生在队列中相同数量的图像上。
当寻找到tensorflow文档的sliceInputProducer
num_epochs:(可选)一个整数。如果指定的input_producer 在生成 OutOfRange错误之前生成input_tensor num_epochs次的每一行。如果未指定,input_producer可以循环执行 ,通过input_tensor的行无限次数。
因此,切片输入生产者在看到所有数据后不应关闭。
这是我的预处理过重,所以队列无法足够快速地填充并在一段时间后关闭?
谢谢您的帮助
如果您可以粘贴一些重现错误的自包含代码,这将有所帮助。 – npf
这种错误通常表示您的预处理代码中的一个操作失败,并且在关闭期间关闭了队列。在OutOfRangeError之前是否还有其他例外或错误消息? – mrry