OutOfRangeError
错误信息为:
padding_fifo_queue is closed and has insufficient elements (required 1 current size 0)[[Node: get_batch/batch = QueueDequeueManyV2[component_types=[DT_STRING, DT_FLOAT, DT_INT32, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](get_batch/batch/padding_fiflo_queue, get_batch/batch/n)]]
错误原因
这个错误耗费了我整整两天的时间,主要原因在于tensorflow中报错是insufficient elements,让我认为时queue设置参数有误导致的问题,但其实不然。真正原因是输入数据的问题。
对于检测应用,输入的图像尺寸与对应xml文件中记录的图像尺寸(h, w)不一致,从而引起了该错误。
该原因从属于输入reshape时shape不一致这一范畴。
而该错误(图像保存后的尺寸与xml记录尺寸不一致)的原因在于使用plt.save保存图像时,图像尺寸有时会发生一个像素单位的偏差(真的坑,万万没想到)。
其他可能原因:data preprocessing
Problem solved : it was an error that randomly appears during the preprocessing. When my images_queue tries to enqueue a new image and raise this exception, nothing is printed but the queue closes. Then later when I try to access the queue, it raises the OutOfRangeError.
来源于该网址
其他可能原因:文件末尾的空行
I had the exactly same issue today and later I found it was the input data file I downloaded from “famous data set” (such as https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data) that caused the error: It has some empty lines at the end of the file. Remove the empty lines, the error was gone!
来源于该网址
其他可能原因:输入reshape时shape不一致
You’re likely processing the parsed TFRecord example wrong. E.g. trying to reshape a tensor to an incompatible size. You can debug using a tf_record_iterator to confirm the data you’re reading is stored the way you think it is:
import tensorflow as tf
import numpy as nptfrecords_filename = '/path/to/some.tfrecord'
record_iterator = tf.python_io.tf_record_iterator(path=tfrecords_filename)for string_record in record_iterator:# Parse the next exampleexample = tf.train.Example()example.ParseFromString(string_record)# Get the features you stored (change to match your tfrecord writing code)height = int(example.features.feature['height'].int64_list.value[0])width = int(example.features.feature['width'].int64_list.value[0])img_string = (example.features.feature['image_raw'].bytes_list.value[0])# Convert to a numpy array (change dtype to the datatype you stored)img_1d = np.fromstring(img_string, dtype=np.float32)# Print the image shape; does it match your expectations?print(img_1d.shape)
Phew, that was a rough bug, but your answer solved it. I had a tf.py_func node that returned the wrong type, but TF only shows a misleading error message about insufficient elements. – Lenar Hoyt Jun 15 ‘17 at 18:46
来源于网址
其他可能原因:未初始化local variables
I had a similar problem. Digging around the web, it turned out that if you use some num_epochs argument, you have to initialize all the local variables, so your code should end up looking like:
with tf.Session() as sess:sess.run(tf.local_variables_initializer())sess.run(tf.global_variables_initializer())coord = tf.train.Coordinator()threads = tf.train.start_queue_runners(coord=coord)# do your stuff herecoord.request_stop()coord.join(threads)
Queue详解
-
十图详解tensorflow数据读取机制(附代码)
-
tensorflow队列操作详解
-
理解TensorFlow的Queue