我的代码是从tfrecord文件中读取图像
Traceback (most recent call last):
File "/home/robinreni/Documents/pythonprojects/cnn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1323, in _do_call
return fn(*args)
File "/home/robinreni/Documents/pythonprojects/cnn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1302, in _run_fn
status, run_metadata)
File "/home/robinreni/Documents/pythonprojects/cnn/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 473, in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.OutOfRangeError: RandomShuffleQueue '_1_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 10, current size 0)
[[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "read_tfrecords.py", line 35, in <module>
img, lbl = sess.run([images, labels])
File "/home/robinreni/Documents/pythonprojects/cnn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 889, in run
run_metadata_ptr)
File "/home/robinreni/Documents/pythonprojects/cnn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1120, in _run
feed_dict_tensor, options, run_metadata)
File "/home/robinreni/Documents/pythonprojects/cnn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1317, in _do_run
options, run_metadata)
File "/home/robinreni/Documents/pythonprojects/cnn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1336, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.OutOfRangeError: RandomShuffleQueue '_1_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 10, current size 0)
[[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]
Caused by op 'shuffle_batch', defined at:
File "read_tfrecords.py", line 27, in <module>
images, labels = tf.train.shuffle_batch([image, label], batch_size=10, capacity=30, num_threads=1, min_after_dequeue=10)
File "/home/robinreni/Documents/pythonprojects/cnn/lib/python3.6/site-packages/tensorflow/python/training/input.py", line 1225, in shuffle_batch
name=name)
File "/home/robinreni/Documents/pythonprojects/cnn/lib/python3.6/site-packages/tensorflow/python/training/input.py", line 796, in _shuffle_batch
dequeued = queue.dequeue_many(batch_size, name=name)
File "/home/robinreni/Documents/pythonprojects/cnn/lib/python3.6/site-packages/tensorflow/python/ops/data_flow_ops.py", line 464, in dequeue_many
self._queue_ref, n=n, component_types=self._dtypes, name=name)
File "/home/robinreni/Documents/pythonprojects/cnn/lib/python3.6/site-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 2418, in _queue_dequeue_many_v2
component_types=component_types, timeout_ms=timeout_ms, name=name)
File "/home/robinreni/Documents/pythonprojects/cnn/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/home/robinreni/Documents/pythonprojects/cnn/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2956, in create_op
op_def=op_def)
File "/home/robinreni/Documents/pythonprojects/cnn/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1470, in __init__
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
OutOfRangeError (see above for traceback): RandomShuffleQueue '_1_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 10, current size 0)
[[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]
错误消息
INSERT OR REPLACE INTO table () values();
我将所有图像和标签转换为tfrecord文件,并且必须在训练期间将文件转换为原始图像和标签。我正在尝试从tfrecords中读取图像,但弹出了outofrange错误。请任何人帮助如何解决此错误
答案 0 :(得分:0)
OutOfRangeError
因为未指定shapes
而加注:
images, labels = tf.train.shuffle_batch([image, label], batch_size=10, capacity=30, num_threads=1, min_after_dequeue=10, shapes=[[224, 224, 1], []])
应该有用。
请参阅文档here