def decode(serialized_example):
"""
Parses an image and label from the given `serialized_example`.
It is used as a map function for `dataset.map`
"""
IMAGE_SIZE = 28
IMAGE_PIXELS = IMAGE_SIZE * IMAGE_SIZE
features = tf.parse_single_example(
serialized_example,
features={
'image_raw': tf.FixedLenFeature([], tf.string),
'label': tf.FixedLenFeature([], tf.int64),
})
image = tf.decode_raw(features['image_raw'], tf.uint8)
label = tf.cast(features['label'], tf.int32)
image.set_shape((IMAGE_PIXELS))
return image, label
Preparing MNIST data for Distributed DL
This notebook uses MNIST as an example to show how to load TFRecord files for distributed DL.
Before running this notebook, you must:
tfrecord_location
.