title: Accessing Images and Labels Inside a tf.data.Dataset Object
body: <p>I'm following along the <a href="https://keras.io/examples/vision/image_classification_from_scratch/" rel="nofollow noreferrer">keras tutorial</a> on image classification. I have created a <code>tf.data.Dataset</code> and specified a single batch using the <code>.take()</code> method:</p>
  <pre><code>train_ds = tf.keras.preprocessing.image_dataset_from_directory(
      &quot;data&quot;,
      validation_split=0.2,
      subset=&quot;training&quot;,
      image_size=(224,224),
      batch_size=32)
  
  train_batch = train_ds.take(1)
  </code></pre>
  <p>Inspecting the <code>train_batch</code> object, as expected, I see it is made up of two objects: images and labels:</p>
  <pre><code>&lt;TakeDataset shapes: ((None, 224, 224, 3), (None,)), types: (tf.float32, tf.int32)&gt;
  </code></pre>
  <p>The tutorial states uses the following code to plot the images in this batch:</p>
  <pre><code>for images, labels in train_batch:
      for i in range(32):
          ax = plt.subplot(4, 8, i + 1)
          plt.imshow(images[i].numpy().astype(&quot;uint8&quot;))
  </code></pre>
  <p>My question is how does <code>for images, labels in train_batch:</code> manage to specify the images and labels separately. Apart from <code>enumerate</code>  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?</p>