TFRecords文件
是一种二进制文件,能够很好的利用内存,更方便复制和移动,并且不需要单独的标签文件
使用步骤
1)获取数据
2)将数据填入到Example协议内存块(protocol buffer)
3)将协议内存块序列化为字符串,并且通过 tf.python_io.TFRecordWriter写入到TFRecords文件
文件格式 *.tfrecords
Example结构

●tf. train. Example协议内存块(protocol buffer)(协议内存块包含了字段 Features )
●Features包含了一个Feature 字段
●Feature 中包含要写入的数据、并指明数据类型。
这是一个样本的结构,批数据需要循环存入这样的结构
- tf.train.Example(features=None)
写入tfrecords文件
features: tf.train.Features类型的特征实例
return: example格式协议块
- tf.train.Features(feature=None)
构建每个样本的信息键值对
feature: 字典数据,key为要保存的名字
value为tf.train.Feature实例
return: Features类型
- tf.train.Feature(options)
options: 例如
bytes_ litftrain. BytesList(value=[Bytes])
int64. lststf.train. Int64List(value=[Value)
支持存入的类型如下
tf.train.Int64List(value=Malue])
tf.train.BytesList(value=[Bytes])
tf.train.FloatList(value=[value]
流程分析
1)构造存储实力 tf.python_io.TFRecordWriter(patch)
2)循环将数据填入到Example协议内存块(protocol buffer)
example解析
●tf.parse. single_ example(serialized, features=None, name=None)
解析一个单一的Example原型
serialized: 标量字符串Tensor, - 一个序列化的Example
features: dict字典数据,键为读取的名字,值为FixedLenFeature
return:一 个键值对组成的字典,键为读取的名字
●tf.FixedL enFeature(shape, dtype)
shape: 输入数据的形状,一般不指定,为空列表
dtype: 输入数据类型,与存储进文件的类型要一致
类型只能是float32, int64, string
案例:
写入:

读取:
流程:
1)构造文件名队列

2)读取和解码
读取

解析example

解码

3)构造批处理队列
