Doesn't Data Augmentation via Keras Preprocessing layers also augment the validation set?

As I understand it, data augmentation should only be used for the train set.

However, as I understand the code in c4 week 2, “Transfer learning with MobilenetV2 exercise” it implements data augmentation on both the train and validation set.

The data_augmenter() sequential model includes layers of RandomFlip and RandomRotation.

This data_augmenter model then becomes preprocessing layers prior to the frozen mobilenet model used for transfer learning. (see model summary picture)

When is called, aren’t both train_data and validation data are passed to it?

Doesn’t this mean that both train_data and validation_data are augmented?

Also, In the general case, now that Keras recommends using preprocessing layers instead of ImageDataGenerator(which can run independently on train and test data), doesn’t this mean that train and validation_data are always both augmented if you use the preprocessing layer design paradigm?

In the Tensorflow Developer courses, you see the expected design pattern. You use ImageDataGenerator to preprocess the train data with augmentation(rotation, flip etc) and validation differently with rescale only.

Am I missing something? do keras preprocessing layers somehow not function on the validation dataset?

1 Like

Ah. I figured it out.

It’s PEBCAK because I didnt RTFM.

The documentation states that those specific layers are only active during training, not at inference time (when the validation dataset is being run).

1 Like

When is called, aren’t both train_data and validation data are passed to it?

The use of the validation_data argument is given here (from the Keras Model documentation):

I don’t see anywhere in the notebook that the validation set is augmented. Please post a screen capture image If you know of one.

1 Like

I wasn’t saying that the validation data would be used for training, I was saying that it was being run through preprocessing layers like the training data was at inference time. I didn’t see a way around that, since the preprocessing was baked into the model pipeline instead of being separate from the model.

However, the documentation states that those specific image data augmentation preprocessing layers do not run at inference time. (see my comment above). I find that behavior to be confusing and unintuitive, but that’s what it does I guess.

1 Like