Only you know how it works, since it is what you wrote. 
But this is a good question, since behavior of augmentater() is different by the mode, i.,e, training=True or False.
model2 is created like this.
model2 = alpaca_model(IMG_SIZE, data_augmentation)
Let’s go back a few cells above.
data_augmentation = data_augmenter()
data_augmentation is an instantiation of data_augmenter() that you wrote in the first exercise.
Assuming that you passed the local testing, data_augmenter is a Sequential model which consists of two layers, RandomFlip and RandomRotation. (I put links for those. Please refer that.)
It is quite simple function to “flip” and “rotate” an original image. So, the number of samples is unchanged. Both RandomFlip and RandomRotation take a parameter of “training=True” or “training=False”. If “True”, both RandomFlip and RandomRotation work on image transformation. So, this is very useful for training, at each epoch, you can expect that slightly different images are fed into a neural network even though you prepared one image. But, a prediction (inference) time, we do not want the augmenter to change any. So, we usually set “training=False” to disable augmentation.
If you look at model2.summary(), you can find the augmenter.
In the second layer, you see “sequential_1 (Sequential)”. That is the one. Since nested function can not be expanded in old Keras, we can not see its contents. But, if we use newer version of Keras, it can be seen like this. You see both “random_flip” and “random_rotation” are in the neural network.
To summarize the above, “data_augmentation” does not change the number of samples, but transforms data if “Training=True”. In each epoch, we can expect an image is transformed with flip and rotation. This can be seen that different samples are fed into the system, which is beneficial if the number of samples is small. At the prediction time, we usually set “training=False” not to add any transformation to the sample.
If you have time, you can revisit a cell to see 9 variations of an image with adding “training=False”, and see what will happen.
data_augmentation = data_augmenter()
for image, _ in train_dataset.take(1):
plt.figure(figsize=(10, 10))
first_image = image[0]
for i in range(9):
ax = plt.subplot(3, 3, i + 1)
augmented_image = data_augmentation(tf.expand_dims(first_image, 0), training=False)
plt.imshow(augmented_image[0] / 255)
plt.axis(‘off’)
Hope this clarifies.