Skip to content

Instantly share code, notes, and snippets.

@dpoulopoulos
Created August 24, 2021 14:15
Show Gist options
  • Save dpoulopoulos/22d18fc0c212e651bda65b891018a14a to your computer and use it in GitHub Desktop.
Save dpoulopoulos/22d18fc0c212e651bda65b891018a14a to your computer and use it in GitHub Desktop.
def image_feature(value):
"""Returns a bytes_list from a string / byte."""
return tf.train.Feature(
bytes_list=tf.train.BytesList(value=[tf.io.encode_jpeg(value).numpy()])
)
def bytes_feature(value):
"""Returns a bytes_list from a string / byte."""
return tf.train.Feature(
bytes_list=tf.train.BytesList(value=[value.encode()])
)
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])
)
def float_feature_list(value):
"""Returns a list of float_list from a float / double."""
return tf.train.Feature(
float_list=tf.train.FloatList(value=value)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment