I'm following along the keras tutorial on image classification. I have created a tf.data.Dataset
and specified a single batch using the .take()
method:
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
"data",
validation_split=0.2,
subset="training",
image_size=(224,224),
batch_size=32)
train_batch = train_ds.take(1)
Inspecting the train_batch
object, as expected, I see it is made up of two objects: images and labels:
<TakeDataset shapes: ((None, 224, 224, 3), (None,)), types: (tf.float32, tf.int32)>
The tutorial states uses the following code to plot the images in this batch:
for images, labels in train_batch:
for i in range(32):
ax = plt.subplot(4, 8, i + 1)
plt.imshow(images[i].numpy().astype("uint8"))
My question is how does for images, labels in train_batch:
manage to specify the images and labels separately. Apart from enumerate
I have not come across specifying two variables in a for loop. Is this the only way to access the images and labels in a batch?