吴裕雄 python 神经网络——TensorFlow 输入文件队列
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 = ('E:\\temp\\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() files = tf.train.match_filenames_once("E:\\temp\\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)
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)
吴裕雄 python 神经网络——TensorFlow 输入文件队列的更多相关文章
- 吴裕雄 python 神经网络——TensorFlow 多线程队列操作
import tensorflow as tf queue = tf.FIFOQueue(100,"float") enqueue_op = queue.enqueue([tf.r ...
- 吴裕雄 python 神经网络——TensorFlow 队列操作
import tensorflow as tf q = tf.FIFOQueue(2, "int32") init = q.enqueue_many(([0, 10],)) x = ...
- 吴裕雄 python 神经网络——TensorFlow 循环神经网络处理MNIST手写数字数据集
#加载TF并导入数据集 import tensorflow as tf from tensorflow.contrib import rnn from tensorflow.examples.tuto ...
- 吴裕雄 python 神经网络——TensorFlow 使用卷积神经网络训练和预测MNIST手写数据集
import tensorflow as tf import numpy as np from tensorflow.examples.tutorials.mnist import input_dat ...
- 吴裕雄 python 神经网络——TensorFlow 训练过程的可视化 TensorBoard的应用
#训练过程的可视化 ,TensorBoard的应用 #导入模块并下载数据集 import tensorflow as tf from tensorflow.examples.tutorials.mni ...
- 吴裕雄 python 神经网络——TensorFlow实现搭建基础神经网络
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def add_layer(inputs, in_ ...
- 吴裕雄 python 神经网络——TensorFlow图片预处理调整图片
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def distort_color(image, ...
- 吴裕雄 python 神经网络TensorFlow实现LeNet模型处理手写数字识别MNIST数据集
import tensorflow as tf tf.reset_default_graph() # 配置神经网络的参数 INPUT_NODE = 784 OUTPUT_NODE = 10 IMAGE ...
- 吴裕雄 python 神经网络——TensorFlow pb文件保存方法
import tensorflow as tf from tensorflow.python.framework import graph_util v1 = tf.Variable(tf.const ...
随机推荐
- jumpserver 常见错误解决
官方链接:https://jumpserver.readthedocs.io/zh/master/faq_install.html 重启jumpserver后台 #cd /opt#python3.6 ...
- 关于static 关键字的总结
转发自:https://www.cnblogs.com/xrq730/p/4820992.html 前言 之前讲到final关键字的作用是每次面试的时候我必问求职者的两个问题之一,另外一个问题就是文本 ...
- EntityFramework使用SqlCe数据库
使用NuGet添加下面3个引用 App.Config的<entityFramework>节点这样配置: <entityFramework> <defaultConnect ...
- django入门与实践(开)
1.什么是Django? 基于python的高级web开发框架 高效 快速 免费 开源 正常上网流程 浏览器浏览网页的基本原理 请求响应过程 开发环境搭建 Python Django pip inst ...
- 初识hadoop --- (分布式文件系统 + 分块计算)
[转载] + 整理 2016-11-18 使用范围: Hadoop典型应用有:搜索.日志处理.推荐系统.数据分析.视频图像分析.数据保存等. Hadoop历史 雏形开始于2002年的Apache的Nu ...
- 解决安装VMware Player出错,提示安装程序无法继续,microsoft runtime dll安装程序未能完成安装
方案一: 以兼容模式运行和管理员方式运行安装程序,右键点击安装文件选择属性,在弹出的面板中修改兼容性如下 方案二: 下载最近版的VMWare player安装包哈哈 方案三: 1.双击VMware P ...
- 转 C#中哈希表(HashTable)的用法详解
看了一遍有关哈希表的文字,作者总结的真是不错 .收藏起来 1. 哈希表(HashTable)简述 在.NET Framework中,Hashtable是System.Collections命名空间提 ...
- 链剖-What you are?-大话西游-校内oj2440
This article is made by Jason-Cow.Welcome to reprint.But please post the writer's address. http://ww ...
- [蓝桥杯][基础训练]Huffuman树
Description Huffman树在编码中有着广泛的应用.在这里,我们只关心Huffman树的构造过程. , p1, …, pn-1},用这列数构造Huffman树的过程如下:1. 找到{pi} ...
- 安装Linux系统后配置的一般步骤
安装linux后配置的一般步骤 最近在尝试不同的linux系统,记录一下安装完linux之后常用的软件的安装方法 1.源的更新 ubuntu 源的更新方法 参考(没有测试过,但是都大同小异,不行就换一 ...