TensorFlow TFRecord
把mnist数据集另存为TFRecord格式
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import numpy as npdef _int64_feature(value):return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))def _bytes_feature(value):return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))mnist = input_data.read_data_sets("MNIST_data/", dtype=tf.uint8, one_hot=True)images = mnist.train.images
print(images.shape)
pixels = images.shape[1] #图像分辩率28*28=784
labels = mnist.train.labelsfilename = "MNIST_data/output.tfrecords"
writer = tf.python_io.TFRecordWriter(filename)num = mnist.train.num_examples
print(num)
for i in range(num):example = tf.train.Example(features=tf.train.Features(feature={'pixels':_int64_feature(pixels),'label':_int64_feature(np.argmax(labels[i])),'image_raw':_bytes_feature(images[i].tostring())}))writer.write(example.SerializeToString())
writer.close()
读TFRecord格式
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import numpy as np#队列
queue = tf.train.string_input_producer(["MNIST_data/output.tfrecords"])reader = tf.TFRecordReader()
_, serialized_example = reader.read(queue)#解析数据,对应写入格式
features = tf.parse_single_example(serialized_example,features={'image_raw':tf.FixedLenFeature([], tf.string),'pixels':tf.FixedLenFeature([], tf.int64),'label':tf.FixedLenFeature([], tf.int64)} )images = tf.decode_raw(features['image_raw'], tf.uint8)
labels = tf.cast(features['label'], tf.int32)
pixels = tf.cast(features['pixels'], tf.int32)with tf.Session() as sess:coord = tf.train.Coordinator()#启动多线程输入数据threads = tf.train.start_queue_runners(sess=sess, coord=coord)for i in range(2):image, label, pixel = sess.run([images, labels, pixels])print(label)print(image.shape)print(pixel)
TensorFlow TFRecord相关推荐
- Tensorflow—TFRecord文件生成与读取
Tensorflow-TFRecord文件生成与读取 微信公众号:幼儿园的学霸 个人的学习笔记,关于OpenCV,关于机器学习, -.问题或建议,请公众号留言; 目录 文章目录 Tensorflow- ...
- Tensorflow—tfrecord数据集生成与使用
参考内容: 数据读取的官方教程:Tensorflow导入数据以及使用数据 tfrecord数据集生成: 数据准备:图片数据+图片目录与label一一对应的的txt 先读取图片信息的txt文件,得到每个 ...
- TensorFlow TFRecord数据集的生成与显示
##TFRecord## TensorFlow提供了TFRecord的格式来统一存储数据,TFRecord格式是一种将图像数据和标签放在一起的二进制文件,能更好的利用内存,在tensorflow中快速 ...
- Tensorflow TFRecord: Can't parse serialized example
问题描述 InvalidArgumentError: Key: 'label'. Can't parse serialized Example. 保存tfrecord def save_tfrecor ...
- TensorFlow框架案例实战
第1课 Tensorflow基础 知识点1:计算图的概念与使用 知识点2:张量的概念与使用 知识点3:Tensorflow与session 实战项目:Tensorflow playground与非线性 ...
- Apache Beam 使用指南(一)
Apache Beam 一.概述 更多 Apache Beam 代码案例:https://github.com/xiye50070/Apache-Beam-Model.git Apache Beam是 ...
- TensorFlow 制作自己的TFRecord数据集
TensorFlow 制作自己的TFRecord数据集 准备图片数据 网上下载了2类吉他和房子的图片, 全部 resize成64*64大小 如下图, 保存项目下: 现在利用这2 类 共108张图片制作 ...
- Tensorflow 处理libsvm格式数据生成TFRecord (parse libsvm data to TFRecord)
#写libsvm格式 数据 write libsvm #!/usr/bin/env python #coding=gbk # ===================================== ...
- 【TensorFlow】TFRecord数据集的制作:读取、显示及代码详解
在跑通了官网的mnist和cifar10数据之后,笔者尝试着制作自己的数据集,并保存,读入,显示. TensorFlow可以支持cifar10的数据格式, 也提供了标准的TFRecord 格式. te ...
最新文章
- Java8 forEach
- maven no Maven Dependencies view
- python读取excel表格-python读取excel表格中的数据
- 更改应用程序图标_【iOS12人机交互指南】6.2-应用图标
- Delphi IDE扩展工具,在IDE中增加Google翻译器
- qt在visual studio 2015下的使用
- 他们也曾在数学“苦海”里痛不欲生
- Java 生成随机数的 N 种方法
- PHP 报错 Use of undefined constant prop_values - ass...
- [转载] python怎么获取redis中的数据_python操作redis数据库
- XStream实现缓存
- centos6.8 hugepage设置
- K8s部署Nexus3管理Docker镜像
- oracle 10g、11g、 12c、19c有什么区别
- 三星手机服务器暂时不可用是怎么回事,三星手机用户注意了!三星云将于2017年1月20日起停止服务...
- css 背景图片虚化磨砂效果
- upperbound找不到_upper_bound 和lower_bound 的返回值问题
- webstorm js中文乱码
- VS2019+OpenCV配置
- 如何理解三维曲面的法线向量公式?
热门文章
- Spring3 MVC Login Interceptor(Spring 拦截器)
- Android程序开发中关于设置全屏无效问题
- 米老鼠想吞并喜羊羊,不是赤裸裸的文化侵略是什么
- ……OleContainer中嵌入WORD后,用什么办法显示滚动条???……
- 中石油训练赛 - Check List(线段树维护偏序问题)
- 中石油训练赛 - One-Way Conveyors(边双缩点+树上差分)
- HDU - 2896 病毒侵袭(AC自动机)
- php新闻模块,新闻模块的代码~!
- TCP 和 UDP 绑定同一端口通信的解释
- STL 之find,find_if,find_end,find_first_of