Skip to content

Instantly share code, notes, and snippets.

@novasush
Created March 7, 2020 18:09
Show Gist options
  • Save novasush/cc3d4f33838ba71bed9e4ca8df88228a to your computer and use it in GitHub Desktop.
Save novasush/cc3d4f33838ba71bed9e4ca8df88228a to your computer and use it in GitHub Desktop.
def read_tfrecord(serialized_example):
# Create the feature description dictionary
feature_description = {
'image': tf.io.FixedLenFeature((), tf.string, ""),
'label': tf.io.FixedLenFeature((), tf.int64, -1),
}
# Parse the serialized_example and decode the image
example = tf.io.parse_single_example(serialized_example, feature_description)
image = tf.io.decode_jpeg(example['image'], channels=3)
image = tf.cast(image, tf.float32)
# Normalize the pixels in the image
image = image/255.
# Resize the image to (224, 224) using tf.image.resize
image = tf.image.resize(image, [224, 224])
return image, example['label']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment