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文件存储的更多相关文章

  1. Tensorflow 读写 tfrecord 文件(Python3)

    TensorFlow笔记博客:https://blog.csdn.net/xierhacker/article/category/6511974 写入tfrecord文件 import tensorf ...

  2. Tensorflow 中(批量)读取数据的案列分析及TFRecord文件的打包与读取

    内容概要: 单一数据读取方式: 第一种:slice_input_producer() # 返回值可以直接通过 Session.run([images, labels])查看,且第一个参数必须放在列表中 ...

  3. TFRecord文件的读写

    前言在跑通了官网的mnist和cifar10数据之后,笔者尝试着制作自己的数据集,并保存,读入,显示. TensorFlow可以支持cifar10的数据格式, 也提供了标准的TFRecord 格式,而 ...

  4. TensorFlow笔记-文件读取

    小数量数据读取 这些只用于可以完全加载到内存中的小型数据集: 1,储存在常数中 2,储存在变量中,初始化后,永远不改变它的值 使用常量 training_data = ... training_lab ...

  5. 生成TFRecord文件完整代码实例

    import os import json def get_annotation_dict(input_folder_path, word2number_dict): label_dict = {} ...

  6. AI tensorflow模型文件

    tensorflow模型可以利用tf.train.Saver类保存成文件.一个模型包含下面四个文件. meta文件 存储计算图的protobuf. data-00000-of-00001文件和inde ...

  7. 吴裕雄 python 神经网络——TensorFlow TFRecord样例程序

    import numpy as np import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_dat ...

  8. 吴裕雄--天生自然 pythonTensorFlow图形数据处理:将MNIST手写图片数据写入TFRecord文件

    import numpy as np import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_dat ...

  9. Android数据存储之Android 6.0运行时权限下文件存储的思考

    前言: 在我们做App开发的过程中基本上都会用到文件存储,所以文件存储对于我们来说是相当熟悉了,不过自从Android 6.0发布之后,基于运行时权限机制访问外置sdcard是需要动态申请权限,所以以 ...

随机推荐

  1. Guitar Por如何演奏刮弦

    每当我们听到吉他现场演出的时候,看到吉他手在激烈的刮弦时,都觉得很酷,非常有感染力.刮弦在我们弹吉他或编曲时,会经常用到,虽然时间很短,但会为你加分不少. 那么我们应该如何演奏刮弦呢,我们先用E5和弦 ...

  2. vs2013突然打不开项目,项目全部不兼容

    转载:https://forum.cocos.com/t/vs2013/40931 转载:https://jingyan.baidu.com/article/cdddd41c7c6b5353cb00e ...

  3. JSESSIONID的简单说明

    原文地址:http://blog.csdn.net/chunqiuwei/article/details/23461995 1)第一次访问服务器的时候,会在响应头里面看到Set-Cookie信息(只有 ...

  4. Pycharm 的设置--参数设置(运行.py文件带参数,例如argument)

    程序运行时,如果需要输入参数,如下图中程序代码: 在生成exe后,程序在控制台下运行时格式为: 这种情况在调试程序时,如果只是在Pycharm环境中简单执行“Run”菜单下的“Run”命令,会出现以下 ...

  5. HTML有哪些标签?html常用标签大全

    html中标签有很多,每一种标签都有着不同的用处,下面这篇文章php中文网给大家总结html常用的标签,每一种标签都会跟随一个例子,话不多说,让我们来看看具体内容.<font>字体标签,用 ...

  6. 调参贝叶斯优化(BayesianOptimization)

    from sklearn.datasets import make_classification from sklearn.model_selection import cross_val_score ...

  7. Request类源码分析

    通过APIView进入找到Request的源码 可以看见一堆属性和方法,其中request.data其实是一个方法,被包装成一个属性 继续看__getattr__和query_params方法: 代码 ...

  8. php接口实现拖拽排序功能

    列表拖拽排序是一个很常见的功能,但是后端接口如何处理却是一个令人纠结的问题 如何实现才能达到效率最高呢 先分析一个场景,假如有一个页面有十条数据,所谓的拖拽就是在这十条数据来来回回的拖,但是每次拖动都 ...

  9. ArcGIS Pro开发Web3D应用(2)——地图分屏对比(多屏对比)思路

    很多应用中都需要用到地图联动.多屏对比.二三维分屏.大屏显示,有图形可视化的地方就有事件响应触发:鼠标按下.移动.鼠标滚轮,由此触发了地图上坐标或范围的变化,将这些变化发送给另一个地图并响应这些变化, ...

  10. LInux 些许知识

    1.Linux下去掉^M的方法 ①dos2unix filename ②sed -i 's/^M//g' filename #注意:^M的输入方式是 Ctrl + v ,然后Ctrl + M 2.so ...