import tensorflow as tf

files = tf.train.match_filenames_once("data.tfrecords-*")
filename = tf.train.string_input_producer(files, shuffle=False, num_epochs=3) # 创建输入队列
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename) features = tf.parse_single_example( # 解析serialized_example
serialized_example,
features={
'i': tf.FixedLenFeature([], tf.int64),
'j': tf.FixedLenFeature([], tf.int64),
}
) example, label = features['i'], features['j']
batch_size = 3
capacity = 1000 + 3 * batch_size
# example_batch, label_batch = tf.train.batch([example, label], batch_size=batch_size, capacity=capacity)
# example_batch, label_batch = tf.train.shuffle_batch([example, label], batch_size=batch_size,
# capacity=capacity, min_after_dequeue=30)
example_batch, label_batch = tf.train.shuffle_batch([example, label], batch_size=batch_size,
capacity=capacity, min_after_dequeue=30, num_threads=2)
# capacity与队列有关,当队列容量小于capacity时,Tensorflow将重新启动入队操作,当长度等于容量时,暂停入队操作
# 以上这玩意tf.train.batch是会新创建一个队列的
with tf.Session() as sess:
tf.local_variables_initializer().run() # 处理files = tf.train.match_filenames_once("data.tfrecords-*")
print(sess.run(files))
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
for i in range(4):
cur_example_batch, cur_label_batch = sess.run([example_batch, label_batch])
print(cur_example_batch, cur_label_batch) coord.request_stop()
coord.join(threads)

Tensorflow细节-P194-组合训练数据的更多相关文章

  1. TensorFlow多线程输入数据处理框架(三)——组合训练数据

    参考书 <TensorFlow:实战Google深度学习框架>(第2版) 通过TensorFlow提供的tf.train.batch和tf.train.shuffle_batch函数来将单 ...

  2. tensorflow读取训练数据方法

    1. 预加载数据 Preloaded data # coding: utf-8 import tensorflow as tf # 设计Graph x1 = tf.constant([2, 3, 4] ...

  3. Tensorflow细节-P170-图像数据预处理

    由于6.5中提出的TFRecord非常复杂,可扩展性差,所以本节换一种方式 import tensorflow as tf from tensorflow.examples.tutorials.mni ...

  4. Tensorflow 从文件中载入训练数据

    本节包含: 用纯文本文件准备训练数据 加载文件中的训练数据 一.用纯文本文件准备训练数据 1.数据的数字化 比如,“是” —— “1”,“否” —— “0” “优”,“中”,“差” —— 1 2 3  ...

  5. TensorFlow Distribution(分布式中的数据读取和训练)

    本文目的 在介绍estimator分布式的时候,官方文档由于版本更新导致与接口不一致.具体是:在estimator分布式当中,使用dataset作为数据输入,在1.12版本中,数据训练只是datase ...

  6. Tensorflow细节-P202-数据集的高层操作

    本节是对上节的补充 import tempfile import tensorflow as tf # 输入数据使用本章第一节(1. TFRecord样例程序.ipynb)生成的训练和测试数据. tr ...

  7. 学习TensorFlow,调用预训练好的网络(Alex, VGG, ResNet etc)

    视觉问题引入深度神经网络后,针对端对端的训练和预测网络,可以看是特征的表达和任务的决策问题(分类,回归等).当我们自己的训练数据量过小时,往往借助牛人已经预训练好的网络进行特征的提取,然后在后面加上自 ...

  8. [开发技巧]·TensorFlow中numpy与tensor数据相互转化

    [开发技巧]·TensorFlow中numpy与tensor数据相互转化 个人主页–> https://xiaosongshine.github.io/ - 问题描述 在我们使用TensorFl ...

  9. tesnorflow实现N个epoch训练数据读取的办法

    https://blog.csdn.net/lujiandong1/article/details/53991373 方式一:不显示设置读取N个epoch的数据,而是使用循环,每次从训练的文件中随机读 ...

随机推荐

  1. flask框架(三)——路由系统route转换成add_url_rule及源码分析

    这节我们不用@app.route来写路由,而是通过add_url_rule 传统写法  (<int:nid>传递int类型参数,endpoint是取别名) @app.route('/det ...

  2. golang数组

  3. 支付宝支付回调方法RSA2验签失败处理方法

    支付宝支付签名方式RSA2生成支付时使用的是支付宝公钥和应用私钥, 而不是应用公钥,支付宝公钥的生成是根据上传应用公钥而变动的, 所以在做回调的时候参数ALIPAY_PUBLIC_KEY也需要传支付宝 ...

  4. 一张图看懂SharpImage

    通过下面的图片,可以瞬间看懂整个类库的脉络.图片比较大,如果看不清,可

  5. tp5模板中js方法中url函数传参的解决办法

    代码如下: layer.msg(data.msg, {icon: 1,time:1500,shade: 0.1}, function(index){ layer.close(index); var s ...

  6. HTML Marquee跑马灯

    Marquee是html的标签,所有的主流浏览器都能兼容,用于创建文字滚动. 来介绍下标签的属性 滚动方向 direction <!--滚动方向 direction 4个值 up down le ...

  7. 【iOS】去除字符串首尾空格或某字符

    在iOS的实际开发中,常会出现需要去除空格的情况,总结有三种情况: 去除字符串首尾连续字符(如空格): 去除字符串首部连续字符(如空格): 去除字符串尾部连续字符(如空格): 去除字符串首尾连续字符( ...

  8. 使nginx支持pathinfo模式

    在将fastadmin部署到虚拟机中时,遇到如下问题:当访问登录页面时,页面进行不断的循环跳转重定向.解决方法是将nginx配置为支持pathinfo的模式 以下是nginx中的配置内容: locat ...

  9. vue-cli脚手架——3.0版本项目案例

    一.[准备工作] node与git部分见vue-cli2.0搭建案例 vue-cli3.0是一个基于 Vue.js 进行快速开发的完整系统.有三个组件: CLI:@vue/cli 全局安装的 npm ...

  10. Centos 端口被占用,kill被占用的进程

    1.yum install lsof 2.输入netstat -tln,查看系统当前所有被占用端口 3.根据端口查询进程,输入lsof -i :9555,切记不要忘了添加冒号 4. 既然知道进程号了, ...