Skip to content

Instantly share code, notes, and snippets.

@kevashcraft
Created February 4, 2020 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevashcraft/493d233562a48b3d2c4dd9322a25e865 to your computer and use it in GitHub Desktop.
Save kevashcraft/493d233562a48b3d2c4dd9322a25e865 to your computer and use it in GitHub Desktop.
Reading a TFRecord File
label_size = 1 # the length of the previously written label
feature_size = 256 # the length of the previously written feature lists
def map_fn(serialized_example):
feature = {
'label': tf.io.FixedLenFeature([label_)size], tf.int64),
'features': tf.io.FixedLenFeature([feature_size], tf.float32)
}
example = tf.io.parse_single_example(serialized_example, feature)
features = example['features']
label = tf.cast(example['label'], tf.int32)
return features, label
dataset = tf.data.TFRecordDataset('examples.tfrecord')
dataset = dataset.map(map_fn)
dataset = dataset.batch(1)
# to see the data
for features, label in dataset.take(1):
print(features.shape, label.shape)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment