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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CutMix and Mosaic Augmentation #677

Open
awsaf49 opened this issue Aug 10, 2020 · 17 comments
Open

CutMix and Mosaic Augmentation #677

awsaf49 opened this issue Aug 10, 2020 · 17 comments

Comments

@awsaf49
Copy link

awsaf49 commented Aug 10, 2020

📚 Documentation

CutMix and Mosaic Augmentations are pretty good augmentation when it comes to achieve better score. It would be great if these two are included in albumentations.

@ternaus
Copy link
Collaborator

ternaus commented Aug 10, 2020

Could you please provide links to the description of Mosaic Augmentation?

@awsaf49
Copy link
Author

awsaf49 commented Aug 11, 2020

Could you please provide links to the description of Mosaic Augmentation?

I think it was even mentioned in YOLOv4 paper. Here are some references:
https://www.kaggle.com/nvnnghia/awesome-augmentation
https://github.com/klauspa/Yolov4-tensorflow

@chamorajg
Copy link

Is someone working on this issue ? Can I pick this up and create a PR for this request ?

@Dipet
Copy link
Collaborator

Dipet commented Jul 29, 2021

Yes, you can try to implement this.

@senarvi
Copy link

senarvi commented Aug 26, 2021

I guess what makes it difficult is that you would need to implement an augmentation that takes multiple images as input. Is that even possible in Albumentations?

@mulcyber
Copy link

The BasicTransform (and all other transforms) take only 1 image a input and don't manage iterables themselves.
So I don't think it's possible without changing how albumentations or putting them as a different kind of object.

We would need to create an "BasicIterableTransform" than takes an iterable as input. But it wouldn't work with tools like torch.utils.data.Dataset without modification, need a new compose class, etc.

I agree it's a shame they're not included. It's super useful in detection problems, even though it requires quite a few modifications in albumentations and changes how the transforms would be used.

Any maintainer can tell us if it's the kind of features (namely Transforms taking iterables) that would be accepted/merged or it's just too different to how the library works now?

@dav-ell
Copy link

dav-ell commented Mar 14, 2022

I've been working on a custom augment that performs mosaic by loading in 3 new images with whatever image is currently in the pipeline, but I got stuck at trying to return the new set of bounding boxes in the final moasic-ed image. Has anyone made progress on this?

@dav-ell
Copy link

dav-ell commented Mar 15, 2022

I was able to create a custom version that fit my needs, but I couldn't get it to work with the albumentations pipeline. I ended up doing this (where self.mosaic :

# in my datamodule

self.mosaic = Mosaic(img_files, bbox_files, p=0.9) # requires all image and label files to create random mosaics

def transform(image, bboxes, class_labels, **params):
    """A wrapper for the albumentations pipeline"""
    image, bboxes, class_labels = self.mosaic(image, bboxes, class_labels)
    return self.transform(image=image, bboxes=bboxes, class_labels=class_labels, **params)

# create dataset, pass transform

That way my dataset could still call transform() with the usual albumentations API. However, it'd be nice to not have to use workarounds like this.

@i-aki-y
Copy link
Contributor

i-aki-y commented Mar 18, 2022

I made a PR to add Mosaic augmentation with as few changes to the existing implementation as possible #1147.
Although some remaining works are to be done, please check it out if you are interested in this feature.
I welcome any comments and feedback.

@innat
Copy link

innat commented Apr 16, 2022

cc. @awsaf49
Cutmix is available officially in keras, HERE. The Mosaic one will be soon.

@awsaf49
Copy link
Author

awsaf49 commented Apr 16, 2022

cc. @awsaf49
Cutmix is available officially in keras, HERE. The Mosaic one will be soon.

Thank you 😀

@ccl-private
Copy link

ccl-private commented Aug 16, 2022

Hi @dav-ell
How to write albumentations pipeline wrapper? Can you provide your whole code?

@mikel-brostrom
Copy link

Any updates on Mosaic for Albumentations?

@ternaus
Copy link
Collaborator

ternaus commented Mar 29, 2024

Working on it.

@ankandrew
Copy link

Having Mosaic augmentation available in Albumentations would be great 🙏

@Buckler89
Copy link

@ternaus Any update?

@ternaus
Copy link
Collaborator

ternaus commented Jan 22, 2025

Postponed it till I start training object detection model myself. There are different ways to implement the transform, not sure which will be the most convenient.

But if someone want to write an implementation and create a pull request - would be happy to review and discuss.

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