Skip to content

Instantly share code, notes, and snippets.

@kevashcraft
Last active February 7, 2020 18:49
Show Gist options
  • Save kevashcraft/dbbeedc5c751ab622ac63d91658fb833 to your computer and use it in GitHub Desktop.
Save kevashcraft/dbbeedc5c751ab622ac63d91658fb833 to your computer and use it in GitHub Desktop.
Writing a TFRecord File
# Write a ambient, target, and label data to a TFRecords file
with tf.io.TFRecordWriter('examples.tfrecord') as training_file:
for ambient, target, label in batch: # batch is a list of (ambient, target, label) tuples
features = {
'label': tf.train.Feature(int64_list=tf.train.Int64List(value=[label])),
'ambient': tf.train.Feature(float_list=tf.train.FloatList(value=ambient.tolist())), # ambient is a 1-D np array
'target': tf.train.Feature(float_list=tf.train.FloatList(value=target.tolist())) # target is a 1-D np array
}
example_proto = tf.train.Example(features=tf.train.Features(feature=features))
training_file.write(example_proto.SerializeToString())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment