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.

New YOLOv5 ๐Ÿš€ + Albumentations Official Integration!!

See original GitHub issue

Iโ€™m super excited to announce our new YOLOv5 ๐Ÿš€ + Albumentations integration!! Now you can train the worldโ€™s best Vision AI models even better with custom Albumentations automatically applied ๐Ÿ˜ƒ!

PR https://github.com/ultralytics/yolov5/pull/3882 implements this integration, which will automatically apply Albumentations transforms during YOLOv5 training if albumentations>=1.0.3 is installed in your environment.

Get Started

To use albumentations simply pip install -U albumentations and then update the augmentation pipeline as you see fit in the new Albumentations class in yolov5/utils/augmentations.py. Note these Albumentations operations run in addition to the YOLOv5 hyperparameter augmentations, i.e. defined in hyp.scratch.yaml.

Hereโ€™s an example that applies Blur, MedianBlur and ToGray albumentations in addition to the YOLOv5 hyperparameter augmentations normally applied to your training mosaics ๐Ÿ˜ƒ

class Albumentations:
    # YOLOv5 Albumentations class (optional, used if package is installed)
    def __init__(self):
        self.transform = None
        try:
            import albumentations as A
            check_version(A.__version__, '1.0.3')  # version requirement

            self.transform = A.Compose([
                A.Blur(blur_limit=50, p=0.1),
                A.MedianBlur(blur_limit=51, p=0.1),
                A.ToGray(p=0.3)],
                bbox_params=A.BboxParams(format='yolo', label_fields=['class_labels']))

            logging.info(colorstr('albumentations: ') + ', '.join(f'{x}' for x in self.transform.transforms))
        except ImportError:  # package not installed, skip
            pass
        except Exception as e:
            logging.info(colorstr('albumentations: ') + f'{e}')

    def __call__(self, im, labels, p=1.0):
        if self.transform and random.random() < p:
            new = self.transform(image=im, bboxes=labels[:, 1:], class_labels=labels[:, 0])  # transformed
            im, labels = new['image'], np.array([[c, *b] for c, b in zip(new['class_labels'], new['bboxes'])])
        return im, labels

Example Result

Example train_batch0.jpg on COCO128 dataset with Blur, MedianBlur and ToGray. See the YOLOv5 Notebooks to reproduce: Open In Colab Open In Kaggle

train_batch0

Update

To receive this YOLOv5 update:

  • Git โ€“ git pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
  • PyTorch Hub โ€“ Force-reload with model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
  • Notebooks โ€“ View updated notebooks Open In Colab Open In Kaggle
  • Docker โ€“ sudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

Thank you for your feedback and let us know if this update works for you, and of course feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 ๐Ÿš€ + Albumentations!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:53
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
i-aki-ycommented, Mar 18, 2022

I checked what happened.

Default colab has:

opencv-contrib-python         4.1.2.30
opencv-python                 4.1.2.30

The albumentation requirements are given from the result of pkginfo -f requires_dist albumentations-1.1.0-py3-none-any.whl:

opencv-python-headless>=4.1.1

After the pip -u albumentations

opencv-contrib-python         4.1.2.30
opencv-python                 4.1.2.30
opencv-python-headless        4.5.5.64

So, multiple versions may cause conflicts.

I think there is no simple solution to this problem. The opencv team provides multiple package options and says, โ€œSELECT ONLY ONE OF THEM.โ€

The package owner can not know which opencv package the userโ€™s environment has installed or none of them. Unfortunately, the situation would be worse because there are environments where multiple openvcv packages have been installed, like Colab.

Installing all of them with the same version seems to work, but it introduces unnecessary and redundant dependencies. I think such behavior would not be wanted for users who use packages in production.

1reaction
BloodAxecommented, Jul 5, 2021

Great work @glenn-jocher !

Read more comments on GitHub >

github_iconTop Results From Across the Web

yolov5 training with Albumentations - Kaggle
This notebook shows you how to apply augmentations from the Albumentations package on the fly using yolov5's Albumentations integration.
Read more >
Augmentation - YOLOv5 Documentation - Ultralytics
YOLOv5 ๐Ÿš€ is now fully integrated with Albumentations, a popular open-source image augmentation package. Now you can train the world's best Vision AI...
Read more >
Frameworks and libraries that use Albumentations
YOLOv5 ๐Ÿš€ is a family of object detection architectures and models pretrained on the COCO dataset, and represents Ultralytics open-source research intoย ...
Read more >
tutorial.ipynb - gagan3012/yolov5 - DagsHub
This is the official YOLOv5 ๐Ÿš€ notebook by Ultralytics, and is freely available for ... downloading models automatically from the latest YOLOv5 release,ย ......
Read more >
YOLOv5 Tutorial - Colaboratory - Google Colab
This YOLOv5 ๐Ÿš€ notebook by Ultralytics presents simple train, validate and predict ... from the latest YOLOv5 release, and saving results to runs/detect...
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