前言

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

错误描述:

OutOfRangeError (see above for traceback): RandomShuffleQueue '_1_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested , current size )
[[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_UINT8, DT_INT32, DT_FLOAT, DT_FLOAT], timeout_ms=-, _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等等。

4. 也可以更换更好的硬件设备,比如更好的GPU显卡;

参考

1. 理解tfrecord读取数据

2. TensorFlow bug

【error】OutOfRangeError (see above for traceback): RandomShuffleQueue的更多相关文章

  1. laravel 【error】MethodNotAllowedHttpException No message

    Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message 报错原因[原理]CSRF ...

  2. 【Error】IOError: [Errno 22] invalid mode ('wb') or filename

    错误描述: IOError: [Errno 22] invalid mode ('wb') or filename: 'C:\\Users\\Viral Patel\\Documents\\GitHu ...

  3. 【ERROR】使用jquery的ajax出现error:readyState=4,status=500

    使用jquery的ajax出现error:readyState=4,status=500,ajax代码如下: $.ajax({ url : "../toBeFinMisManage/show ...

  4. 【ERROR】ERROR: transport error 202: bind failed: Cannot assign requested address

    异常信息: ERROR: transport error : bind failed: Cannot assign requested address ERROR: JDWP Transport dt ...

  5. 【ERROR】no matching function for call to 'std::basic_ifstream<char>::basic_ifstream

    错误记录:QT中使用 no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(QString ...

  6. 【error】'isnan' was not declared in this scope

    error问题 'isnan' was not declared in this scope isnan在cmath中被取消宏定义: // These are possible macros impo ...

  7. 【error】no type named ‘type’ in ‘class std::result_of<void

    Q: std::thread fs_module(fs_process, prob_orig, fb_sz, line_num, probp, plabel, std::ref(confidence_ ...

  8. 【error】scripts/basic/fixdep: Syntax error: "(" unexpected

    前言 第一次安装PCIE驱动的时候容易出现各种问题,总结一下下.. 原因分析 一般情况下,直接make的时候会出现问题. scripts/basic/fixdep: : scripts/basic/f ...

  9. 【error】Invalid ADAPTORNAME specified. Type 'imaqhwinfo' for a list of available ADAPTORNAMEs.

    前言 使用matlab通过摄像头获取图像进行处理: 问题描述 使用matalb调用摄像头时出现错误: >> imaqhwinfo Warning: No Image Acquisition ...

随机推荐

  1. Linux LVM--三种Logic Volume

    本文链接:https://blog.csdn.net/u012299594/article/details/84551722 概述 为了满足在性能和冗余等方面的需求,LVM支持了下面三种Logic V ...

  2. Pytorch在colab和kaggle中使用TensorBoard/TensorboardX可视化

    在colab和kaggle内核的Jupyter notebook中如何可视化深度学习模型的参数对于我们分析模型具有很大的意义,相比tensorflow, pytorch缺乏一些的可视化生态包,但是幸好 ...

  3. 【微信小程序】如何获取用户绑定手机号

    用户调用wx.login()方法,获取登录用户凭证code wx.login({ success: function(res) { console.log('loginCode', res.code) ...

  4. jquery.nicescroll.js Unable to preventDefault inside passive event listener due to target being treated as passive.

    解决办法就是:https://github.com/bestjhh/Plugin 下载替换. 参考: https://github.com/bestjhh/Plugin https://blog.cs ...

  5. python 装饰器demo

    本质就是一个函数,这个函数符合闭包语法结构,可以在函数不需要改变任何代码情况下增加额外功装饰器的返回值是一个函数的引用 功能:1.引入日志:2.函数执行时间统计:3.执行函数前预备处理:4.执行函数后 ...

  6. docker技术入门(1)

    1Docker技术介绍 DOCKER是一个基于LXC技术之上构建的container容器引擎,通过内核虚拟化技术(namespace及cgroups)来提供容器的资源隔离与安全保障,KVM是通过硬件实 ...

  7. python 椭球面

    作者:chaowei wu链接:https://www.zhihu.com/question/266366089/answer/307037017来源:知乎著作权归作者所有.商业转载请联系作者获得授权 ...

  8. post请求头中常见content-type(非常重要)

    定义和用法 enctype 属性规定在发送到服务器之前应该如何对表单数据进行编码.默认地,表单数据会编码为 "application/x-www-form-urlencoded". ...

  9. debian9 ps 命令不能用

    # cat > /etc/apt/sources.list << EOF> deb http://mirrors.aliyun.com/debian/ stretch main ...

  10. win10不能将文件拖到另外一个程序中去的解决办法

    author: headsen chen date: 2019-07-25   14:48:32 notice : 个人原创 新建一个 aa.txt的文本文档: Windows Registry Ed ...