我一直在試圖將下面的代碼段與所述輸入管線Tensorflow:OutOfRangeError異常tf.train.string_input_producer閉合並且沒有足夠的元件
import tensorflow as tf
with tf.Session() as sess:
filename = ['/data/read/A.JPG', '/data/read/B.JPG', '/data/read/C.JPG']
filename_queue = tf.train.string_input_producer(filename, shuffle=False, num_epochs=5)
reader = tf.WholeFileReader()
key, value = reader.read(filename_queue)
tf.local_variables_initializer().run()
threads = tf.train.start_queue_runners(sess=sess)
i = 0
while True:
i += 1
image_data = sess.run(value)
with open('/data/read/test_%d.jpg' % i, 'wb') as f:
f.write(image_data)
運行上述代碼進行實驗得到下面的錯誤信息,看起來好像是由string_input_producer
生成的filename_queue
造成的。但我不清楚是什麼問題以及如何糾正它。謝謝。
caused by op 'ReaderReadV2', defined at:
File "test_input.py", line 12, in <module>
key, value = reader.read(filename_queue)
File "lib/python3.6/site-packages/tensorflow/python/ops/io_ops.py", line 193, in read
return gen_io_ops._reader_read_v2(self._reader_ref, queue_ref, name=name)
File "lib/python3.6/site-packages/tensorflow/python/ops/gen_io_ops.py", line 411, in _reader_read_v2
queue_handle=queue_handle, name=name)
File "lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 768, in apply_op
op_def=op_def)
File "lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2336, in create_op
original_op=self._default_original_op, op_def=op_def)
File "lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1228, in __init__
self._traceback = _extract_stack()
OutOfRangeError (see above for traceback): FIFOQueue '_1_input_producer' is closed and has insufficient elements (requested 1, current size 0)
[[Node: ReaderReadV2 = ReaderReadV2[_device="/job:localhost/replica:0/task:0/cpu:0"](WholeFileReaderV2, input_producer)]]