tf.train.Example
TFRecord can be understood as a list file composed of a series of serialized elements, each of which is composed tf.train.Example
of several tf.train.Feature
dictionaries.
write record
Read the data element into memory;
Convert the element into
tf.train.Example
an object (each consiststf.train.Example
of severaltf.train.Feature
dictionaries, so you need to create a Feature dictionary first);Serialize
tf.train.Example
the object to a string and write it to a TFRecord file via a predefined onetf.io.TFRecordWriter
.
import tensorflow as tf
import os
data_dir = './catsdogs'
train_cats_dir = data_dir + '/train/Cat/'
train_dogs_dir = data_dir + '/train/Dog/'
train_cat_filenames = [train_cats_dir + filename for filename in os.listdir(train_cats_dir)]
train_dog_filenames = [train_dogs_dir + filename for filename in os.listdir(train_dogs_dir)]
train_filenam