Skip to content

Instantly share code, notes, and snippets.

@kevashcraft
Last active February 4, 2020 16:32
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/c32a8a0d61a5282f1af48c8f5e328771 to your computer and use it in GitHub Desktop.
Save kevashcraft/c32a8a0d61a5282f1af48c8f5e328771 to your computer and use it in GitHub Desktop.
Writing a TFRecord File
with tf.io.TFRecordWriter('examples.tfrecord') as training_file:
for features, label in batch:
features = {
'label': tf.train.Feature(int64_list=tf.train.Int64List(value=[label])),
'features': tf.train.Feature(float_list=tf.train.FloatList(value=features)) # expects list, so if numpy use .tolist() and ensure it's 1-D
}
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