3.4.15 · D4Convolutional Neural Networks

Exercises — Data augmentation for images

2,591 words12 min readBack to topic

This page is a self-test. Each problem states cleanly what to find; the full worked solution hides inside a collapsible [!recall]- callout so you can try first, then reveal. Problems climb from recognition to mastery. After each level, a [!mistake] callout steel-mans the trap most people fall into there.

Prerequisite ideas (build them if rusty): the parent note, 5.2.3-Overfitting-vs-underfitting, 6.14-Generalization-in-ML, 3.4.8-Dropout-in-neural-networks, 3.4.12-Transfer-learning-CNs.

Everything below reuses only symbols the parent defined. Where a picture helps (rotation, flip, crop), a chalkboard figure carries the geometry.


Level 1 — Recognition

Recall Solution 1.1

A transformation is label-preserving when a human still reads the same digit afterward.

  • (a) Horizontal flip — NO. A flipped 2 looks like a mirror 2 (not a real digit); a 3 becomes a backwards shape. Mirror-symmetry is not respected by digits.
  • (b) Rotation — YES. A slightly tilted 5 is still a 5. Small tilts occur naturally in handwriting.
  • (c) Rotation — NO. A 6 rotated becomes a 9. The label changes, so this breaks the constraint.
  • (d) Brightness — YES. A brighter 7 is still a 7; intensity does not carry digit identity.

Answer: label-preserving = (b), (d); not = (a), (c).

Recall Solution 1.2
  • (i) = Cutout / Random Erasing — masks a rectangle to zero.
  • (ii) = MixUp, and crucially the label mixes too.
  • (iii) = Horizontal Flip.

Level 2 — Application

Figure — Data augmentation for images
Recall Solution 2.1

Use the parent formula . The pixel moves to column 26, row 10 — the same distance from the right edge (5 from left → 5 from right, and ). The figure shows the original dot and its mirror partner reflected across the vertical centre line. Answer: .

Recall Solution 2.2

is inside , so no clipping needed. Answer: . Note the two effects fight: contrast pushed it up to 120 (it was below the mid-grey 127.5, so actually darkens dark pixels only if shifts them — here the net move is down because dominated).

Recall Solution 2.3

Why modulo? Hue is a circle: and are the same red. Adding to walks past the top of the wheel and lands at . Without the wrap we'd get an illegal . Answer: .


Level 3 — Analysis

Figure — Data augmentation for images
Recall Solution 3.1

At : . So — the point on the +x axis swings up to the +y axis. Look at the blue quarter-turn arc in the figure. At : . So ✓ — a half-turn flips the point to the opposite side. Answers: then .

Recall Solution 3.2

pixels².

  • Smallest area: → side px.
  • Largest area: → side px. So crops range from about up to , all then resized to the network's fixed input. The smallest crop occupies only of the image, forcing scale invariance: the model must recognise an object even when it fills a large fraction of a zoomed-in view. Answers: min side px, max side px.
Recall Solution 3.3

The target is a soft label: 70% cat, 30% dog. This is exactly the "smoother decision boundary" idea — the network is asked for a graded, calibrated answer instead of a hard 0/1. Answer: .


Level 4 — Synthesis

Recall Solution 4.1

(a) Each epoch shows all images once, each freshly augmented: views per epoch. Over epochs: (b) Here (distinct views per image) , one per epoch. It is called potentially infinite because the transforms draw continuous parameters — a rotation angle , a crop area , a brightness from continuous ranges — so there is no finite catalogue of augmentations; each epoch samples new real-valued parameters and (almost surely) never exactly repeats. Answers: (a) ; (b) realised, unbounded in principle.

Recall Solution 4.2

Step 1 — flip. New point . Step 2 — rotate . With : Answer: . What it means: augmentations compose — the order matters. Flipping first then rotating is generally not the same as rotating first then flipping (matrix multiplication is not commutative), which is why augmentation pipelines fix a definite order.

Recall Solution 4.3
  • Horizontal flip — RISKY. Anatomy is left–right asymmetric (heart on the left, liver on the right); flipping can create anatomically impossible images and mislead a model that has learned true side-specific cues. Use only with caution.
  • Vertical flip — NO. An upside-down chest never occurs; not realistic.
  • rotation — NO. Same reason; degenerate, unrealistic.
  • Brightness — YES. Simulates exposure/scanner differences; label unchanged.
  • Small rotation — YES. Patient positioning varies slightly; realistic and label-preserving.
  • MixUp — CAUTIOUS YES. Blending can improve calibration, but blended X-rays are non-physical; used, but often with small effect. Key principle: medical imaging tightens the "could this occur naturally?" test far more than natural photos.

Level 5 — Mastery

Recall Solution 5.1

The inner expectation is the average loss over the augmentations: Gradient descent minimises this averaged loss, not the loss on any one view. The effect: the model can't drive one view's loss to zero by memorising its exact pixels — it must lower the loss across all transformed versions simultaneously, which pushes it toward features invariant to . That invariance is the source of the generalization gain (link to 6.14-Generalization-in-ML). Answer: .

Recall Solution 5.2
  • :
  • : Interpretation. Both distributions are symmetric about mean . The larger variance at means is pushed toward the extremes or — i.e. little actual mixing (one image dominates, gentle augmentation). The small variance at means clusters near heavy, near-uniform mixing (both images contribute almost equally). This is exactly why the parent recommends small : enough blending to smooth boundaries, not so much that inputs become mush. Answers: and .
Recall Solution 5.3

Independent per-pixel noise leaves every region partly visible, so a model can still lean on its single favourite discriminative patch. A contiguous rectangular mask removes an entire region's information at once, mimicking a real-world occluder (a tree in front of a car, a hand over a face). To keep the loss low when any region might vanish, the network must spread its evidence across multiple distributed features — precisely the robustness Cutout targets. So contiguity, not mere randomness, is the mechanism: it reproduces the structure of real occlusion. This is regularization in the same family as 3.4.8-Dropout-in-neural-networks (drop information to prevent over-reliance on any one path).


Recall Self-test checklist (reveal to grade yourself)

Can you flip a pixel with the correct ? ::: Yes — . Can you rotate by from the matrix? ::: Yes — . Can you write a MixUp soft label at ? ::: for cat/dog. Do you know why the augmented objective uses an expectation, not a minimum? ::: Because we want invariance across all views, not the easiest one.