albumentations

Fast image augmentation library and an easy-to-use wrapper around other libraries. Documentation: https://albumentations.ai/docs/ Paper about the library: https://www.mdpi.com/2078-2489/11/2/125

9872
1270
Python

Albumentations

PyPI version
CI
PyPI Downloads
Conda Downloads
Stack Overflow
License: MIT
Gurubase
PyPI - Types

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

Community-Driven Project, Supported By

Albumentations thrives on developer contributions. We appreciate our sponsors who help sustain the project’s infrastructure.

πŸ† Gold Sponsors
Your company could be here
πŸ₯ˆ Silver Sponsors
Datature
πŸ₯‰ Bronze Sponsors
Roboflow

πŸ’ Become a Sponsor

Your sponsorship is a way to say β€œthank you” to the maintainers and contributors who spend their free time building and maintaining Albumentations. Sponsors are featured on our website and README. View sponsorship tiers on GitHub Sponsors

Table of contents

Authors

Current Maintainer

Vladimir I. Iglovikov | Kaggle Grandmaster

Emeritus Core Team Members

Mikhail Druzhinin | Kaggle Expert

Alex Parinov | Kaggle Master

Alexander Buslaev | Kaggle Master

Eugene Khvedchenya | Kaggle Grandmaster

Installation

Albumentations requires Python 3.9 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. For volumetric data (volumes and 3D masks), these transforms are applied independently to each slice along the Z-axis (depth dimension), maintaining consistency across the volume. 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. For volumetric data (volumes and 3D masks), these transforms are applied independently to each slice along the Z-axis (depth dimension), maintaining consistency across the volume. The following table shows which additional targets are supported by each transform:

  • Volume: 3D array of shape (D, H, W) or (D, H, W, C) where D is depth, H is height, W is width, and C is number of channels (optional)
  • Mask3D: Binary or multi-class 3D mask of shape (D, H, W) where each slice represents segmentation for the corresponding volume slice
Transform Image Mask BBoxes Keypoints Volume Mask3D
Affine βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
AtLeastOneBBoxRandomCrop βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
BBoxSafeRandomCrop βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
CenterCrop βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
CoarseDropout βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
ConstrainedCoarseDropout βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
Crop βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
CropAndPad βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
CropNonEmptyMaskIfExists βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
D4 βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
ElasticTransform βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
Erasing βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
FrequencyMasking βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
GridDistortion βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
GridDropout βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
GridElasticDeform βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
HorizontalFlip βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
Lambda βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
LongestMaxSize βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
MaskDropout βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
Morphological βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
NoOp βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
OpticalDistortion βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
OverlayElements βœ“ βœ“
Pad βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
PadIfNeeded βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
Perspective βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
PiecewiseAffine βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
PixelDropout βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
RandomCrop βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
RandomCropFromBorders βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
RandomCropNearBBox βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
RandomGridShuffle βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
RandomResizedCrop βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
RandomRotate90 βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
RandomScale βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
RandomSizedBBoxSafeCrop βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
RandomSizedCrop βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
Resize βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
Rotate βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
SafeRotate βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
ShiftScaleRotate βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
SmallestMaxSize βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
ThinPlateSpline βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
TimeMasking βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
TimeReverse βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
Transpose βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
VerticalFlip βœ“ βœ“ βœ“ βœ“ βœ“ βœ“
XYMasking βœ“ βœ“ βœ“ βœ“ βœ“ βœ“

3D transforms

3D transforms operate on volumetric data and can modify both the input volume and associated 3D mask.

Where:

  • Volume: 3D array of shape (D, H, W) or (D, H, W, C) where D is depth, H is height, W is width, and C is number of channels (optional)
  • Mask3D: Binary or multi-class 3D mask of shape (D, H, W) where each slice represents segmentation for the corresponding volume slice
Transform Volume Mask3D Keypoints
CenterCrop3D βœ“ βœ“ βœ“
CoarseDropout3D βœ“ βœ“ βœ“
CubicSymmetry βœ“ βœ“ βœ“
Pad3D βœ“ βœ“ βœ“
PadIfNeeded3D βœ“ βœ“ βœ“
RandomCrop3D βœ“ βœ“ βœ“

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

System Information

  • Platform: macOS-15.1-arm64-arm-64bit
  • Processor: arm
  • Python Version: 3.12.8

Benchmark Parameters

  • Number of images: 2000
  • Runs per transform: 5
  • Max warmup iterations: 1000

Library Versions

  • albumentations: 2.0.2
  • augly: 1.0.0
  • imgaug: 0.4.0
  • kornia: 0.8.0
  • torchvision: 0.20.1

Performance Comparison

Number shows how many uint8 images per second can be processed on one CPU thread. Larger is better.

Transform albumentations
2.0.2
augly
1.0.0
imgaug
0.4.0
kornia
0.8.0
torchvision
0.20.1
Resize 3662 Β± 54 1083 Β± 21 2995 Β± 70 645 Β± 13 260 Β± 9
RandomCrop128 116784 Β± 2222 45395 Β± 934 21408 Β± 622 2946 Β± 42 31450 Β± 249
HorizontalFlip 12649 Β± 238 8808 Β± 1012 9599 Β± 495 1297 Β± 13 2486 Β± 107
VerticalFlip 24989 Β± 904 16830 Β± 1653 19935 Β± 1708 2872 Β± 37 4696 Β± 161
Rotate 3066 Β± 83 1739 Β± 105 2574 Β± 10 256 Β± 2 258 Β± 4
Affine 1503 Β± 29 - 1328 Β± 16 248 Β± 6 188 Β± 2
Perspective 1222 Β± 16 - 908 Β± 8 154 Β± 3 147 Β± 5
Elastic 359 Β± 7 - 395 Β± 14 1 Β± 0 3 Β± 0
ChannelShuffle 8162 Β± 180 - 1252 Β± 26 1328 Β± 44 4417 Β± 234
Grayscale 37212 Β± 1856 6088 Β± 107 3100 Β± 24 1201 Β± 52 2600 Β± 23
GaussianBlur 943 Β± 11 387 Β± 4 1460 Β± 23 254 Β± 5 127 Β± 4
GaussianNoise 234 Β± 7 - 263 Β± 9 125 Β± 1 -
Invert 35494 Β± 17186 - 3682 Β± 79 2881 Β± 43 4244 Β± 30
Posterize 14146 Β± 1381 - 3111 Β± 95 836 Β± 30 4247 Β± 26
Solarize 12920 Β± 1097 - 3843 Β± 80 263 Β± 6 1032 Β± 14
Sharpen 2375 Β± 38 - 1101 Β± 30 201 Β± 2 220 Β± 3
Equalize 1303 Β± 64 - 814 Β± 11 306 Β± 1 795 Β± 3
JpegCompression 1354 Β± 23 1202 Β± 19 687 Β± 26 120 Β± 1 889 Β± 7
RandomGamma 12631 Β± 1159 - 3504 Β± 72 230 Β± 3 -
MedianBlur 1259 Β± 8 - 1152 Β± 14 6 Β± 0 -
MotionBlur 3608 Β± 18 - 928 Β± 37 159 Β± 1 -
CLAHE 649 Β± 13 - 555 Β± 14 165 Β± 3 -
Brightness 11254 Β± 418 2108 Β± 32 1076 Β± 32 1127 Β± 27 854 Β± 13
Contrast 11255 Β± 242 1379 Β± 25 717 Β± 5 1109 Β± 41 602 Β± 13
CoarseDropout 15760 Β± 594 - 1190 Β± 22 - -
Blur 7403 Β± 114 386 Β± 4 5381 Β± 125 265 Β± 11 -
Saturation 1581 Β± 127 - 495 Β± 3 155 Β± 2 -
Shear 1336 Β± 18 - 1244 Β± 14 261 Β± 1 -
ColorJitter 968 Β± 52 418 Β± 5 - 104 Β± 4 87 Β± 1
RandomResizedCrop 4521 Β± 17 - - 661 Β± 16 837 Β± 37
Pad 31866 Β± 530 - - - 4889 Β± 183
AutoContrast 1534 Β± 115 - - 541 Β± 8 344 Β± 1
Normalize 1797 Β± 190 - - 1251 Β± 14 1018 Β± 7
Erasing 25411 Β± 5727 - - 1210 Β± 27 3577 Β± 49
CenterCrop128 119630 Β± 3484 - - - -
RGBShift 3526 Β± 128 - - 896 Β± 9 -
PlankianJitter 3351 Β± 42 - - 2150 Β± 52 -
HSV 1277 Β± 91 - - - -
ChannelDropout 10988 Β± 243 - - 2283 Β± 24 -
LinearIllumination 462 Β± 52 - - 708 Β± 6 -
CornerIllumination 464 Β± 45 - - 452 Β± 3 -
GaussianIllumination 670 Β± 91 - - 436 Β± 13 -
Hue 1846 Β± 193 - - 150 Β± 1 -
PlasmaBrightness 163 Β± 1 - - 85 Β± 1 -
PlasmaContrast 138 Β± 4 - - 84 Β± 0 -
PlasmaShadow 190 Β± 3 - - 216 Β± 5 -
Rain 2121 Β± 64 - - 1493 Β± 9 -
SaltAndPepper 2233 Β± 35 - - 480 Β± 12 -
Snow 588 Β± 32 - - 143 Β± 1 -
OpticalDistortion 687 Β± 38 - - 174 Β± 0 -
ThinPlateSpline 75 Β± 5 - - 58 Β± 0 -

Contributing

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

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

Community

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}
}