TFRecord —— tensorflow 下的统一数据存储格式

tensorflow 提供了统一的数据存储格式,即 TFRecord(record 表示记录),以提高程序的可扩展性,当数据来源十分复杂时,仍能有效记录输入数据中的信息。

1. tfrecord 使用流程

比如对于 mnist 训练数据集,我们要将其 label 和像素内容以 TFRecord 的形式写入到本地。

所需 api:

  • tf.python_io.TFRecordWriter(path):writer
  • tf.train.Example() ⇒ 构建一条 record
from tensorflow.examples.tutorials.mnist import input_data

mnist = input_data(train_dir='./MNIST_DATA', dtype=tf.uint8, one_hot=True)
labels = mnist.train.labels
images = mnist.train.images

num_images, num_pixels = images.shape

你可能感兴趣的:(TFRecord —— tensorflow 下的统一数据存储格式)