Sub topic 11
Automated Policies: AutoAugment, RandAugment, and TrivialAugment
Assume you know Python, image tensors, supervised classification, train/validation splits, and basic PyTorch training loops. This chapter focuses on choosing and using automated image-augmentation policies. These policies select transformations for you instead of requiring a long, hand-written list of probabilities and strengths.
Why use an automated policy?
An augmentation policy is a rule for selecting image transformations during training. A transformation might change rotation, color, contrast, sharpness, or perspective. The goal is still label preservation: a transformed image should normally belong to the same class as the original.
Manual pipelines are easy to understand, but their settings can take time to tune. Automated policies reduce this search space. They do not discover the correct policy for every dataset automatically. They provide a useful starting point whose strength must still match the data.
The three common approaches differ in how much they search:
| Policy | How it chooses transforms | Main tuning burden |
|---|---|---|
| AutoAugment | Uses a policy learned from a separate search process | Select a suitable published policy |
| RandAugment | Randomly selects a fixed number of operations at one magnitude | Choose operation count and magnitude |
| TrivialAugment | Selects one operation and a random strength | Usually little or no tuning |
AutoAugment
AutoAugment searches for a policy using a validation set. A policy contains sub-policies. Each sub-policy contains operations, probabilities, and magnitudes. During training, one sub-policy is selected, and its operations are applied according to their probabilities.
For example, a sub-policy might apply rotation with probability 0.7 and color adjustment with probability 0.5. The search process tries many such combinations and keeps policies that improve validation performance.
Published policies are usually tied to a dataset family, such as natural-image classification. A policy found for one dataset may be too strong or inappropriate for medical images, satellite images, documents, or industrial inspection. AutoAugment can also be expensive to search because policy discovery requires many training runs.
RandAugment
RandAugment removes the large policy search. It chooses num_ops operations randomly from a fixed operation list. Each selected operation uses the same magnitude.
This gives two important controls:
num_opscontrols how many changes an image receives.magnitudecontrols how strong those changes are.
The following pipeline applies RandAugment before conversion to a floating-point tensor. In torchvision, this is appropriate when the input is a PIL image or a uint8 tensor.
from torchvision import transforms
train_tf = transforms.Compose([
transforms.RandomResizedCrop(224, scale=(0.7, 1.0)),
transforms.RandomHorizontalFlip(p=0.5),
transforms.RandAugment(num_ops=2, magnitude=9),
transforms.ToTensor(),
transforms.Normalize(
mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225],
),
])Start with a small number of operations and a moderate magnitude. Increase them only when validation results or visual inspection show that the model still overfits.
TrivialAugment
TrivialAugment selects one operation at random and samples its strength from the available range. It does not require a large policy search or a carefully selected magnitude shared by all operations.
This simplicity is useful when you need a strong baseline quickly. It can also be safer for a small dataset because there are fewer settings to overfit during tuning. However, one random operation may provide less diversity than RandAugment, depending on the operation set and data.
Choosing and validating a policy
Use the same deterministic evaluation pipeline for every policy comparison. Do not apply random augmentation to validation or test images. Otherwise, metric changes may come from different validation samples rather than model quality.
Compare policies with the same model, optimizer, training duration, and random-seed procedure. Record both training and validation metrics. A policy that lowers training accuracy but improves validation accuracy may be reducing overfitting. A policy that harms both metrics is probably too strong, incompatible with the domain, or incorrectly placed in the pipeline.
A common error is putting RandAugment after Normalize. Many operations expect PIL images or uint8 values, while normalization produces floating-point tensors with values centered around zero. Keep image-space operations before ToTensor and normalization unless the transform documentation explicitly supports normalized tensors.
Another error is using a policy in evaluation. Training should be stochastic; validation should be reproducible. Also inspect transformed images. A high validation score cannot reveal every annotation mistake or domain mismatch.
Exercise
Your classifier recognizes upright traffic signs, and RandAugment with magnitude 20 produces many upside-down signs. What should you change first?
Show answer
Reduce the magnitude or remove unsafe rotation operations, then compare the revised policy with the same deterministic validation pipeline.