albumentations icon indicating copy to clipboard operation
albumentations copied to clipboard

Mixup or CutMix augmentations

Open ogencoglu opened this issue 5 years ago • 12 comments

Any plan on adding Mixup or CutMix augmentations?

  • https://github.com/clovaai/CutMix-PyTorch - https://arxiv.org/abs/1905.04899
  • https://github.com/facebookresearch/mixup-cifar10 - https://arxiv.org/abs/1710.09412

ogencoglu avatar Sep 05 '19 16:09 ogencoglu

I am looking into contributing both Mixup and CutMix augmentations. Both of these augmentations take multiple images in order to do the augmentation. As far as I can tell all of the existing augmentations in the library only operates on a single image and the entire API is build around a single image being fetched in the datalaoder. Is that correct? To implement these new augmentations we would be operating on the batch level. Do you have any thoughts on how this should be implemented API wise within the library?

bmabey avatar Nov 12 '19 17:11 bmabey

Now when I checked the API, you are right. For CutMix, if the mixed image is fixed it can be treated as an input variable (numpy array etc.) but Mixup is more tricky obviously.

ogencoglu avatar Nov 12 '19 17:11 ogencoglu

@bmabey Randomly sampling within the dataloader for multiple images. Would be nice to augment labels as well. These can then be fed in with

AUGMENTATION = MIXUP(p=0.6)  # Second image is 1-p, although ideally this scales for n mixups
aug = albumentations.AUGMENTATION(images=[image1, image2, ...], labels=[[0, 0, 1], [0, 1, 0]]) 
print(aug['labels'])
-->
[0, 0.4, 0.6]

JeffreyWardman avatar Dec 28 '20 00:12 JeffreyWardman

Please see the repository https://github.com/naver-ai/relabel_imagenet It shows impressive accuracy improvements with CutMix

CutMix implementation: https://github.com/naver-ai/relabel_imagenet/blob/main/utils/data_augment.py#L54 It does mixing within the batch.

This may be a simpler alternative to using multiple images. Looking forward to see this in albumentations

mathmanu avatar May 10 '21 09:05 mathmanu

Is anyone working on this? I would be happy to take it and do a PR

dimimal avatar Mar 01 '22 10:03 dimimal

The following paper also shows good improvements with MixUp/CutMix https://arxiv.org/abs/2111.05328

vedal avatar Mar 04 '22 13:03 vedal

Ref PR #1147

chAwater avatar Jul 20 '22 01:07 chAwater

MixUp PR here: https://github.com/albumentations-team/albumentations/pull/1409

mikel-brostrom avatar Feb 23 '23 08:02 mikel-brostrom

Any follow up on this?

nopps07 avatar Apr 25 '23 17:04 nopps07

Any updates on this? This issue is almost 3 years old

rusmux avatar Aug 16 '23 13:08 rusmux

Yeah, better to use keras-cv at this point instead of albumentations (for these augmentations)

Aryan-Garg avatar Aug 21 '23 03:08 Aryan-Garg

MixUp added in https://github.com/albumentations-team/albumentations/pull/1549

ternaus avatar Mar 05 '24 01:03 ternaus