Overview
AugmentationCfg defines data augmentation parameters for training image transforms. It controls random augmentations like resized cropping, color jitter, and random erasing.
Class Definition
Fields
Range of size of the random crop relative to the original image size. Used in RandomResizedCrop.
- First value: minimum crop scale (e.g., 0.08 = crop can be 8% of original)
- Second value: maximum crop scale (e.g., 1.0 = crop can be 100% of original)
(0.08, 1.0): Standard ImageNet training(0.9, 1.0): Light augmentation
Range of aspect ratio of the random crop. Used in RandomResizedCrop.
- First value: minimum aspect ratio (e.g., 0.75 = 3:4)
- Second value: maximum aspect ratio (e.g., 1.33 = 4:3)
Color jitter augmentation strength. Can be specified as:
- float: Applied to brightness, contrast, saturation (e.g.,
0.4) - Tuple[float, float, float]: (brightness, contrast, saturation)
- Tuple[float, float, float, float]: (brightness, contrast, saturation, hue)
(0.4, 0.4, 0.4, 0.1) = moderate jitter with slight hue variationRandom erasing probability. Probability of applying random erasing augmentation.
0.0: No random erasing0.25: 25% chance of erasing per image1.0: Always apply random erasing
use_timm=True.Number of random erasing operations per image when random erasing is applied.Requires
use_timm=True.Whether to use timm (PyTorch Image Models) augmentation transforms.When True, enables advanced augmentations from timm:
- RandAugment
- Random erasing
- More sophisticated augmentation pipelines
Probability of applying color jitter when
use_timm=False.0.0: Never apply color jitter0.8: Apply color jitter 80% of the time (common default)1.0: Always apply color jitter
use_timm=False.Probability of converting image to grayscale (with 3 channels) when
use_timm=False.0.0: Never grayscale0.2: 20% chance of grayscale (common default)1.0: Always grayscale
use_timm=False.Examples
Standard ImageNet augmentation
Light augmentation
Strong augmentation with timm
No augmentation
Custom aspect ratio range
Grayscale augmentation
Usage with image_transform_v2
Augmentation Strategy Guide
Light Augmentation
- scale: (0.9, 1.0)
- color_jitter: 0.2
- Best for: Fine-tuning, small datasets
Standard Augmentation
- scale: (0.08, 1.0)
- color_jitter: 0.4
- Best for: Training from scratch
Strong Augmentation
- use_timm: True
- re_prob: 0.25
- Best for: Large-scale training
Minimal Augmentation
- scale: (0.95, 1.0)
- No color jitter
- Best for: High-quality datasets
Notes
- Only used when
is_train=Trueinimage_transform_v2() color_jitter_probandgray_scale_probare ignored whenuse_timm=True- Random erasing (
re_prob,re_count) requiresuse_timm=True - Default values provide minimal augmentation; increase for stronger regularization
- For contrastive learning, stronger augmentation typically improves performance
See Also
PreprocessCfg- Preprocessing configurationimage_transform_v2()- Create transforms with config
