Sub topic 13
Inspecting, Validating, and Tuning Augmentation Strength
Assume you know Python, image arrays, supervised learning, train/validation splits, and a basic PyTorch training loop. This chapter focuses on checking whether augmentation creates useful variation without destroying the task signal.
Start with visual inspection
A model cannot tell you whether an augmentation is sensible. Inspect transformed images before training. Display several original images beside several independently augmented versions. Check object identity, important details, colors, geometry, and image boundaries.
Use the same fixed source images while tuning. Otherwise, a different random sample can make one configuration appear better by chance.
from PIL import Image
import matplotlib.pyplot as plt
from torchvision import transforms
image = Image.open("data/example.jpg").convert("RGB")
transform = transforms.Compose([
transforms.RandomResizedCrop(224, scale=(0.6, 1.0)),
transforms.RandomHorizontalFlip(p=0.5),
transforms.ColorJitter(
brightness=0.25,
contrast=0.25,
saturation=0.25,
hue=0.05,
),
])
fig, axes = plt.subplots(2, 4, figsize=(12, 6))
axes[0, 0].imshow(image)
axes[0, 0].set_title("Original")
axes[0, 0].axis("off")
for index in range(1, 8):
augmented = transform(image)
axes.flat[index].imshow(augmented)
axes.flat[index].set_title(f"Augmented {index}")
axes.flat[index].axis("off")
plt.tight_layout()
plt.show()Look for transformations that produce images a human would still assign the same label. A crop that removes the object, a rotation that is impossible in the real setting, or a color shift that changes the class is too strong.
Measure the effect with controlled experiments
Keep the model architecture, optimizer, training duration, data split, and random seeds constant. Change one augmentation setting or one small group of related settings at a time. Compare the unaugmented baseline with augmented runs.
| Observation | Likely interpretation | Next action |
|---|---|---|
| Training accuracy rises, validation accuracy lags | Overfitting remains | Increase useful augmentation or add other regularization |
| Both accuracies fall after stronger transforms | Signal may be destroyed | Reduce severity or probability |
| Training accuracy falls, validation accuracy improves | Augmentation is regularizing effectively | Keep it and check repeated runs |
| Validation results vary greatly between runs | Experiment is noisy | Use fixed seeds and multiple runs |
Do not tune augmentation against the test set. Use the validation set for decisions, then evaluate the final configuration on the test set once. Record the transform settings, seed, dataset version, and validation metrics for every experiment.
Tune probability and severity
Most transforms have two controls:
- Probability determines how often the transform runs.
- Severity determines how strongly it changes an image.
For example, a horizontal flip may use probability 0.5, while ColorJitter controls brightness or contrast ranges. Start with realistic values. Increase one control gradually instead of maximizing every setting.
Augmentations interact. A strong crop followed by a strong rotation can be much more destructive than either operation alone. Inspect the complete pipeline, not only each transform separately.
Use a validation checklist
Before trusting a result, verify the following:
- Training samples change across epochs.
- Validation and test samples use deterministic transforms.
- Class balance is not accidentally changed by filtering or failed transforms.
- Labels remain correct after every operation.
- Augmented pixels stay in the expected range and normalization is applied once.
- Performance is measured on several seeds when differences are small.
- Improvements appear on realistic validation data, not only on synthetic examples.
Exercise
Validation accuracy decreases after adding strong random crops, but training accuracy also decreases. What should you test first?
Show answer
Reduce the crop severity or probability, then inspect whether important objects are being removed. The simultaneous decrease suggests that the model is receiving overly difficult or invalid examples.