TL;DR
A model learns from a finite set of examples, and it can memorise the particular examples it was given. Data augmentation fights this by creating extra examples from the ones you already have. You take an image, flip it, crop it, or change its brightness, and the result is a new training example with the same label. The model sees more variety for free.
Augmentation is a cheap way to get more data without collecting or labelling anything new. It only works when the transformation really keeps the label. A rotated photo of a cat is still a cat. A rotated "6" is a "9".
Where you'll see it: in nearly every image classifier trained from a modest dataset, in speech recognition where audio gets speed and noise changes, and in the training pipeline of the U-Net style segmentation models.
Intuition
More views of the same thing
Think of a student preparing for an exam. If they only practise with last year's paper, they may learn its exact wording. If they practise with the same questions reworded, turned around, and given with different numbers, they learn the subject. Augmentation is the second kind of practice for a model.
A photo of a dog is still a dog when it is mirrored left to right. It is still a dog when it is a little brighter, a little zoomed in, or cropped so the ears are cut off. None of those changes alter the answer, but each one changes every pixel. The model cannot memorise the exact pixels of one photo if it keeps seeing new arrangements of them.
This is why augmentation is a form of Overfitting control. A model that memorises its training set has a large gap between training and test error. Augmentation makes the training set harder to memorise, so the gap shrinks.
flowchart LR A["Training image (label: cat)"] --> B["Random transform t"] B --> C["Augmented image t(x), label still cat"] C --> D["Model prediction"] D --> E["Loss against the cat label"] E --> F["Gradient step"]
A plot of what it buys
Suppose you train on different amounts of data and measure error on new images. Without augmentation, error falls as the training set grows. With augmentation, the same curve sits lower, and the gain is largest when data is scarce.
- no augmentation
- with augmentation
The math
Setting up the objective
Let be a training example, where is the input (an image) and is its label. Let be a transformation, such as a flip or a crop, and let be a distribution over transformations we choose from.
An augmentation is label-preserving when the label of the transformed input is the same as the original label:
Let be the model with parameters , and let be the loss, for example Cross-Entropy Loss. Ordinary training minimises the average loss over the original examples:
With augmentation, each example is replaced by its expected loss over the transformations:
In practice the expectation is estimated by sampling. Each time an example is used in a training step, a fresh is drawn, so over many epochs the model sees many different versions of it.
Counting the examples
If each image gets random augmentations, a dataset of images gives examples per epoch, counting the originals. The number of possible views can be much larger than this, because the transformations combine. Two simple parts multiply:
Why it helps
Augmentation is a regulariser. It adds the belief that the label should not change under the transformations we chose. The model is pushed to give the same output for and for , which removes some of the freedom it had to fit accidental details. For small transformations this behaves roughly like a penalty on how much the output moves when the input is nudged, which is the same idea behind lowering variance by constraining a model.
Choosing transformations
Each transformation encodes a claim about what should not matter. Choose claims that are true for your task.
| Transformation | Keeps the label for | Breaks the label for |
|---|---|---|
| Horizontal flip | Objects, animals, scenes | Text, left and right hand gestures |
| Random crop | Objects that stay mostly in frame | Crops that remove the object |
| Small rotation | Most natural photos | Digits such as 6 and 9, letters such as b and d |
| Brightness or colour jitter | Most natural photos | Tasks where colour is the label, such as ripeness |
| Added noise | Tasks robust to noise | Tasks where fine detail is the label |
Worked examples
Take a 3 by 3 greyscale image, written as rows of pixel values:
- Original: rows , , .
- Horizontal flip reverses each row, so row one becomes .
- Row two becomes , and row three becomes .
- The flipped image is , , .
- Every pixel value is still present, but every position has moved. A network that saw only the original has never seen this arrangement.
- If the label is "cat", the flipped image is still labelled "cat". Training on both gives two examples from one.
Interpretation: a single transformation doubles the number of distinct training arrays, at zero labelling cost, as long as the label is unchanged.
Many image models are trained on images. A common recipe pads each image with 4 pixels of zeros on every side, making a image, and then takes random crops.
- A window can start at any row from 0 to 8 in the padded image, which is positions.
- The same holds for columns, giving 9 positions.
- The number of distinct crops is .
- Adding a random horizontal flip doubles this: possible views per image.
- A dataset of 50,000 images then has possible views.
- Each epoch the model sees one random view of each image, so successive epochs show it different versions of the same picture.
Interpretation: the augmentation does not add information about the image, but it multiplies the number of configurations the model could memorise, which makes memorising the exact training set much harder.
Tradeoffs and failure modes
Augmentation is cheap and usually helps, but it has real costs.
- Label changes. If the transformation changes the true answer, you teach the model the wrong thing. A rotated 6 labelled as 6 is noise.
- Distribution mismatch. If training images are flipped and test images never are, the model spends capacity on views it will never meet. Augmentation should match the variation you expect at test time.
- Tasks with fixed geometry. Medical scans, satellite images, and documents often have a meaningful orientation. Heavy geometric changes can destroy the signal.
- Segmentation needs care. The mask must receive exactly the same geometric transform as the image. Colour changes only touch the image.
- Too much is worse. Very strong augmentation can make training slow and underfit the data, which is the opposite of the goal.
| Situation | Problem | Better choice |
|---|---|---|
| Small image dataset, natural photos | Overfitting | Flips, crops, colour jitter |
| Digits or letters | Rotation flips the meaning | Small shifts and noise only |
| Already huge dataset | Little gain, longer training | Light or no augmentation |
| Fixed-orientation scans | Geometry carries signal | Intensity changes, small elastic warps |
| Learning the policy itself | Hand-tuning is slow | Search for policies, such as AutoAugment |
History
The idea is old. In the early 2000s, Simard, Steinkraus, and Platt (2003) showed that applying small elastic distortions to handwritten digits made a neural network generalise better. Elastic deformation, which bends an image smoothly while keeping its shape, is still one of the augmentations listed in the aliases of this lesson.
It became standard practice with the 2012 AlexNet paper, which trained a large convolutional network on ImageNet and reduced overfitting by using random crops, horizontal reflections, and changes to the colour intensities of the image. Those choices were part of why the network generalised well, and most image pipelines since have used a similar set.
Later work asked which augmentations to use. AutoAugment, in 2018, used a search procedure to find augmentation policies from data rather than by hand. Surveys in 2019 collected the many variants that had appeared, and the field now treats augmentation as a standard part of training rather than an extra trick.
Check yourself
QuestionWhy is a horizontal flip a good augmentation for photos of cats but a poor one for the digit 2 written in a handwriting dataset?Show answer
A cat mirrored left to right is still a cat, so the label is preserved. A mirrored 2 looks like a different shape and is not a clean example of the digit 2. The question to ask is whether the transformation keeps the label, not whether it produces a new image.
QuestionA dataset has 10,000 images and each is given 3 random augmentations. How many examples are there per epoch if the originals are kept?Show answer
There are examples per epoch. The originals are kept, so each image contributes itself plus three augmented copies.
QuestionAn image is padded by 2 pixels on each side and then cropped to its original size. How many distinct crop positions are there along each axis, and in total?Show answer
Along one axis the crop can start at offsets 0 to 4, which is positions, using with . In total there are distinct crop positions.
QuestionWhy can augmentation help even though it adds no new real images?Show answer
It multiplies the number of distinct inputs the model sees while keeping the labels, so memorising the exact training pixels becomes harder. The model is pushed to learn the features that survive the transformations, which is the same thing a better model of the underlying rule would do. This is a form of regularisation, and it narrows the gap between training and test error.