New YOLOv5 ๐ + Albumentations Official Integration!!
See original GitHub issueIโ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:
Update
To receive this YOLOv5 update:
- Git โ
git pull
from within youryolov5/
directory orgit 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
- Docker โ
sudo docker pull ultralytics/yolov5:latest
to update your image
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:
- Created 2 years ago
- Reactions:53
- Comments:12 (2 by maintainers)
I checked what happened.
Default colab has:
The albumentation requirements are given from the result of
pkginfo -f requires_dist albumentations-1.1.0-py3-none-any.whl
:After the pip -u albumentations
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.
Great work @glenn-jocher !