question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mosaic Augmentation for Object Detection

See original GitHub issue

Mosaic augmentation for object detection is used in Yolo-V4 literature, FR. I’m not sure if it’s used for classification tasks there. I was wondering if it’s possible to do so for the image classification task. Here are two issues:

  • References. Not sure if it’s ever used for classification only in any literature.
  • Creation of class labels.

For creating class labels, here is one possible solution, described HERE; using Dirichlet distribution.

# for 2 images. Equivalent to λ and (1-λ)
>>> np.random.dirichlet((1, 1), 1)  
array([[0.92870347, 0.07129653]])  

>>> np.random.dirichlet((1, 1, 1), 1)  # for 3 images.
array([[0.38712673, 0.46132787, 0.1515454 ]])

>>> np.random.dirichlet((1, 1, 1, 1), 1)  # for 4 images.
array([[0.59482542, 0.0185333 , 0.33322484, 0.05341645]])

As mosaic takes 4 images. inbox_1984321_b0530886377eb3d7f0c29401ba069ffa_download (1)


update:

Mosaic augmentation for classification did use in literature. Please check: https://github.com/keras-team/keras-cv/issues/250#issuecomment-1130256698

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
AlexeyABcommented, May 18, 2022

We set the ground truth probability in proportion to the area occupied by each sample: https://github.com/AlexeyAB/darknet/blob/4ee3be7e68fb9c7eda5cc390e47e59f01e40dded/src/data.c#L1913-L1942 So if areas for: Car=10%, Table=20%, Cat=30%, Dog = 40%, then we set labels: Car=0.1, Table=0.2, Cat=0.3, Dog=0.4.

We have not tried using it in any other way.

Mosaic for Classifier reduces Top5-error from 6.0% to 5.5% (-10 relative %) on Imagenet-1k, and it works better than CutMix/MixUp, Tables 2 and 3: https://arxiv.org/abs/2004.10934


We used Mosaic data augmentation:

We didn’t use Mosaic for Classifier in (Scaled-YOLOv4, YOLOv5, YOLOR), just because they don’t need Classification or any pre-trained weights. We train these Detector from scratch to achieve the best accuracy/speed ratio.

It was originally introduced in the YOLOv4 paper: https://arxiv.org/abs/2004.10934

Some later work has used Mosaic:

1reaction
innatcommented, May 23, 2022

Not sure but some suspicious feelings about the creation of mosaic_x/y, s1-s4, center_x, center_y. Can you check this and this implementation, it might give you some pointers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data Augmentation in YOLOv4 - Roboflow Blog
Mosaic [video] is the first new data augmentation technique introduced in YOLOv4. This allows for the model to learn how to identify objects...
Read more >
YOLOX Explanation — Mosaic and Mixup For Data ... - Medium
Data augmentation is a way to help a model generalize. When augmenting data, the model must find new features in the data to...
Read more >
Improved Mosaic: Algorithms for more Complex Images
The object detection model can identify the location and type of object by part of the object contour. 2.3. Improved Mosaic data augmentation...
Read more >
Mosaic Data Augmentation - Deep Dive - YouTube
How to Use Amazon Rekognition Custom Labels and Roboflow to Build an Object Detection Model · Mix - Roboflow · How to Train...
Read more >
Data Augmentation for Object Detection - Kaggle
Mosaic Augmentation ¶. In mosaic, instead of using 2 images we use 4 images. We stitch them together to make one big image...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found