Created
February 7, 2020 18:37
-
-
Save kevashcraft/cfb82943ac764852955445216f8235ea to your computer and use it in GitHub Desktop.
Read TFRecord File into TF Dataset
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
# 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