Skip to content

Instantly share code, notes, and snippets.

@kevashcraft
Created February 7, 2020 18:37
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/cfb82943ac764852955445216f8235ea to your computer and use it in GitHub Desktop.
Save kevashcraft/cfb82943ac764852955445216f8235ea to your computer and use it in GitHub Desktop.
Read TFRecord File into TF Dataset
# Read a TFRecord file into a TF Dataset
def map_fn(serialized_example):
feature = {
'label': tf.io.FixedLenFeature([1], tf.int64),
'ambient': tf.io.FixedLenFeature([16000], tf.float32),
'target': tf.io.FixedLenFeature([4000], tf.float32)
}
example = tf.io.parse_single_example(serialized_example, feature)
ambient = tf.expand_dims(example['ambient'], 1)
target = tf.expand_dims(example['target'], 1)
label = tf.cast(example['label'], tf.int32)
return (ambient, target), label
dataset = tf.data.TFRecordDataset('example.tfrecord')
dataset = dataset.map(map_fn)
# dataset = dataset.repeat()
# dataset = dataset.shuffle(1000)
# dataset = dataset.batch(64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment