This was a custom function included in the assignment
EXERCISE: shuffle and map the batches
This will turn the 3 sets into batches
so you can train and load batches
def format_image(features):
image = features[‘image’]
image = tf.image.resize(image, IMAGE_SIZE) / 255.0
return image, features[‘label’]
As far as i understand the function takes in the tfds.record dataset and converts them into a tuple of images and label. While this works in the assignment when i run it like this:
train_batches = train_examples.shuffle(num_examples).map(format_image).batch(BATCH_SIZE)
, when i run the function like this:
image,label=format_image(train_examples)
I am getting the following error–
TypeError Traceback (most recent call last)
Input In [13], in <cell line: 1>()
----> 1 image, label=format_image(train_examples)
Input In [6], in format_image(features)
7 def format_image(features):
----> 8 image = features[‘image’]
9 image = tf.image.resize(image, IMAGE_SIZE) / 255.0
10 return image, features[‘label’]
TypeError: ‘PrefetchDataset’ object is not subscriptable
Can someone help me understand this?