吴裕雄--天生自然 pythonTensorFlow图形数据处理:输入文件队列
import tensorflow as tf # 1. 生成文件存储样例数据。
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 = ('E:\\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()
# 2. 读取文件。
files = tf.train.match_filenames_once("E:\\data.tfrecords-*")
filename_queue = tf.train.string_input_producer(files, shuffle=False)
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(serialized_example,features={'i': tf.FixedLenFeature([], tf.int64),'j': tf.FixedLenFeature([], tf.int64)})
with tf.Session() as sess:
sess.run([tf.global_variables_initializer(), tf.local_variables_initializer()])
print(sess.run(files))
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
for i in range(6):
print(sess.run([features['i'], features['j']]))
coord.request_stop()
coord.join(threads)
# 3. 组合训练数据(Batching)
example, label = features['i'], features['j']
batch_size = 2
capacity = 1000 + 3 * batch_size
example_batch, label_batch = tf.train.batch([example, label], batch_size=batch_size, capacity=capacity) with tf.Session() as sess:
tf.global_variables_initializer().run()
tf.local_variables_initializer().run()
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
for i in range(3):
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)
吴裕雄--天生自然 pythonTensorFlow图形数据处理:输入文件队列的更多相关文章
- 吴裕雄--天生自然 pythonTensorFlow图形数据处理:队列操作
import tensorflow as tf #1. 创建队列,并操作里面的元素. q = tf.FIFOQueue(2, "int32") init = q.enqueue_m ...
- 吴裕雄--天生自然 pythonTensorFlow图形数据处理:输入数据处理框架
import tensorflow as tf # 1. 创建文件列表,通过文件列表创建输入文件队列 files = tf.train.match_filenames_once("F:\\o ...
- 吴裕雄--天生自然 pythonTensorFlow图形数据处理:数据集高层操作
import tempfile import tensorflow as tf # 1. 列举输入文件. # 输入数据生成的训练和测试数据. train_files = tf.train.match_ ...
- 吴裕雄--天生自然 pythonTensorFlow图形数据处理:循环神经网络预测正弦函数
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt # 定义RNN的参数. HIDDEN_SIZE = ...
- 吴裕雄--天生自然 pythonTensorFlow图形数据处理:数据集基本使用方法
import tempfile import tensorflow as tf # 1. 从数组创建数据集. input_data = [1, 2, 3, 5, 8] dataset = tf.dat ...
- 吴裕雄--天生自然 pythonTensorFlow图形数据处理:多线程队列操作
import tensorflow as tf #1. 定义队列及其操作. queue = tf.FIFOQueue(100,"float") enqueue_op = queue ...
- 吴裕雄--天生自然 pythonTensorFlow图形数据处理:图像预处理完整样例
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt #随机调整图片的色彩,定义两种顺序. def di ...
- 吴裕雄--天生自然 pythonTensorFlow图形数据处理:TensorFlow图像处理函数
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt #读取图片 image_raw_data = tf ...
- 吴裕雄--天生自然 pythonTensorFlow图形数据处理:读取MNIST手写图片数据写入的TFRecord文件
import numpy as np import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_dat ...
随机推荐
- c\c++ 中字符串分割,并且转换为整形数据
在项目开发中,经常使用到字符串分割, 并且将其转换为整形(比如IP的分割获取,MAC地址的分割获取等),代码如下: #ifndef _UNICODE void StrToIntData( char * ...
- 从零开始Windows环境下安装python+tensorflow
从零开始Windows环境下安装python+tensorflow 2017年07月12日 02:30:47 qq_16257817 阅读数:29173 标签: windowspython机器学习te ...
- 15. react UI组件和容器组件的拆分 及 无状态组件
1.组件的拆分 组件拆分的前提 当所有的逻辑都出现在一个组件内时 组件会变得非常复杂 不便与代码的维护 所以对组件进行拆分 IU组件 进行页面渲染 容器组件 进行逻辑操作 UI组件的拆分 新建一个 ...
- Spring Boot2(001):入门介绍和一些官网链接参考
Spring官方文档比较齐全,学习的过程中可以多参考官方文档,最权威的版本.01.Spring Boot的一些官方链接 01.01 Spring Boot官网 https://spring.io/pr ...
- 一、VIP课程:互联网工程专题 01-Git基本概念与核心命令掌握
第一课:Git基本概念与核心命令掌握.docx 课程概要: GIT 体系概述 GIT 核心命令使用 GIT 底层原理 一.GIT体系概述 1.使用方式区别 从本地把文件推送远程服务,SVN只需要com ...
- Day 9:双列集合Map及实现该接口的类的常用方法
为什么要学双列集合? 因为单列集合无法处理映射关系,会有成对出现的数据 Map接口 如果是实现了Map接口的集合类,具备的特点: 存储的数据都是以键值对的形式存在的,键不可重复,值可以重复 Map接 ...
- 18 12 27 css 盒模型使用 以及相关技巧问题 元素溢出 块元素、内联元素、内联块元素
盒子模型的实际尺寸 盒子的width和height设置的是盒子内容的宽和高,不是盒子本身的宽和高,盒子的真实尺寸计算公式如下: 盒子宽度 = width + padding左右 + border左右 ...
- OpenCV2基础操作----直线、矩形、圆、椭圆函数的使用
opencv2几个画图函数的调用 要用到几个随机变量: int fr = rand()%frame.rows; int fc = rand()%frame.cols; int b = rand()%2 ...
- 【每日Scrum】第八天冲刺
一.计划会议内容 继续昨天的设计 二.任务看板 任务看板 已完成:登录与个人界面布局实现 进行中:UI设计美化,,地图主界面 待进行:功能整合,连接数据库 三.scrum讨论照片 四.产品的状态 无 ...
- vscode 集成git bash, mingw, mintty 的terminal
设置 右上角打开json文件的设置 输入以下代码: "terminal.external.windowsExec": "D:\\Program Files\\Git\\b ...