Use epoch value during data augmentation

Hi everybody,

I’m using fastai version 40 on image classification.
I’ve a specific dataset on which data augmentation use only 8 possibilities: 4 x rot90 (0°, 90°, 180° and 270°) and random flip (x2). No other augmentation (zoom, wrap etc…)
Even with 12 epoch and random choice of these 8 possibilties, statistically I will have an average use of only 6 of them. So, more or less, each image will be seen exactly the same way 2 times…
To improve the accuracy and the training time, I would like to train the CNN with only 8 epoch and use the value of the epoch (as a variable ?) to force the image to change during data augmentation in a controlled way:
epoch will be in a the range [0,7]
epoch 0 --> image (no change)
epoch 1 --> image ROT 90°
epoch 2 --> image ROT 180°

epoch 7 --> image (flip + ROT 270°)

I hope my explanations are clear enough :grinning:

Can someone help me to find a solution for this ?

Best regards,


I don’t think there is a direct way to do that, but you should be to create a callback which accomplishes the same thing.

Try removing the current transformation and add the next one using remove_tfm and add_tfm in the on_epoch_end method of your callback. Or if that doesn’t work, recreate the databunch with the next transformation and assign it to the learner during on_epoch_end.

Hi, thanks for the answer. I’ll try to do it.
Best regards,