Deep Learning / Architectures and training dynamics / Lesson 14
Augmentation and Label Consistency
Apply data transformations only when inputs, targets, and evaluation boundaries remain meaningful.
On this page
Lesson goals
- Determine whether a transformation preserves a task label.
- Transform spatial targets consistently with an input.
- Evaluate augmentation without contaminating validation.
Choose a task-valid transformation
Augmentation creates altered training examples to expose a model to plausible variation. Whether a transformation preserves the target depends on the task. A horizontal flip might preserve the category of a generic object but change a left-versus-right label or the meaning of text. Document the intended invariance rather than assuming every visual change is safe.
For detection or segmentation, the target often has spatial structure. Transform the boxes or masks using the same geometric operation as the image. Keep source identity so augmented variants of one original cannot cross a train-validation boundary.
Flip a tiny image
This list represents a two-row synthetic image; reversing each row performs a horizontal flip. The values make the movement visible. It does not establish whether flipping is valid for a real task, and it is not a substitute for checking a libraryโs coordinate and interpolation conventions.
image = [[1, 2, 3], [4, 5, 6]]
flipped = [list(reversed(row)) for row in image]
print(flipped)
Each row reverses, producing [[3, 2, 1], [6, 5, 4]].
Transform a bounding interval
For a half-open horizontal interval [x_min, x_max) in an image of width W, a horizontal flip maps it to [W - x_max, W - x_min). The example assumes coordinates are measured from the left and the width is unchanged. Different conventions require their own verified formula.
width = 6
x_min, x_max = 1, 4
print(width - x_max, width - x_min)
With width 6, [1, 4) becomes [2, 5); the interval retains width three.
Protect evaluation
Split original entities before creating variants. Fit any learned preprocessing only on training data, and evaluate on held-out examples using the declared evaluation policy. A separate robustness test can intentionally apply perturbations, but report it separately from the primary evaluation. Record random state and transform configuration when reproducibility matters.
Inspect and compare
Visualize or inspect transformed input-target pairs, including edge cases near image boundaries. Check for empty boxes, altered label semantics, and unintended clipping. Compare training with and without the augmentation under the same split and budget, and inspect relevant slices; a lower training loss alone does not establish useful robustness.
Common errors and fixes
A flipped image has an unchanged location target.
- Why it happens
- The input was transformed without its bounding interval or mask.
- How to fix it
- Apply the matching geometry to both input and target.
- Prevent it next time
- Inspect transformed pairs and test boundary cases.
Validation results are suspiciously strong.
- Why it happens
- Variants of the same original appear in training and validation.
- How to fix it
- Split by source identity before augmentation.
- Prevent it next time
- Track provenance and enforce group separation.
A label becomes incorrect after a flip.
- Why it happens
- The task distinguishes left from right or contains directional text.
- How to fix it
- Remove the transform or update the label when a valid mapping exists.
- Prevent it next time
- Document task-specific invariances before augmentation.
2 practice exercises
1. A width-six image has a half-open box interval [1, 4). Where is it after a horizontal flip?
Show worked solution
The interval is [6 - 4, 6 - 1), or [2, 5). Its width remains three under the stated coordinate convention.
2. Why split original images before producing augmented variants?
Show worked solution
Variants of the same source can be highly related. Keeping them on one side of the split avoids measuring recognition of a near-duplicate as generalization to a new source.
Key takeaways
- A valid augmentation depends on task semantics.
- Spatial targets must follow the input transformation.
- Separate original sources before generating variants.