我在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秒后再次尝试时,队列中相同数量的图像也会发生同样的情况。
查看sliceInputProducer的tensorflow doc
num_epochs :(可选。)一个整数。如果指定了input_producer 在生成之前生成每行input_tensor num_epochs次 OutOfRange错误。如果未指定,input_producer可以循环 通过input_tensor行无限次。
因此,在看到所有数据后,切片输入生成器不应该关闭。
我的预处理是否太重,以至于队列无法快速填充并在一段时间后关闭?
感谢您的帮助
答案 0 :(得分:0)
问题解决了:这是在预处理期间随机出现的错误。当我的images_queue
尝试将新图像排入队列并引发此异常时,不会打印任何内容但队列会关闭。然后,当我尝试访问队列时,它会引发OutOfRangeError