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 most augmentation stages run. Every path normalizes on GPU.

AX vs TorchVision on 44 shared recipes
AX vs TorchVision on 44 shared recipes Scroll horizontally to see the full chart. Open the image for full size.

Each comparison uses its own shared recipe set. Compare paths within each chart. 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,6913,8543,425
R02RandomCrop2244,4214,1204,464
R03RandomResizedCrop4,7063,5872,336
R04HorizontalFlip3,9554,1793,645
R05VerticalFlip4,2794,2203,495
R06Pad+RandomCrop2244,2443,5473,147
R07Rotate4,4092,4991,245
R08Affine4,1062,6521,280
R09Perspective4,1802,6451,262
R10Elastic3,03223622
R11ColorJitter3,569967689
R12ChannelShuffle4,7513,9862,867
R13Grayscale4,8043,8413,152
R14RGBShift4,655——
R15GaussianBlur4,3992,1681,904
R16GaussianNoise3,3761,2313,132
R17Invert4,9284,2213,483
R18Posterize4,9684,1473,075
R19Solarize4,6223,5833,168
R20Sharpen4,4812,3071,941
R21AutoContrast4,1602,7182,344
R22Equalize3,9762,9731,293
R23Erasing4,7263,8771,932
R24JpegCompression3,8683,3282,360
R25RandomGamma4,5863,0593,821
R26PlankianJitter4,340——
R27MedianBlur3,758——
R28MotionBlur4,213——
R29CLAHE3,109——
R30Brightness4,6333,8833,562
R31Contrast4,3803,4282,676
R32Blur4,851——
R33ChannelDropout4,732——
R34LinearIllumination3,826——
R35CornerIllumination3,991——
R36GaussianIllumination3,789——
R37Hue4,0641,403838
R38PlasmaBrightness2,603——
R39PlasmaContrast2,202——
R40PlasmaShadow2,502——
R41Rain3,979——
R42SaltAndPepper4,750——
R43Saturation4,354——
R44Snow3,733——
R45OpticalDistortion3,817——
R46Shear3,7562,8391,526
R47ThinPlateSpline3,139——
R48PhotoMetricDistort3,4821,172635
R49ColorJiggle3,6401,210687
R50LongestMaxSize+RandomCrop2243,7293,3802,492
R51SmallestMaxSize+RandomCrop2243,1873,0792,593
R52Transpose4,9454,0144,168
R53RandomRotate904,8464,1493,840
R54RandomJigsaw4,442——
R55EnhanceEdge4,480——
R56EnhanceDetail4,412——
R57UnsharpMask4,252——
R58CenterCrop4,6584,2405,997
R59Resize256+Crop4,5953,6053,302
R60Resize224+CropAndPad4,2842,9002,835
R61LetterBox4,6493,7722,762
R62PadIfNeeded+RandomCrop2244,4044,2754,014
R63Resize224+ChannelSwap4,5693,5852,636
R64Resize224+Colorize4,267——
R65Resize224+Dithering895——
R66Resize224+MorphologicalDilation4,496——
R67Resize224+MorphologicalErosion4,429——
R68RandomScale+RandomCrop2243,6633,0152,612
R69Resize224+RandomSizedCrop4,3133,2952,020
R70Resize224+CoarseDropout4,3623,5051,897
R71Resize224+Emboss4,159——
R72Resize224+PixelSpread3,524——
R73Resize224+ShiftScaleRotate3,8422,5441,352

Measurement setup and limits

When a batch arrives late, the GPU sits idle and completes fewer steps in the same time.
When a batch arrives late, the GPU sits idle and completes fewer steps in the same time. Scroll horizontally to see the full chart. Open the image for full size.

The timeline illustrates input stalls with a fixed model step duration.

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.

Run 03b5fd6c6fab74fd1029fc88012e03cb4b51d0a2e3c4b8be59ead6928efae6ee · 1323 measurements · measured source 3859d93 · machine-readable results · paper and methodology. This selected run differs from the paper's frozen results.

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.