Skip to content

Instantly share code, notes, and snippets.

@CihanSoylu
Created July 17, 2019 13:04
Show Gist options
  • Save CihanSoylu/75c4cc56567b7c8c330ec66b9f80ba77 to your computer and use it in GitHub Desktop.
Save CihanSoylu/75c4cc56567b7c8c330ec66b9f80ba77 to your computer and use it in GitHub Desktop.
The functions provided by Tensorflow to create tf.train.Feature protocol buffer messages
def _bytes_feature(value):
"""Returns a bytes_list from a string / byte."""
# If the value is an eager tensor BytesList won't unpack a string from an EagerTensor.
if isinstance(value, type(tf.constant(0))):
value = value.numpy()
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
def _float_feature(value):
"""Returns a float_list from a float / double."""
return tf.train.Feature(float_list=tf.train.FloatList(value=[value]))
def _int64_feature(value):
"""Returns an int64_list from a bool / enum / int / uint."""
return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment