Week 2: 2nd Assignment - Exercise 2 - data_augmentation

In the alpaca_model function,
We create an input layer: inputs = tf.keras.Input(shape=input_shape)
then we apply
x = data_augmentation(inputs)
and use this x further.

We want to augment the actual image and not the instantiation of an Input layer done here by the tf.keras.Input() function. Can someone explain how this works then?

Have you seen this link?

Yes. I had.
But I still was unclear.

In the code you show data_augmentation is just a function which takes an input tensor containing an image and outputs an “augmented” version of that image. The Input layer there is just the Keras way to specify what the tensor is going to look like that will be the input to the data augmentation step.

Note that they give an example earlier in the notebook of how to use the data augmentation logic and see the results it produces.

One other thing to observe about how they use data augmentation here is that additional augmented images are not “saved” and incorporated into the underlying dataset: they are generated dynamically “on the fly” every time you run the training. Of course that means that you may not get the exact same augmentations each time, depending on how you manage the random seeds. That is probably A Good Thing ™, since it will make the model more flexible and less likely to overfit.

If the above doesn’t help, then please explain in more detail what you are asking.