Data Augmentation
Why Augmentation?
Data augmentation artificially expands the training dataset by applying random transformations that preserve the label. It's the most cost-effective regularization technique for computer vision — often gives 2–5% accuracy improvement for free.
Basic Augmentations
Geometric: RandomHorizontalFlip, RandomRotation, RandomCrop, RandomResizedCrop, RandomAffine, ElasticTransform. Color/Photometric: ColorJitter (brightness/contrast/saturation/hue), GaussianBlur, RandomGrayscale, RandomSolarize. Erasing: RandomErasing, Cutout — randomly masks regions, forces learning from partial views.
Advanced Augmentations
Mixup: blends two images and their labels linearly: x̃ = λx_i + (1-λ)x_j, ỹ = λy_i + (1-λ)y_j. CutMix: pastes a random crop from one image into another, mixes labels proportionally by area. RandAugment: applies N random operations from a fixed set, each at magnitude M. Removes the need for manual augmentation tuning. TrivialAugment: even simpler — one random op at a random strength. Matches RandAugment performance.
Augmentation Pipeline with torchvision & Albumentations
torchvision v2 for classification, Albumentations for segmentation tasks with synchronized mask transforms.
Use Albumentations for segmentation tasks — it automatically applies identical spatial transforms to both image and mask. torchvision v2 is great for classification.
Finished reading? Mark it complete to earn your XP.