Fast image augmentation · images / masks / bboxes / keypoints · verified against Albumentations 2.x (2026)

albumentations cheat sheet

Albumentations is the standard fast image-augmentation library (the practical replacement for imgaug). One A.Compose pipeline augments an image and its labels together — segmentation masks, bounding boxes and keypoints all transform consistently — over 100 optimized transforms. This sheet targets Albumentations 2.x. Note the successor project AlbumentationsX (dual-licensed) now carries active development; the import name and API below are shared.

pipeline (Compose) transforms composition masks / bboxes / keypoints framework integration gotcha most common

Verified 2026-08-24 against the official docs at albumentations.ai/docs and the albumentations-team repos (Albumentations 2.x / AlbumentationsX). Works on NumPy HWC arrays; integrates with PyTorch via ToTensorV2.

Outline

Build a Compose once, then call it with keyword targets (image=, mask=, bboxes=). The two things that trip everyone up: inputs are NumPy, not PIL, and ToTensorV2 goes last.

Pipeline

  1. 1 · Install & Compose
  2. 2 · Apply & read output

Transforms

  1. 3 · Spatial & crops
  2. 4 · Pixel-level

Control

  1. 5 · Probabilities & OneOf

Labels

  1. 6 · Masks (segmentation)
  2. 7 · Bounding boxes
  3. 8 · Keypoints

Integrate

  1. 9 · PyTorch & serialization
  2. 10 · Gotchas
  3. Worth memorizing

The Pipeline

Compose a list of transforms; call it with named targets.

1Install & Compose2.x
2Apply & read outputkeyword targets

Transforms

Two families: spatial (change geometry — also move masks/boxes) and pixel-level (change appearance only).

3Spatial & cropsmove geometry
4Pixel-levelappearance only

Composition & Probability

Control which transforms fire and how often.

5Probabilities & OneOfstructure the pipeline

Masks, Boxes & Keypoints

The reason to use Albumentations: labels transform with the image.

6Masks (segmentation)easiest target
7Bounding boxesdetection
8Keypointspose / landmarks

Integrate

Wire into PyTorch, and save pipelines for reproducibility.

9PyTorch & serializationdatasets & replay
!Common gotchasread before shipping

Worth memorizing

Compose once, call per sampletf(image=..., mask=..., bboxes=...) returns a dict; each call re-randomizes
NumPy HWC RGB, not PILnp.array(img); convert cv2 BGR→RGB
labels ride alongmasks, bboxes & keypoints transform consistently with the image
spatial vs pixel-levelspatial moves geometry (+labels); pixel-level changes only the image
OneOf to avoid stackingpick one of a group with probability p
BboxParams(format=...)pascal_voc / coco / yolo / albumentations; label_fields keeps labels aligned
min_area / min_visibilitydrop boxes a crop shrank too far
Normalize then ToTensorV2, lastToTensorV2 doesn't scale to [0,1] — Normalize does
A.save / ReplayComposeserialize pipelines; replay exact params on paired images