Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batched (random) augmentations #8484

Open
Guitaricet opened this issue Jun 7, 2024 · 3 comments
Open

Batched (random) augmentations #8484

Guitaricet opened this issue Jun 7, 2024 · 3 comments

Comments

@Guitaricet
Copy link

馃殌 The feature

Randomly sample augmentation parameters for each image in the batch

Motivation, pitch

Torch augmentations have two big advantages over alternatives like Albumentations: ability to apply them to a batch of images and ability to run them on GPU. This can make a big difference when batch size is very large (e.g., 1000). However, right now augmentation pipeline would apply exactly the same transformation to every image in the batch, which makes augmentations less valuable and can destabilize the training because of significantly chaged batch statistics.

Alternatives

Any recommendations to existing libraries that allow batched + GPU augmentations?

Additional context

In some of my training pipelines I observed that Albumentations are not fast enough and that we can benefit from going back to torchvision, but then I noticed that all images are augmented in the same way.

@NicolasHug
Copy link
Member

Thanks for the feature request @Guitaricet . This has been a reccurent feature request for a while, but there is no current obvious path to support that just yet, as most kernel implementations are just not easily parallelizable over RNG. vmap is a potential avenue, but last time I tried I ended up quickly blocked.

You'll see torchaug mentioned in #2929 (comment) which supports what you need. Some kernels are natively implemented with support for per-sample RNG, but for most transforms the batches are instead split into sub-batches, transformed and then re-concatenated, so it's more of a per-subbatch-RNG AFAIU. If you try it and it works for your use-case I'd love to hear it, and perhaps consider something simliar in torchvision (CC @juliendenize who's the author of torchaug).

@Guitaricet
Copy link
Author

Thank you, I will take a look!

@juliendenize
Copy link

Hi thanks for the ping @NicolasHug , you're right about how Torchaug works it offers the flexibility to do per-subbatch-RNG when a per-sample RNG is not possible in Torch.

I'd like to also hearing from you @Guitaricet if you try it and if it works, I try to maintain it as much as I can and follow Torchvision advances but I'd need more feedback from users to make it better. I'd love it if eventually Torchvision could natively support such features 馃槃.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants