Using data augmentation in a callback

Hello everyone,

I’m trying to implement the Mixmatch algorithm (https://arxiv.org/abs/1905.02249) as a way to familiarize myself with the inner workings of fast.ai. I stumbled upon several questions, the most critical of which is how to call data augmentation methods within a callback.

More specifically, when subclassing the on_batch_begin() method, I use the last_input object, but I am not sure if at this point the data is already augmented.

If I try to dig a bit deeper again, I find it hard to access the tensors that represent the images within the Databunch object.

If anyone has an idea, feel free to share!

Thanks,
Pierre-Antoine

Hello,

I actually just published a blog post on implementing MixMatch in fastai – you can find it here: https://medium.com/@noachr/a-fastai-pytorch-implementation-of-mixmatch-314bb30d0f99.

As to your specific question, the data is indeed already augmented in the last_input object. I avoid applying augmentation in the callback altogether and instead modify LabelList to augment each image multiple times.

2 Likes