Created
February 4, 2020 16:36
-
-
Save kevashcraft/493d233562a48b3d2c4dd9322a25e865 to your computer and use it in GitHub Desktop.
Reading a TFRecord File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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