tensorflow tfrecord文件存储
import tensorflow as tf
import numpy as np
import skimage
from skimage import data, io, color
from PIL import Image path = "1.tfrecords"
img_path = '/data/test/img/1.png' with tf.python_io.TFRecordWriter(path) as writer:
# list: int or float
a = 1024
b = 10.24 c = [0.1, 0.2, 0.3]
c = np.array(c).astype(np.float32).tobytes() d = [[1, 2], [3, 4]]
d = np.array(d).astype(np.int8).tobytes() e = "Python"
e = bytes(e, encoding='utf-8') img = io.imread(img_path)
img = img.astype(np.uint8).tobytes() img2 = Image.open(img_path)
img2 = img2.resize((256, 256))
img2 = img2.tobytes() example = tf.train.Example(features=tf.train.Features(feature={
'a': tf.train.Feature(int64_list=tf.train.Int64List(value=[a])),
'b': tf.train.Feature(float_list=tf.train.FloatList(value=[b])),
'c': tf.train.Feature(bytes_list=tf.train.BytesList(value=[c])),
'd': tf.train.Feature(bytes_list=tf.train.BytesList(value=[d])),
'e': tf.train.Feature(bytes_list=tf.train.BytesList(value=[e])),
'image': tf.train.Feature(bytes_list=tf.train.BytesList(value=[img])),
'image2': tf.train.Feature(bytes_list=tf.train.BytesList(value=[img2])), }))
writer.write(example.SerializeToString()) # 读取
filename_queue = tf.train.string_input_producer([path])
_, serialized_example = tf.TFRecordReader().read(filename_queue) features = tf.parse_single_example(serialized_example,
features={
'a': tf.FixedLenFeature([], tf.int64),
'b': tf.FixedLenFeature([], tf.float32),
'c': tf.FixedLenFeature([], tf.string),
'd': tf.FixedLenFeature([], tf.string),
'e': tf.FixedLenFeature([], tf.string),
'image': tf.FixedLenFeature([], tf.string),
'image2': tf.FixedLenFeature([], tf.string), }) a = features['a'] # 返回是张量
b = features['b'] c = features['c']
c = tf.decode_raw(c, tf.float32) d = features['d']
d = tf.decode_raw(d, tf.int8)
d = tf.reshape(d, [2, 2]) e = features['e'] img = tf.decode_raw(features['image'], tf.uint8)
img = tf.reshape(img, shape=[256, 256, 3]) img2 = tf.decode_raw(features['image2'], tf.uint8)
img2 = tf.reshape(img2, [256, 256,3]) with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
tf.train.start_queue_runners(sess=sess) print(sess.run([a, b, c, d, e])) e = sess.run(e)
print(type(e), bytes.decode(e)) img = sess.run(img)
io.imshow(img) img2 = sess.run(img2)
io.imshow(img2)
tensorflow tfrecord文件存储的更多相关文章
- Tensorflow 读写 tfrecord 文件(Python3)
TensorFlow笔记博客:https://blog.csdn.net/xierhacker/article/category/6511974 写入tfrecord文件 import tensorf ...
- Tensorflow 中(批量)读取数据的案列分析及TFRecord文件的打包与读取
内容概要: 单一数据读取方式: 第一种:slice_input_producer() # 返回值可以直接通过 Session.run([images, labels])查看,且第一个参数必须放在列表中 ...
- TFRecord文件的读写
前言在跑通了官网的mnist和cifar10数据之后,笔者尝试着制作自己的数据集,并保存,读入,显示. TensorFlow可以支持cifar10的数据格式, 也提供了标准的TFRecord 格式,而 ...
- TensorFlow笔记-文件读取
小数量数据读取 这些只用于可以完全加载到内存中的小型数据集: 1,储存在常数中 2,储存在变量中,初始化后,永远不改变它的值 使用常量 training_data = ... training_lab ...
- 生成TFRecord文件完整代码实例
import os import json def get_annotation_dict(input_folder_path, word2number_dict): label_dict = {} ...
- AI tensorflow模型文件
tensorflow模型可以利用tf.train.Saver类保存成文件.一个模型包含下面四个文件. meta文件 存储计算图的protobuf. data-00000-of-00001文件和inde ...
- 吴裕雄 python 神经网络——TensorFlow TFRecord样例程序
import numpy as np import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_dat ...
- 吴裕雄--天生自然 pythonTensorFlow图形数据处理:将MNIST手写图片数据写入TFRecord文件
import numpy as np import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_dat ...
- Android数据存储之Android 6.0运行时权限下文件存储的思考
前言: 在我们做App开发的过程中基本上都会用到文件存储,所以文件存储对于我们来说是相当熟悉了,不过自从Android 6.0发布之后,基于运行时权限机制访问外置sdcard是需要动态申请权限,所以以 ...
随机推荐
- FL Studio里的常规设置介绍
上期我们介绍了FL Studio中的项目设置,今天我们来介绍FL Studio中的常规设置.要打开常规设置,我们需要在主菜单中选择选项>常规选项,当然也可以直接按快捷键F10. “常规设置”页面 ...
- Python day 06
day06 数据类型(四) 今日内容 集合 内存相关 深浅拷贝 补充 补充 列表 reverse,反转. v1 = [1,2,3111,32,13] print(v1) # [1,2,311,32,1 ...
- 使用Python创建一个简易的Web Server
Python 2.x中自带了SimpleHTTPServer模块,到Python3.x中,该模块被合并到了http.server模块中.使用该模块,可以快速创建一个简易的Web服务器. 我们在C:\U ...
- oracle更改字符集为zhs16GBK
PDBalter pluggable database PDBANBOB open; alter session set container=pdbanbob; ALTER SYSTEM ENABLE ...
- 什么是LDAP?
LDAP是轻量目录访问协议,英文全称是Lightweight Directory Access Protocol,一般都简称为LDAP.它是基于X.500标准的,但是简单多了并且可以根据需要定制.与X ...
- 【转载】Jmeter 性能测试入门
[转载]Jmeter性能测试 入门 Jmeter是一款优秀的开源测试工具, 是每个资深测试工程师,必须掌握的测试工具,熟练使用Jmeter能大大提高工作效率. 熟练使用Jmeter后, 能用Jmete ...
- MTLAB: 稀疏矩阵的表示-sparse
我们在学习数值算法的过程中,发现像有限差分,谱方法和有限元方法的微分矩阵($\tt Differentiation~Matrices$)往往是稀疏的(即非零元素个数为$O(N)$,其中$N$为矩阵的维 ...
- document.body.scrollTop和document.documentElement.scrollTop 以及值为0的问题
转自http://wo13145219.iteye.com/blog/2001598 一.先遇到document.body.scrollTop值为0的问题 做页面的时候可能会用到位置固定的层,读取do ...
- ASP.NET MVC 简单介绍①
ASP.NET MVC 简单介绍① 只做了重要描述,内容出自菜鸟教程网站内容. 目录 1布局 2HTML 帮助器 3.Razor 语法 4.添加样式 5.Layout 6. Controllers ...
- python之asyncio三种应用方法
1.直接使用asyncio.run方法2.同步的效果,用await调用函数3.创建任务(asyncio.create_task),并发运行任务(await asyncio.gather) import ...