Skip to content

Instantly share code, notes, and snippets.

@ntakouris
Created September 25, 2020 11:33
Show Gist options
  • Save ntakouris/93b1a7e5e047617d5fa6ed78a77405a9 to your computer and use it in GitHub Desktop.
Save ntakouris/93b1a7e5e047617d5fa6ed78a77405a9 to your computer and use it in GitHub Desktop.
def serialize_example(feature0, feature1, feature2, feature3):
"""
Creates a tf.train.Example message ready to be written to a file.
"""
# Create a dictionary mapping the feature name to the tf.train.Example-compatible
# data type.
feature = {
'feature0': _int64_feature(feature0),
'feature1': _int64_feature(feature1),
'feature2': _bytes_feature(feature2),
'feature3': _float_feature(feature3),
}
# Create a Features message using tf.train.Example.
example_proto = tf.train.Example(features=tf.train.Features(feature=feature))
return example_proto.SerializeToString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment