以下代码要学会几个地方

1、filename = ('data.tfrecords-%.5d-of-%.5d' % (i, num_shards)) 这个东西就是要会data.tfrecords-%.5d-of-%.5d两个.5d,

2、记住这两个操作writer = tf.python_io.TFRecordWriter(filename)writer = tf.python_io.TFRecordWriter(filename)

3、得到的是以下TFrecoard两个文件

import tensorflow as tf

def _int64_feature(value):
return tf.train.Feature(int64_list=tf.train.Int64List(value=[value])) num_shards = 2
instances_per_shard = 2
# 以下文件用于存储数据
for i in range(num_shards):
filename = ('data.tfrecords-%.5d-of-%.5d' % (i, num_shards))
# 将Example结构写入TFRecord文件。
writer = tf.python_io.TFRecordWriter(filename) for j in range(instances_per_shard):
# Example结构仅包含当前样例属于第几个文件以及是当前文件的第几个样本。
example = tf.train.Example(features=tf.train.Features(feature={
'i': _int64_feature(i),
'j': _int64_feature(j)}))
writer.write(example.SerializeToString())
writer.close()
以下是对上面程序生成文件的读取(该讲的已经讲了)
import tensorflow as tf

# 获取一个符合正则表达式的所有文件列表,这样就可以得到所有的符合要求的文件了
files = tf.train.match_filenames_once("data.tfrecords-*") # *是一个通配符 filename = tf.train.string_input_producer(files, shuffle=True, num_epochs=3) # 打乱顺序,迭代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),
}
) with tf.Session() as sess:
tf.local_variables_initializer().run()
print(sess.run(files))
coord = tf.train.Coordinator() # 定义tf.Coordinator类以协同线程
threads = tf.train.start_queue_runners(sess=sess, coord=coord) # 启动线程
for i in range(12):
print(sess.run([features['i'], features['j']]))
coord.request_stop()
coord.join(threads)

Tensorflow细节-P190-输入文件队列的更多相关文章

  1. TensorFlow多线程输入数据处理框架(二)——输入文件队列

    参考书 <TensorFlow:实战Google深度学习框架>(第2版) 一个简单的程序来生成样例数据. #!/usr/bin/env python # -*- coding: UTF-8 ...

  2. 吴裕雄 python 神经网络——TensorFlow 输入文件队列

    import tensorflow as tf def _int64_feature(value): return tf.train.Feature(int64_list=tf.train.Int64 ...

  3. Tensorflow读取文件到队列文件

    TensorFlow读取二进制文件数据到队列 2016-11-03 09:30:00      0个评论    来源:diligent_321的博客   收藏   我要投稿 TensorFlow是一种 ...

  4. TensorFlow笔记-线程和队列

    线程和队列 在使用TensorFlow进行异步计算时,队列是一种强大的机制. 为了感受一下队列,让我们来看一个简单的例子.我们先创建一个“先入先出”的队列(FIFOQueue),并将其内部所有元素初始 ...

  5. Tensorflow细节-P196-输入数据处理框架

    要点 1.filename_queue = tf.train.string_input_producer(files, shuffle=False)表示创建一个队列来维护列表 2.min_after_ ...

  6. Tensorflow细节-P194-组合训练数据

    import tensorflow as tf files = tf.train.match_filenames_once("data.tfrecords-*") filename ...

  7. Tensorflow细节-P186-队列与多线程

    先感受一下队列之美 import tensorflow as tf q = tf.FIFOQueue(2, "int32") # 创建一个先进先出队列 # 队列中最多可以保存两个元 ...

  8. tensorflow函数学习:队列和线程

    队列函数: FIFOQueue和RandomShuffleQueue 1.FIFOQueue FIFOQueue是先进先出队列,主要针对序列样本.如:使用循环神经网络时,需要处理语音.文字.视频等序列 ...

  9. Tensorflow细节-P312-PROJECTOR

    首先进行数据预处理,需要生成.tsv..jpg文件 import matplotlib.pyplot as plt import numpy as np import os from tensorfl ...

随机推荐

  1. vs中web api程序不包含适合于入口点的静态“Main”方法

    步骤:选择该项目的属性--应用程序--输出类型--类库

  2. vue中$router与$route的区别

    $.router是VueRouter的实例,相当于一个全局的路由器对象.包含很多属性和子对象,例如history对象 $.route表示当前正在跳转的路由对象.可以通过$.route获取到name,p ...

  3. C#代码常用技巧

    1.拼sql语句时,list中元素加单引号并以逗号分开:string.Join(",",list.Select(r=>"'"+r+"'" ...

  4. Java对list进行分页,subList()方法实现分页

    /** * 自定义List分页工具 * @author hanwl */ public class PageUtil { /** * 开始分页 * @param list * @param pageN ...

  5. git便携版 添加git-bash到右键菜单

    注册表路径 HKEY_CLASSES_ROOT\Directory\Background\shell 新建项取名open in git 默认设置为右键显示的名称 Git Bash Here 新建字符串 ...

  6. Spring Boot 实战 —— MyBatis(注解版)使用方法

    原文链接: Spring Boot 实战 -- MyBatis(注解版)使用方法 简介 MyBatis 官网 是这么介绍它自己的: MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过 ...

  7. 博客使用 utterances 作为评论系统

    utterances 是一款基于 GitHub issues 的评论工具. 相比同类的工具 gitment.gitalk 以及 disqus 评论工具,优点如下: 极其轻量 加载非常快 配置比较简单 ...

  8. 解决Vivado XSDK在Ubuntu系统上自带UART Terminal Crash问题

    在Ubuntu 18.04 LTS系统上使用某些版本的Vivado XSDK的Eclipse IDE中自带的串口Terminal会有Crash的问题.Xilinx的XSDK的Terminal插件是用的 ...

  9. 制作IOS ANE的基本流程

    来源:http://www.swfdiy.com/?p=1239 1. 使用xcode新建ios上的static library 工程 2. 从air sdk/include里拷贝flashrunti ...

  10. python 笔记一

    1. is 和 ==区别 is 判断是否是一个ID(内存中的数据是否是同一个), == 判断内容是否一致. 2.python 常量池包括 1.短整型的-5~256 2.字符串的数字.大小写字母随意组合 ...