albumentations

An efficient library for image augmentation, providing extensive transformations to support machine learning and computer vision tasks.


Keywords
image, augmentation, data, computer, vision, deep, learning, machine, processing, artificial, intelligence, library, transformation, deep-learning, detection, fast-augmentations, image-augmentation, image-classification, image-processing, image-segmentation, machine-learning, object-detection, python, segmentation
License
MIT
Install
pip install albumentations==0.3.2

Documentation

Albumentations

PyPI version CI License: MIT Ruff Pydantic v2

Docs | Discord | Twitter | LinkedIn

Albumentations is a Python library for image augmentation. Image augmentation is used in deep learning and computer vision tasks to increase the quality of trained models. The purpose of image augmentation is to create new training samples from the existing data.

Here is an example of how you can apply some pixel-level augmentations from Albumentations to create new images from the original one: parrot

Why Albumentations

  • Albumentations supports all common computer vision tasks such as classification, semantic segmentation, instance segmentation, object detection, and pose estimation.
  • The library provides a simple unified API to work with all data types: images (RBG-images, grayscale images, multispectral images), segmentation masks, bounding boxes, and keypoints.
  • The library contains more than 70 different augmentations to generate new training samples from the existing data.
  • Albumentations is fast. We benchmark each new release to ensure that augmentations provide maximum speed.
  • It works with popular deep learning frameworks such as PyTorch and TensorFlow. By the way, Albumentations is a part of the PyTorch ecosystem.
  • Written by experts. The authors have experience both working on production computer vision systems and participating in competitive machine learning. Many core team members are Kaggle Masters and Grandmasters.
  • The library is widely used in industry, deep learning research, machine learning competitions, and open source projects.

Sponsors

Table of contents

Authors

Vladimir I. Iglovikov | Kaggle Grandmaster

Mikhail Druzhinin | Kaggle Expert

Alex Parinov | Kaggle Master

Alexander Buslaev β€” Computer Vision Engineer at Mapbox | Kaggle Master

Evegene Khvedchenya β€” Computer Vision Research Engineer at PiΓ±ata Farms | Kaggle Grandmaster

Installation

Albumentations requires Python 3.8 or higher. To install the latest version from PyPI:

pip install -U albumentations

Other installation options are described in the documentation.

Documentation

The full documentation is available at https://albumentations.ai/docs/.

A simple example

import albumentations as A
import cv2

# Declare an augmentation pipeline
transform = A.Compose([
    A.RandomCrop(width=256, height=256),
    A.HorizontalFlip(p=0.5),
    A.RandomBrightnessContrast(p=0.2),
])

# Read an image with OpenCV and convert it to the RGB colorspace
image = cv2.imread("image.jpg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Augment an image
transformed = transform(image=image)
transformed_image = transformed["image"]

Getting started

I am new to image augmentation

Please start with the introduction articles about why image augmentation is important and how it helps to build better models.

I want to use Albumentations for the specific task such as classification or segmentation

If you want to use Albumentations for a specific task such as classification, segmentation, or object detection, refer to the set of articles that has an in-depth description of this task. We also have a list of examples on applying Albumentations for different use cases.

I want to know how to use Albumentations with deep learning frameworks

We have examples of using Albumentations along with PyTorch and TensorFlow.

I want to explore augmentations and see Albumentations in action

Check the online demo of the library. With it, you can apply augmentations to different images and see the result. Also, we have a list of all available augmentations and their targets.

Who is using Albumentations

See also

List of augmentations

Pixel-level transforms

Pixel-level transforms will change just an input image and will leave any additional targets such as masks, bounding boxes, and keypoints unchanged. The list of pixel-level transforms:

Spatial-level transforms

Spatial-level transforms will simultaneously change both an input image as well as additional targets such as masks, bounding boxes, and keypoints. The following table shows which additional targets are supported by each transform.

Transform Image Mask BBoxes Keypoints
Affine βœ“ βœ“ βœ“ βœ“
BBoxSafeRandomCrop βœ“ βœ“ βœ“
CenterCrop βœ“ βœ“ βœ“ βœ“
CoarseDropout βœ“ βœ“ βœ“
Crop βœ“ βœ“ βœ“ βœ“
CropAndPad βœ“ βœ“ βœ“ βœ“
CropNonEmptyMaskIfExists βœ“ βœ“ βœ“ βœ“
D4 βœ“ βœ“ βœ“ βœ“
ElasticTransform βœ“ βœ“ βœ“
Flip βœ“ βœ“ βœ“ βœ“
GridDistortion βœ“ βœ“ βœ“
GridDropout βœ“ βœ“
HorizontalFlip βœ“ βœ“ βœ“ βœ“
Lambda βœ“ βœ“ βœ“ βœ“
LongestMaxSize βœ“ βœ“ βœ“ βœ“
MaskDropout βœ“ βœ“
Morphological βœ“ βœ“
NoOp βœ“ βœ“ βœ“ βœ“
OpticalDistortion βœ“ βœ“ βœ“
PadIfNeeded βœ“ βœ“ βœ“ βœ“
Perspective βœ“ βœ“ βœ“ βœ“
PiecewiseAffine βœ“ βœ“ βœ“ βœ“
PixelDropout βœ“ βœ“
RandomCrop βœ“ βœ“ βœ“ βœ“
RandomCropFromBorders βœ“ βœ“ βœ“ βœ“
RandomGridShuffle βœ“ βœ“ βœ“
RandomResizedCrop βœ“ βœ“ βœ“ βœ“
RandomRotate90 βœ“ βœ“ βœ“ βœ“
RandomScale βœ“ βœ“ βœ“ βœ“
RandomSizedBBoxSafeCrop βœ“ βœ“ βœ“
RandomSizedCrop βœ“ βœ“ βœ“ βœ“
Resize βœ“ βœ“ βœ“ βœ“
Rotate βœ“ βœ“ βœ“ βœ“
SafeRotate βœ“ βœ“ βœ“ βœ“
ShiftScaleRotate βœ“ βœ“ βœ“ βœ“
SmallestMaxSize βœ“ βœ“ βœ“ βœ“
Transpose βœ“ βœ“ βœ“ βœ“
VerticalFlip βœ“ βœ“ βœ“ βœ“
XYMasking βœ“ βœ“ βœ“

Mixing-level transforms

Transforms that mix several images into one

Transform Image Mask BBoxes Keypoints Global Label
MixUp βœ“ βœ“ βœ“

A few more examples of augmentations

Semantic segmentation on the Inria dataset

inria

Medical imaging

medical

Object detection and semantic segmentation on the Mapillary Vistas dataset

vistas

Keypoints augmentation

Benchmarking results

To run the benchmark yourself, follow the instructions in benchmark/README.md

Results for running the benchmark on the first 2000 images from the ImageNet validation set using an AMD Ryzen Threadripper 3970X CPU. The table shows how many images per second can be processed on a single core; higher is better.

Library Version
Python 3.10.13 (main, Sep 11 2023, 13:44:35) [GCC 11.2.0]
albumentations 1.4.1
imgaug 0.4.0
torchvision 0.17.1+rocm5.7
numpy 1.26.4
opencv-python-headless 4.9.0.80
scikit-image 0.22.0
scipy 1.12.0
pillow 10.2.0
kornia 0.7.2
augly 1.0.0
albumentations
1.4.0
torchvision
0.17.1+rocm5.7
kornia
0.7.2
augly
1.0.0
imgaug
0.4.0
HorizontalFlip 9843 Β± 2135 2436 Β± 29 1014 Β± 3 3663 Β± 18 4884 Β± 51
VerticalFlip 9898 Β± 18 2570 Β± 37 1024 Β± 4 5325 Β± 13 8683 Β± 5
Rotate 610 Β± 4 153 Β± 2 204 Β± 1 626 Β± 3 499 Β± 5
Affine 1705 Β± 67 159 Β± 1 200 Β± 1 - 663 Β± 24
Equalize 1061 Β± 14 337 Β± 1 77 Β± 1 - 845 Β± 33
RandomCrop64 203197 Β± 2105 15931 Β± 27 837 Β± 2 21858 Β± 362 5681 Β± 96
RandomResizedCrop 2998 Β± 30 1160 Β± 4 190 Β± 1 - -
ShiftRGB 1400 Β± 3 - 435 Β± 1 - 1528 Β± 6
Resize 2581 Β± 3 1239 Β± 1 197 Β± 1 431 Β± 1 1728 Β± 1
RandomGamma 4556 Β± 3 230 Β± 1 205 Β± 1 - 2282 Β± 110
Grayscale 7234 Β± 4 1539 Β± 7 444 Β± 3 2606 Β± 2 918 Β± 42
ColorJitter 452 Β± 43 51 Β± 1 50 Β± 1 221 Β± 1 -
RandomPerspective 465 Β± 1 121 Β± 1 115 Β± 1 - 433 Β± 16
GaussianBlur 2315 Β± 9 106 Β± 2 72 Β± 1 161 Β± 1 1213 Β± 3
MedianBlur 3711 Β± 2 - 2 Β± 1 - 566 Β± 3
MotionBlur 2763 Β± 25 - 101 Β± 4 - 508 Β± 2
Posterize 4238 Β± 51 2581 Β± 20 284 Β± 4 - 1893 Β± 9
JpegCompression 208 Β± 1 - - 692 Β± 4 435 Β± 1
GaussianNoise 64 Β± 9 - - 67 Β± 1 212 Β± 16
Elastic 129 Β± 1 3 Β± 1 1 Β± 1 - 128 Β± 1

Contributing

To create a pull request to the repository, follow the documentation at CONTRIBUTING.md

https://github.com/albuemntations-team/albumentation/graphs/contributors

Community and Support

Comments

In some systems, in the multiple GPU regime, PyTorch may deadlock the DataLoader if OpenCV was compiled with OpenCL optimizations. Adding the following two lines before the library import may help. For more details pytorch/pytorch#1355

cv2.setNumThreads(0)
cv2.ocl.setUseOpenCL(False)

Citing

If you find this library useful for your research, please consider citing Albumentations: Fast and Flexible Image Augmentations:

@Article{info11020125,
    AUTHOR = {Buslaev, Alexander and Iglovikov, Vladimir I. and Khvedchenya, Eugene and Parinov, Alex and Druzhinin, Mikhail and Kalinin, Alexandr A.},
    TITLE = {Albumentations: Fast and Flexible Image Augmentations},
    JOURNAL = {Information},
    VOLUME = {11},
    YEAR = {2020},
    NUMBER = {2},
    ARTICLE-NUMBER = {125},
    URL = {https://www.mdpi.com/2078-2489/11/2/125},
    ISSN = {2078-2489},
    DOI = {10.3390/info11020125}
}