AlbumentationsX vs Torchvision

Compare AlbumentationsX with Torchvision transforms: API differences, RGB image benchmark results, and a PyTorch migration guide.

What Is Different?

Torchvision is the native augmentation layer for the PyTorch ecosystem. AlbumentationsX is framework-independent and optimized around NumPy/OpenCV image augmentation before tensors enter the model.

  • Torchvision commonly operates on PIL images or tensors; AlbumentationsX operates on NumPy arrays and can emit PyTorch tensors with ToTensorV2.
  • Torchvision integrates tightly with PyTorch datasets and model examples; AlbumentationsX focuses on faster CPU augmentation and richer computer-vision target handling.
  • AlbumentationsX pipelines pass named targets such as image, mask, bboxes, and keypoints; Torchvision v1-style pipelines are mostly image-first unless you use the newer tv_tensors stack.
  • AlbumentationsX tends to be easier when geometric transforms must stay consistent across masks, boxes, and keypoints.

RGB input pipeline results

Every path reads RGB JPEGs, prepares the recipe, and delivers a synchronized CUDA batch. CPU and GPU labels identify where augmentation runs; normalization runs on GPU for every path.

Mean relative throughput on the same 25 recipes. AlbumentationsX = 1×; higher is faster.
Mean relative throughput on the same 25 recipes. AlbumentationsX = 1×; higher is faster. Scroll horizontally to see the full chart. Open the image for full size.
Same 25 recipes for every row. Throughput is the arithmetic mean of per-recipe ratios to AlbumentationsX; memory is the median of per-recipe peak-memory medians.
Measured pathThroughput / AXGPU memory (MiB)
AlbumentationsX CPU1.00×1,852
TorchVision CPU0.69×1,814
TorchVision GPU0.66×1,972

Each comparison uses its own shared recipe set. Averages from different sets cannot rank all libraries. The table below includes every measured recipe for these paths, including recipes outside the summary set. Recipe names are shortened; hover over a name for its full pipeline.

Benchmark metric

Higher throughput is better. Values are medians across seeds. Hover for the observed range. A dash means no measured result.

R01Resize2244,7513,6713,852
R02RandomCrop2244,7404,4244,375
R03RandomResizedCrop4,7853,5183,558
R04HorizontalFlip4,7234,2074,374
R05VerticalFlip4,9074,3194,594
R06Pad+RandomCrop2244,3973,6853,626
R07Rotate3,3522,5851,535
R08Affine3,0492,3841,478
R09Perspective2,8792,179886
R10Elastic1,99023622
R11ColorJitter3,5231,203731
R12ChannelShuffle5,0264,2254,337
R13Grayscale5,1573,8914,387
R14RGBShift4,348
R15GaussianBlur4,6792,4472,811
R16GaussianNoise3,288
R17Invert5,0764,0674,430
R18Posterize5,1104,3364,453
R19Solarize4,6073,6714,520
R20Sharpen4,2232,1173,239
R21AutoContrast4,2632,6873,859
R22Equalize3,9863,0641,591
R23Erasing4,9384,0102,907
R24JpegCompression4,2323,448
R25RandomGamma4,969
R26PlankianJitter4,538
R27MedianBlur3,805
R28MotionBlur4,223
R29CLAHE2,373
R30Brightness4,6223,8234,434
R31Contrast4,6423,3773,333
R32Blur4,821
R33ChannelDropout4,972
R34LinearIllumination3,866
R35CornerIllumination4,090
R36GaussianIllumination3,930
R37Hue4,274
R38PlasmaBrightness2,461
R39PlasmaContrast2,162
R40PlasmaShadow2,489
R41Rain4,069
R42SaltAndPepper4,147
R43Saturation4,136
R44Snow3,857
R45OpticalDistortion3,110
R46Shear2,658
R47ThinPlateSpline858
R48PhotoMetricDistort3,3691,170670
R49ColorJiggle3,5261,221742
R50LongestMaxSize+RandomCrop2243,658
R51SmallestMaxSize+RandomCrop2243,221
R52Transpose4,942
R53RandomRotate905,002
R54RandomJigsaw4,662
R55EnhanceEdge4,389
R56EnhanceDetail4,720
R57UnsharpMask3,120

Measurement setup and limits

Throughput measures batch consumption and final CUDA synchronization. GPU memory is sampled from pipeline construction through cleanup.
Throughput measures batch consumption and final CUDA synchronization. GPU memory is sampled from pipeline construction through cleanup. Scroll horizontally to see the full chart. Open the image for full size.

g2-standard-16, nvidia-l4; 10,000 selected ImageNet JPEGs. Batch size 256, 15 workers, prefetch factor 2; persistent workers enabled. Output: cuda float16, BCHW 256×3×224×224.

Seeds: 137, 138, 139. Each observation follows 1 warm-up batch and times 32 batches, ending with CUDA synchronization. Pipeline construction and worker startup are outside throughput timing; prefetch effects remain. JPEG files are prewarmed, so this measures filesystem reads and decoding with a warm page cache.

NVML samples peak process GPU memory every 50 ms, from pipeline construction through final synchronization and cleanup. Brief peaks can be missed. The measurements include no model and do not establish training speed or augmentation quality. Seeds do not guarantee identical augmentation draws across libraries. Observed ranges describe variation between runs; they are not confidence intervals.

In this published run, DALI Crop includes resizing the short side, and DALI Affine omits rotation and shear.

Run 3f8e2e315710528399b8e82e2359ab85c58c809644595b68a92fb9d83492cc8c · 759 measurements · measured source 5fc35f6 · machine-readable results · paper and methodology. This is the run reported in the paper.

Conversion Guide

In PyTorch projects, the usual migration is to keep your Dataset and DataLoader, replace torchvision.transforms with AlbumentationsX, then finish with ToTensorV2.

  • Read images as NumPy arrays, usually with OpenCV plus BGR to RGB conversion.
  • Replace transform lists with A.Compose.
  • For classification, return transformed['image'] after ToTensorV2.
  • For detection or segmentation, pass masks, bboxes, labels, and keypoint params through Compose instead of updating them manually.
Torchvision
from torchvision import transforms

transform = transforms.Compose([
    transforms.RandomHorizontalFlip(p=0.5),
    transforms.ColorJitter(brightness=0.2, contrast=0.2),
    transforms.ToTensor(),
])

image = transform(pil_image)
AlbumentationsX
import albumentations as A
from albumentations.pytorch import ToTensorV2

transform = A.Compose([
    A.HorizontalFlip(p=0.5),
    A.RandomBrightnessContrast(brightness_limit=0.2, contrast_limit=0.2, p=0.5),
    ToTensorV2(),
])

image = transform(image=image_np)["image"]

Use AlbumentationsX When

  • PyTorch training pipelines where CPU augmentation speed matters.
  • Detection, segmentation, keypoints, and multi-input augmentation where targets must stay aligned.
  • Projects that want the same augmentation library across PyTorch, TensorFlow, Keras, and custom training loops.

Use Torchvision When

  • Simple PyTorch classification baselines that already use torchvision examples.
  • Tensor-native workflows that rely on torchvision transforms, tv_tensors, or PyTorch-only deployment assumptions.