码迷,mamicode.com
首页 > 其他好文 > 详细

【error】OutOfRangeError (see above for traceback): RandomShuffleQueue

时间:2019-09-27 10:42:02      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:使用   系统   地方   推荐   reads   current   get   应该   填充   

前言

在使用tensorflow TFRecord的过程中,读取*.tfrecord文件时出现错误,本文解决这个错误。

错误描述:

OutOfRangeError (see above for traceback): RandomShuffleQueue _1_shuffle_batch/random_shuffle_queue is closed and has insufficient elements (requested 64, current size 62)
[[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_UINT8, DT_INT32, DT_FLOAT, DT_FLOAT], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]

源码:

image_batch, label_batch, roi_batch, landmark_batch = tf.train.shuffle_batch([img,label,roi,landmark], 
                                                    batch_size=batch_size, 
                                                    capacity=capacity, 
                                                    min_after_dequeue=min_after_dequeue,
                                                    num_threads=7)  

错误原因:

在执行训练的时候,队列会被后台的线程填充好。如果设置了最大训练迭代数(epoch),在某些时候,样本出队的操作可能会抛出一个tf.OutOfRangeError的错误。这是因为tensorflow的队列已经到达了最大实际的最大迭代数,没有更多可用的样本了。这也是为何推荐代码模板需要用try..except ..finally结构来处理这种错误。

一般遇到这个错误,代码本身并没有什么问题,基本上都是参数设置不一致或者和不合适导致的,要注意检查各个参数。

对于博主来说,更改的参数有:

1. 数据格式的不一致性,要与生成tfrecord的数据格式保持一致。

features = tf.parse_single_example(serialized_example,
                               features={
                               img:tf.FixedLenFeature([],tf.string),
                               label:tf.FixedLenFeature([],tf.int64),                                   
                               roi:tf.FixedLenFeature([4],tf.float32),
                               landmark:tf.FixedLenFeature([10],tf.float32),
                               })

将label的数据格式由int32改为int64;

这方面,还有一个更改的地方是输入图像数据的大小。

# img = tf.reshape(img, [48,48,3])
img = tf.reshape(img, [img_size,img_size,3]) 

这里博主测试的是MTCNN中生成的pos_12_train.tfrecord的数据,故此处img_size应该是12;

2. batch_size的大小;

这个是需要和运行环境匹配的,也就是批量大小过大,系统可能处理不过来造成的;

3. 根据情况可能还有其他参数需要检查,比如num_epochs、num_threads等等。

参考

1. 理解tfrecord读取数据

2. TensorFlow bug

【error】OutOfRangeError (see above for traceback): RandomShuffleQueue

标签:使用   系统   地方   推荐   reads   current   get   应该   填充   

原文地址:https://www.cnblogs.com/happyamyhope/p/11595845.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!