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

Support for imgaug #1954

Closed
5starkarma opened this issue Jan 16, 2021 · 6 comments · Fixed by #3882
Closed

Support for imgaug #1954

5starkarma opened this issue Jan 16, 2021 · 6 comments · Fixed by #3882
Labels
enhancement New feature or request Stale Stale and schedule for closing soon

Comments

@5starkarma
Copy link

5starkarma commented Jan 16, 2021

🚀 Feature

imgaug is very popular and is easy to work with. I am wondering if I put in PR's which allowed use of imgaug, such as BoundingBox instances, to be used in parts of the program if it would be approved.

e.g. The plot_one_box function could accept then convert BoundingBox instances to the proper format (tensor) for easy plotting of bboxes.

Example:

def plot_one_box(x, img, color=None, label=None, line_thickness=None):
    # If bbox is instance of BoundingBox
    if isinstance(x, BoundingBox):
        # Convert to tensor
        x = torch.tensor([x.x1, x.y1, x.x2, x.y2])

Motivation

I use imgaug, albumentations uses imgaug. It is very easy to use.

Pitch

Add functionality which allows use of imgaug.

@5starkarma 5starkarma added the enhancement New feature or request label Jan 16, 2021
@glenn-jocher
Copy link
Member

@5starkarma yes we welcome PRs! I'm not familiar with imgaug, though we have had requests for Albumentations ops, which might go in datasets.py.

Note that you should profile any modifications to verify that performance speed is unaffected by the proposed changes as part of the PR as well.

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale Stale and schedule for closing soon label Feb 17, 2021
@lleye
Copy link

lleye commented Jun 5, 2021

@5starkarma can you give an example of how you integrate imgaug in yolov5, trying to augment as well

@glenn-jocher
Copy link
Member

the best place to insert Albumentation augmentations into the YOLOv5 dataloader is here:

yolov5/utils/datasets.py

Lines 536 to 552 in 6306091

if self.augment:
# Augment imagespace
if not mosaic:
img, labels = random_perspective(img, labels,
degrees=hyp['degrees'],
translate=hyp['translate'],
scale=hyp['scale'],
shear=hyp['shear'],
perspective=hyp['perspective'])
# Augment colorspace
augment_hsv(img, hgain=hyp['hsv_h'], sgain=hyp['hsv_s'], vgain=hyp['hsv_v'])
# Apply cutouts
# if random.random() < 0.9:
# labels = cutout(img, labels)

where img is the image and labels are the bounding box labels. Note that any Albumentation augmentations you add will be in addition to the existing automatic YOLOv5 augmentations defined in your hyperparameter file:

fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5)
hsv_h: 0.015 # image HSV-Hue augmentation (fraction)
hsv_s: 0.7 # image HSV-Saturation augmentation (fraction)
hsv_v: 0.4 # image HSV-Value augmentation (fraction)
degrees: 0.0 # image rotation (+/- deg)
translate: 0.1 # image translation (+/- fraction)
scale: 0.5 # image scale (+/- gain)
shear: 0.0 # image shear (+/- deg)
perspective: 0.0 # image perspective (+/- fraction), range 0-0.001
flipud: 0.0 # image flip up-down (probability)
fliplr: 0.5 # image flip left-right (probability)
mosaic: 1.0 # image mosaic (probability)
mixup: 0.0 # image mixup (probability)

@lleye
Copy link

lleye commented Jul 2, 2021

@glenn-jocher quick question on your comment here "Note that any Albumentation augmentations you add will be in addition to the existing automatic YOLOv5 augmentations defined in your hyperparameter file"

Do you mean if i set mixup to 0.1, it will augment the data with an additional 10% of mixed up images making it 110%? Or is it going to be 90% normal and 10% mixed augmented?

Also i cant seem to integrate imgaug, any pointers in case you saw someone integrate it before? Thanks

@glenn-jocher
Copy link
Member

@lleye 0.10 mixup means 10% of your images will use mixup.

@glenn-jocher glenn-jocher linked a pull request Jul 4, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Stale Stale and schedule for closing soon
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants