title: Augmentation of a tf.data.Dataset
body: <p>Following <a href="https://colab.research.google.com/github/tensorflow/docs/blob/master/site/en/tutorials/images/data_augmentation.ipynb#scrollTo=zkLkgEudzKfc" rel="nofollow noreferrer">this</a> guide here i stumbled across this:In order to augment a tf.data Dataset we manualy use the map function to map image transformations in each image of our original dataset:</p>
  <pre><code>def convert(image, label):
    image = tf.image.convert_image_dtype(image, tf.float32) # Cast and normalize the image to [0,1]
    return image, label
  
  def augment(image,label):
    image,label = convert(image, label)
    image = tf.image.convert_image_dtype(image, tf.float32) # Cast and normalize the image to [0,1]
    image = tf.image.resize_with_crop_or_pad(image, 34, 34) # Add 6 pixels of padding
    image = tf.image.random_crop(image, size=[28, 28, 1]) # Random crop back to 28x28
    image = tf.image.random_brightness(image, max_delta=0.5) # Random brightness
  
    return image,label
  
  BATCH_SIZE = 64
  # Only use a subset of the data so it's easier to overfit, for this tutorial
  NUM_EXAMPLES = 2048
  
  augmented_train_batches = (
      train_dataset
      # Only train on a subset, so you can quickly see the effect.
      .take(NUM_EXAMPLES)
      .cache()
      .shuffle(num_train_examples//4)
      # The augmentation is added here.
      .map(augment, num_parallel_calls=AUTOTUNE)
      .batch(BATCH_SIZE)
      .prefetch(AUTOTUNE)
  ) 
  </code></pre>
  <p>From what i can understand what this does is this:It takes the original <code>train_dataset</code> and creates a new <code>augmented_train_batches</code> dataset which has the same number of images  altered by maps transformations.After that what this does is feeding this dataset into <code>.fit</code> like this:</p>
  <pre><code>model_with_aug.fit(augmented_train_batches, epochs=50, validation_data=validation_batches)
  </code></pre>
  <p>So what i can't seem to grasp is this:Aren't the data supposed to be altered after every epoch so that(according to documentation)our model won't see the same image more than once and moreover make our overfitting chances lower?</p>
  <p>In this tutorial isn't <code>augmented_train_batches</code> just a slightly altered dataset which is fed over and over to our model?</p>
  <p>Or is the augmentaion somehow being applied after each epoch in a way i can't understand?</p>
  <p>P.S.I suppose augmentation(if done correctly) must alter the pre-transformed data in a same manner after every epoch and not keep applying transformations to the same altered dataset.</p>