Settings

Theme
Lite Mode (saves mobile data)

In Lite Mode, animations and videos don't play until you tap them, and their size is shown first. Interactive widgets still work.

Text size

Back up or move your progress →

Part 4: Neural Network Foundations

Data augmentation

P4.1835 min●●○ IntermediateReviewed Dec 3, 2026

Why this matters for machine learning

A model can only learn what its training examples show. Augmentation adds examples that differ in the ways you expect new data to differ, so a model does not have to learn from scratch that a shifted digit is the same digit.

Before this: Build an MLP from scratch (NumPy), Regularization for neural nets, Vector operations

After this lesson you can

  • Explain augmentation as new examples made by label-preserving changes, and as a choice of what the model should ignore
  • Decide, for a data set, which transformations keep the label and which can change it
  • Apply flips, shifts, rotations, brightness, contrast, noise and cutout by hand to a small image
  • Compute a mixup example and its mixed label, and say what CutMix changes
  • Say where augmentation is applied (training only, fresh each time) and why the split comes first
  • Read an augmentation experiment honestly, including when augmentation hurts

A photo of a cat, moved two pixels to the left, is still a photo of a cat. You know that. A network trained on the first photo does not: to its first layer, the shifted photo is a different list of numbers (P4.5). You could collect more photos, but photos need labels, and labels cost money.

Data augmentation is the cheap alternative. Take each training example, change it in a way that should not change its label, and train on the changed copy. The cat moves, brightens or flips, and the label stays “cat”. The data set has not grown on disk, but the network now sees many versions of each example.

The idea, and the bet it makes

Two things are true at the same time:

  • It gives the model more to learn from. A network with thousands of weights can memorize a small training set (P3.A5, P4.17). If every pass shows each image a little differently, memorizing one fixed pixel pattern is harder, and the useful signal (the shape of the digit) is what stays the same.
  • It is a statement about the world. Choosing to shift images says “the label does not depend on where the object is”. Choosing not to flip digits says “left and right matter here”. The model is not told this in words. It is told by examples. So augmentation puts your knowledge into the training data, the way a penalty in the loss puts it into the objective (P3.A6, P4.17).

That makes it a bet. If new data really varies in the way you augmented, you win. If you augment in a way the data never varies, you spend the model’s capacity on cases that never come up, and the model can get worse. The experiment at the end of this lesson shows both outcomes on real digits.

The augmentation preview

The widget below uses the 8 by 8 digit images of P4.10 (one example per digit, chosen as the image closest to the average of its digit) and one made-up colour picture so colour changes are visible. In Part 1, change one thing at a time. In Part 2, draw random combinations the way a training loop does.

Part 1: one transformation at a time
Original
Result
Mixed in (B)
Label of the result
6 1.00

No warning: nothing here should change which class this is.

Order of the steps: flip, rotate, shift, saturation, contrast, brightness, noise, cutout, then mixup with the unchanged image B. Black is 0 and white is 1. The noise pattern is fixed by the seed below.


Part 2: random copies, as a training loop would draw them
seed 7, draw 1
1 6
2 6
3 6⚠
4 6⚠
5 6
6 6
7 6⚠
8 6
Warnings on 3 of 8 copies (red outline)
  • Copy 3. The flip, rotation or shift pushed 10% of the picture out of the frame.
  • Copy 4. The flip, rotation or shift pushed 15% of the picture out of the frame.
  • Copy 7. The flip, rotation or shift pushed 15% of the picture out of the frame.

The same seed and the same draw number always give the same eight copies. Allowed now: rotate (-15 to 15 degrees); shift (1 pixel for digits, 2 for the picture); brightness and contrast (-0.2 to 0.2 and 0.7 to 1.3 (saturation 0.6 to 1.4 for the picture)); noise (size 0 to 0.15). Copies use image A (Digit 6); a mixup partner is another picture of the same kind chosen at random.

Augmentation preview. Part 1: pick a sample picture, then flip it, rotate it, shift it, change brightness, contrast, saturation and noise, erase a square, or mix in a second picture with a lambda slider. Red warnings mark changes that can alter the label. Part 2: choose which changes may be drawn and press Random augment for eight seeded copies. Black pixels are 0 and white pixels are 1.

Things to try:

  • Digit 6, rotate to 180. The picture turns into something that looks like a 9, and the warning says the label would now be wrong. Rotate by 10 or 15 degrees instead: still a 6.
  • Digit 6, flip. It is a mirror image that no writer produces. Flip digit 0, 1 or 8 and the warning goes away, because the widget treats those as roughly symmetric (a rule of thumb; mirrored 4s are still close to real 4s).
  • Shift right by 3. Part of the digit leaves the frame, and the warning counts how much. A shift of one pixel on an 8 by 8 image is already a big move, one eighth of the width.
  • Mixup. Keep digit 6, mix in digit 9, and set lambda to 0.3. The picture is a ghostly blend and the label bars read 0.70 for the 6 and 0.30 for the 9.
  • Part 2. Turn every change off except Cutout and press Random augment a few times. Then turn on Flip and watch the red marks appear.

Which changes keep the label?

The rule is one question: would a careful person still give this image the same label? If yes, the change is label-preserving, and it is a candidate. If not, it is label-changing, and it is a bug in the training data: the model is told a wrong answer, with full confidence.

Run the cell below. Its first part prints one handwritten 6 and the same picture turned by 180 degrees. Then it uses a crude reader, which names the class whose average image is closest, to count what happens to all the 6s. A trained network would be a better reader; this one is simple enough to write in five lines.

Step 1: load the digits and test the changes

First run downloads about 9 MB (Python 6, NumPy 3; once) and a 118 KB data file. The cells of this lesson share their variables, so run them in order.

Output (computed in advance; run the cell to reproduce it)
a 6, then turned 180 degrees
 #:   
:@    
#.    
@.    
.@*##. 
.@#.*# 
##.## 
 #@#  
--------
#@#   
##.##  
#*.#@. 
.##*@. 
  .@  
  .#  
  @:  
 :#   
6s read as 6:        0.967
turned, read as 9:   0.818
turned, read as 6:   0.0
mirrored 2s read as 2: 0.017
mirrored 5s read as 5: 0.0

Read the output:

  • The picture of the turned 6 looks like a 9. The crude reader agrees: 81.8 per cent of the turned 6s are closest to the 9 average, and none is closest to the 6 average. Training with this change and the label “6” would teach the network a wrong rule.
  • Mirrored 2s and mirrored 5s are almost never closest to their own class: 1.7 per cent and 0 per cent. The reader is crude, so the numbers are not exact; they say that a mirrored digit is far from where real 2s and 5s live. The mirror does not reliably turn a 2 into another digit. It mostly makes something that is not a normal digit, so it spends training effort on pictures that never appear in the test data (a milder problem than a wrong label, which is what turning a 6 gives).

So the answer depends on the data, not on the transformation:

  • Digits and letters: mirror flips are unsafe (b and d are mirror images of each other), and so are large rotations (6 and 9).
  • Photos of animals and everyday objects: left-right flips are usually safe. Up-down flips usually are not (the sky is on top).
  • Medical images, satellite images, text in images: it depends on the task. Where left versus right carries meaning, flips are unsafe. Ask someone who knows the field, and look at the outputs.
  • Magnitude matters as much as kind. A 5 degree rotation is safe for a 6. Rotating by 180 degrees is not.

The usual image changes

Geometric changes move the pixels.

  • Horizontal flip: the pixel in column xx goes to column W−1−xW-1-x. Cheap and popular for natural images.
  • Random crop with padding: pad the image with zeros (or a copy of the edge), then cut a random window of the original size. For a 32×3232\times32 image padded by 4 on each side, the padded image is 40×4040\times40 and the window can start in 40−32+1=940-32+1=9 places in each direction, so there are 9×9=819\times9=81 possible crops. A common recipe for small photos is a random crop plus a flip (P5.7). For our 8 by 8 digits, padding by 1 gives 3×3=93\times3=9 crops, which is the same as shifting by −1-1, 00 or +1+1 pixel in each direction. The experiment below uses exactly this.
  • Small rotation and shift: a rotation by θ\theta about the centre looks up, for every output pixel, the input pixel that lands there. The result rarely falls exactly on a pixel, so a rule is needed: take the nearest pixel (what the widget does) or blend neighbours (bilinear interpolation, which looks smoother and is common for photos). Pixels that come from outside the picture are filled with black here, or with a copy of the edge.
  • Scaling: zoom in (crop, then resize) or out (shrink, then pad).

Photometric changes change the values and leave the positions alone. In the widget they are applied to values between 0 and 1, then clipped back into that range:

  • Brightness adds a number: v←v+bv\leftarrow v+b.
  • Contrast stretches values away from the middle: v←(v−0.5) c+0.5v\leftarrow (v-0.5)\,c+0.5. With c<1c<1 everything moves toward grey.
  • Saturation (colour pictures) moves each colour toward its grey value gg, the weighted sum 0.299R+0.587G+0.114B0.299R+0.587G+0.114B of its red, green and blue: v←g+s (v−g)v\leftarrow g+s\,(v-g). At s=0s=0 the picture is grey.
  • Colour jitter is the name for changing brightness, contrast, saturation (and often hue) by small random amounts together.
  • Noise: add a random number to each pixel, here from a normal distribution scaled by the noise size. Blur averages neighbouring pixels. Both teach the model not to depend on fine detail.

Clipping matters. After v+bv+b a pixel can leave the range [0,1][0,1]; most image code clips it back, and the widget does too.

Erasing. Cutout hides a random square of each training image (DeVries and Taylor, 2017). The model cannot rely on one small region and has to use other evidence as well. The widget’s cutout fills the square with 0, which is black. When the square covers the stroke that tells two classes apart, the label becomes doubtful, which is why the widget reports the share of the picture erased.

Mixup and CutMix

The changes so far keep one image and one label. Mixup (Zhang, Cisse, Dauphin and Lopez-Paz, ICLR 2018) takes two training examples and trains on a blend of both. With images x1\mathbf{x}_1, x2\mathbf{x}_2 and one-hot labels y1\mathbf{y}_1, y2\mathbf{y}_2 (P3.A8), it builds

x~=(1−λ) x1+λ x2,y~=(1−λ) y1+λ y2.\begin{aligned} \tilde{\mathbf{x}}&=(1-\lambda)\,\mathbf{x}_1+\lambda\,\mathbf{x}_2,\\ \tilde{\mathbf{y}}&=(1-\lambda)\,\mathbf{y}_1+\lambda\,\mathbf{y}_2 . \end{aligned}

This is the linear combination of P1.B2, with the same formula as the point (1−t)a+tb(1-t)\mathbf{a}+t\mathbf{b} on the segment between two vectors: λ=0\lambda=0 gives the first example and λ=1\lambda=1 the second. The new label is a soft label: not “6” but “70 per cent 6 and 30 per cent 9”.

The number λ\lambda is drawn at random for each pair (or, as in the paper’s reference code, once per batch, as in the Code tab) from a Beta(α,α)(\alpha,\alpha) distribution (P1.D9 draws numbers from distributions; this one lives on the interval from 0 to 1). The setting α\alpha controls how much blending there is. The next cell blends the 6 of the widget with its 9 at λ=0.3\lambda=0.3, one pixel by hand, then checks two things: the loss for the mixed label equals the same mix of the two ordinary losses, and how the Beta distribution spreads.

Step 2: one mixup example

First run downloads about 9 MB (Python 6, NumPy 3; once) and a 118 KB data file. The cells of this lesson share their variables, so run them in order.

Output (computed in advance; run the cell to reproduce it)
pixel (4,1): six 0.1875, nine 0.0000
mixed: 0.7*0.1875 + 0.3*0.0000
   = 0.13125
label: 6 -> 0.7 , 9 -> 0.3
loss, soft label:    1.1963
0.7*loss(6) + 0.3*loss(9): 1.1963
Beta(1.0): mean 0.501, ends 0.199
Beta(0.4): mean 0.499, ends 0.479
Beta(0.2): mean 0.500, ends 0.674

Read the output:

  • The pixel is 0.7×0.1875+0.3×0=0.131250.7\times0.1875+0.3\times0=0.13125. Every pixel is blended with the same λ\lambda, and so are the 10 numbers of the label.
  • The cross-entropy with the soft label equals 0.70.7 times the loss against “6” plus 0.30.3 times the loss against “9”. In practice the program computes the two ordinary losses and mixes them, with no special soft-label code (the cross-entropy is linear in the target, P4.6). This holds for any scores: both losses use the network’s one output for the mixed picture, so one forward pass is enough. The scores 2 and 1 here are made up.
  • A Beta(1,1)(1,1) draw is a plain uniform number: about 20 per cent of draws fall within 0.1 of an end. At α=0.4\alpha=0.4 it is 48 per cent and at α=0.2\alpha=0.2 it is 67 per cent: a small α\alpha gives mostly nearly pure examples with an occasional real blend. Every setting has mean 0.5. (The widget’s Part 2 draws λ\lambda from Beta(0.4,0.4)(0.4,0.4).)

CutMix (Yun and others, ICCV 2019) mixes by area instead of by pixel value. It cuts a rectangle out of one image and pastes in the same rectangle from another. Every pixel is a real pixel from one image, and the label is mixed by area: if the pasted patch covers a share aa of the picture, the label is (1−a) y1+a y2(1-a)\,\mathbf{y}_1+a\,\mathbf{y}_2.

What these do, and what is claimed. Mixup trains the network to behave in a simple way between training examples (the paper’s argument). The authors reported better generalization for several architectures and data sets, including ImageNet and CIFAR, and less memorization of wrong labels. In a separate check of the 100-image digit task below (not shown in the cells), mixup with α\alpha of 0.2, 0.4 and 1 gave test accuracies between 0.870 and 0.883, against 0.885 and 0.888 without it (10 splits, 60 and 150 epochs). The differences are small compared with the spread between splits (about 0.02), so read this as no clear gain, not as mixup hurting. Do not expect it to help everywhere. Mixup and CutMix are applied to training batches only: at test time you give the network a single, unmixed image.

Where augmentation is applied

Training only, after the split. Augment the images the model trains on. The validation and test images must stay as they are, because they measure what the model does on real data (P3.A4). Split first, then augment: if you make augmented copies of every image and then split, copies of one picture land on both sides, and the validation score becomes too good to be true. Fixed preprocessing (resize, scale to 0..1, normalize) is not augmentation and is applied to every split in the same way.

Fresh randomness every time. Two designs:

  • On the fly. Each time an image is read for a batch, a new random change is drawn and applied. Nothing is stored, and no two epochs show the same picture. This is what training code normally does.
  • A fixed enlarged data set. Make kk copies of every image once and store them. It is simple but the data set takes kk times the space, and the network sees only those kk versions. With 50,000 images and k=20k=20 it is 1,000,0001{,}000{,}000 images.

The draws are random numbers like any others (P1.G3): the loop draws a flip, a crop offset or a rotation angle for every image every time. That is a Monte Carlo view (P1.D9): the aim is to minimize the average loss over all the changes you might draw, and a single fresh draw per image per step is a one-sample estimate of that average. For a run you can repeat, seed the generator that makes the augmentation too, not only the one that initializes the weights; the widget’s Part 2 shows the idea: same seed and draw number, same eight copies.

Test-time augmentation is a different trick: at prediction time, average the model’s outputs over a few label-preserving copies of one image (for example the image and its mirror image). It can give a small gain at several times the cost per image, and how much it helps depends on the model and the data.

Look at the outputs. Save 20 augmented images with their labels and look at them, as the widget does. Mistakes show at once: an unrealistic crop, a label-changing flip, a picture clipped to white. For boxes (P5.11) or masks (P5.13), the labels must move together with the pixels.

Beyond this lesson. Text, audio and tables have their own label-preserving changes, each with the same question of whether the label survives; for images, AutoAugment (Cubuk and others, 2018 preprint, CVPR 2019) searches for a policy of changes and RandAugment (Cubuk and others, 2019) shrinks the search to a few settings.

An experiment on 100 digits

How much do these things matter? Use a small task where augmentation has the best chance: a network of the P4.10 kind (64→32→1064\to32\to10) trained on only 100 digit images, tested on the other 1,697. Three runs, with the same starting weights and the same order of data:

  • no augmentation,
  • shift half the time: with probability 0.5, move the image by −1-1, 00 or +1+1 pixels in each direction (the random crop with padding 1 of above),
  • shift every time: with probability 1.

Each run is tested twice: on the test images as they are (the digits are centred) and on the same test images shifted by a random step of at most one pixel. Five different splits and starting weights, averaged. The cell trains 15 networks for 200 epochs each, so allow a few seconds.

Step 3: train with and without shifts

First run downloads about 9 MB (Python 6, NumPy 3; once) and a 118 KB data file. The cells of this lesson share their variables, so run them in order.

Output (computed in advance; run the cell to reproduce it)
100 training images, 5 seeds
shift prob   as is   shifted test
 0.0       0.887     0.348
 0.5       0.886     0.775
 1.0       0.856     0.821
seconds: 2.3

What the numbers say, and what they do not:

  • On the shifted test images, augmentation is a large win. Accuracy rises from about 0.35 to 0.78 with shifts half the time and to 0.82 with shifts every time. The network without augmentation never saw a shifted digit, so a one-pixel move breaks it. This is what augmentation is for.
  • On the centred test images it is not a win. Shifting half the time gives about the same accuracy as no augmentation (0.886 against 0.887; with five runs and 1,697 images a gap this small is noise). Shifting every time costs about three points (0.856), and it was worse in all five runs. Only one shifted image in nine is still centred, so the network practises on a different set of pictures from the one it is tested on.
  • Augmented runs need more training. With 60 epochs instead of 200 (the same cell with epochs=60), the numbers on the centred images are 0.884 with no shifts, 0.864 with half shifts and 0.774 with shifts every time, and on the shifted images 0.350, 0.613 and 0.706. The augmented networks had not finished learning. Each epoch shows each image once, in one of up to nine positions, so there is more to learn. At 200 epochs the augmented runs may still not have fully converged; the cell does not check this.
  • This is one small, easy task. It uses whole-pixel shifts on 8 by 8 images, where one pixel is a large move. On the big photo sets of the papers, augmentation is reported to help on ordinary test images too. Do not carry the numbers from here to those.

The lesson of the experiment is the one of the bet above: augmentation pays when the variation it adds is variation the model will meet. It is not free: it needs a good choice of changes, a size that fits, and more epochs.

Summary: intuition, math, code

Intuition

Imagine teaching a child what a 6 is by showing one drawing. Now show it slightly higher on the page, slightly bigger, a little darker. The child learns that these things do not matter. Augmentation does this for a network. The analogy breaks in one place: the child can tell that a 6 upside down is a 9, and a network only learns this if you do not show it that picture labelled “6”. The model has no common sense about which changes are safe: you do.

Math

Training minimizes the average loss 1N∑iL(fθ(xi), yi)\frac1N\sum_i L\big(f_{\boldsymbol{\theta}}(\mathbf{x}_i),\,y_i\big). With augmentation, each example is first changed by a random transformation TT drawn from a distribution T\mathcal{T} (flip or not, crop offset, angle, noise), and the objective is the average over both:

1N∑i=1NET∼T[L(fθ(T(xi)), yi)].\frac1N\sum_{i=1}^{N}\mathbb{E}_{T\sim\mathcal{T}}\Big[L\big(f_{\boldsymbol{\theta}}(T(\mathbf{x}_i)),\,y_i\big)\Big].

One fresh draw of TT per example per step is a Monte Carlo estimate of the inside average. Mixup: x~=(1−λ)x1+λx2\tilde{\mathbf{x}}=(1-\lambda)\mathbf{x}_1+\lambda\mathbf{x}_2, y~=(1−λ)y1+λy2\tilde{\mathbf{y}}=(1-\lambda)\mathbf{y}_1+\lambda\mathbf{y}_2, with λ∼Beta(α,α)\lambda\sim\mathrm{Beta}(\alpha,\alpha); the cross-entropy with soft label y~\tilde{\mathbf{y}} is (1−λ)L(⋅,y1)+λL(⋅,y2)(1-\lambda)L(\cdot,\mathbf{y}_1)+\lambda L(\cdot,\mathbf{y}_2). Photometric: v←clip((v−0.5)c+0.5+b)v\leftarrow\mathrm{clip}\big((v-0.5)c+0.5+b\big) for contrast cc and brightness bb. Crop count: padding pp on a WW-wide image gives (2p+1)(2p+1) crop positions per direction.

Code

The core of an on-the-fly shift and a mixup step in NumPy. The full experiment with its output is in the section above.

def mixup(xb, Yb, rng, alpha=0.4):
    lam = rng.beta(alpha, alpha)              # one lambda per batch
    j = rng.permutation(len(xb))              # a random partner for each image
    return (1 - lam) * xb + lam * xb[j], (1 - lam) * Yb + lam * Yb[j]

# inside the training loop, with Yb one-hot:
# xb = random_shift(Xtr[i], rng, p_shift)     # fresh random shifts
# xb, Yb = mixup(xb, Yb, rng)                 # optional

Check your understanding

  1. You train a digit classifier and add a random 180 degree rotation to every training image, keeping each label. What is the most likely problem?

  2. Mixup blends a picture of a cat (label cat) and a picture of a dog (label dog) with λ=0.25\lambda=0.25, where λ\lambda weights the dog. What are the pixels and the label of the mixed example?

  3. A student makes 10 augmented copies of every image in a data set, and only then splits the data into training and validation sets at random. What goes wrong?

  4. On the 8 by 8 digits, a network trained with a random shift of every training image scored lower on the ordinary, centred test images than one trained with no shifts, but much higher on shifted test images. What explains it?

  5. Which is the right place to apply a random flip in a training pipeline?

Exercises

  1. Mixup with λ=0.4\lambda=0.4 blends image 1 (a pixel with value 0.50.5, label A) and image 2 (the same pixel with value 0.10.1, label B). What is the mixed pixel, and what is the label vector over the classes (A, B)?
    Show answerThe pixel is 0.6×0.5+0.4×0.1=0.340.6\times0.5+0.4\times0.1=0.34. The label is (0.6, 0.4)(0.6,\,0.4). The weights 1−λ=0.61-\lambda=0.6 and λ=0.4\lambda=0.4 are the same for the pixel and the label.
  2. A 32×3232\times32 image is padded by 4 pixels on each side and a 32×3232\times32 window is cut at a random place. How many different windows are possible? With a random flip as well, how many versions of one image?
    Show answerThe padded image is 40×4040\times40, so the window can start in 40−32+1=940-32+1=9 places in each direction: 9×9=819\times9=81 windows. With flip or no flip it is 2×81=1622\times81=162 versions.
  3. A data set has 50,000 images. You store 20 augmented copies of each, as 8-bit images of 32×32×332\times32\times3 pixels. How many images and how many megabytes (1 MB is 1,000,000 bytes)? Why does on-the-fly augmentation avoid this?
    Show answer50,000×20=1,000,00050{,}000\times20=1{,}000{,}000 images. Each has 32×32×3=307232\times32\times3=3072 bytes, so about 3072×1063072\times10^6 bytes, or about 3,072 MB (3.1 GB). On the fly, the copies are made when a batch is built and thrown away afterwards, so only the original 50,000 images are stored, and every epoch can draw new versions.
  4. CutMix pastes a 16×1616\times16 patch of image 2 into a 32×3232\times32 image 1. What is the mixed label if image 1 is “cat” and image 2 is “dog”?
    Show answerThe patch covers 16×16=25616\times16=256 of 32×32=102432\times32=1024 pixels, which is 0.250.25 of the picture. The label is 75 per cent cat and 25 per cent dog.
  5. A brightness change adds b=0.3b=0.3 to every pixel and the result is clipped to the range 0 to 1. What happens to a pixel of value 0.8, and to a pixel of value 0.1? Why does the clip matter for a bright image?
    Show answer0.8+0.3=1.10.8+0.3=1.1 is clipped to 11, and 0.1+0.3=0.40.1+0.3=0.4. Every bright pixel that would go above 1 ends at exactly 1, so bright areas flatten into pure white and the detail in them is lost. A strong brightness change can destroy the information in a bright image.
  6. For a data set of photos of street signs, explain why a random horizontal flip is risky, and give a case where it is safe.
    Show answerMany signs contain text, arrows or letters that change meaning when mirrored: a left-turn arrow becomes a right-turn arrow, so the label would be wrong. A flip is safe for a class whose picture does not depend on left or right, such as a circular sign with a symmetric symbol. In practice you check the classes one by one, or leave the flip out.

Next: P4.17 covers the other regularizers of neural networks (weight decay, dropout, early stopping), which work on the model and the loss instead of the data. P5.7 trains a CNN on CIFAR-10 with random crops and flips, and P4.22 shows how to tell whether a model is overfitting.

Key takeaways

  • Augmentation makes new training examples by changing the inputs in ways that should not change the label. It is a way of telling the model which changes to ignore: a shifted 6 is still a 6.
  • A transformation is safe only if a person would still give the same label. Flipping a 2 or a 5 gives a shape nobody writes, and turning a 6 by 180 degrees gives a 9. Which changes are safe depends on the data.
  • Common image changes are geometric (flip, crop with padding, small rotation or shift, scale) and photometric (brightness, contrast, colour, noise, blur). Cutout erases a square.
  • Mixup trains on (1−λ)x1+λx2(1-\lambda)\mathbf{x}_1+\lambda\mathbf{x}_2 with the labels mixed the same way, where λ\lambda is drawn from a Beta(α,α)(\alpha,\alpha) distribution. CutMix pastes a patch of one image into another and mixes the labels by area.
  • Augment the training images only, after the split, and draw fresh random changes every time an image is used. The random draws are seeded like any others.
  • Augmentation helps with variation that the test data really has. On the 8 by 8 digits, shifting every training image made centred test images worse and shifted ones much better, and the augmented runs needed more epochs.
Found a mistake? Tell us