Data Augmentation
Data augmentation enlarges a training set by transforming each input in ways that leave its label unchanged. Its aim is to make the model indifferent to those transformations. The transformations are drawn at random every time an example is used, so the network rarely sees exactly the same input twice. Common transformations depend on the data:
- Images, geometric: crops and translations, horizontal flips, rotations, shears.
- Images, photometric: brightness, contrast, color, sharpness, posterize, solarize, equalize, autocontrast. Added noise and blur are also common.
- Text: words can be replaced by synonyms, or a sentence translated to another language and back.
- Audio: frequency bands can be amplified or attenuated.
Masking and mixing methods change images more strongly:
- Cutout masks a square region of the image and keeps the label.
- Mixup blends two images and their one-hot labels with the same weight .
- CutMix pastes a rectangle from one image into another and mixes the labels in proportion to the area of each.
- PixMix mixes an image with pattern images such as fractals and keeps the original label. It mixes over several rounds and picks additive or multiplicative mixing at random in each round.
For Mixup the mixed input and target are
Beyond accuracy on the test set, these methods aim at robustness to image corruptions and to shifts in the data distribution.AlexNet enlarged its training set by a factor of with random crops and mirror flips, and it also changed pixel intensities. At test time it averaged its predictions over several cropped and mirrored versions of each image, which is called test-time augmentation. Dropout can be read as augmentation applied to the hidden units instead of the input.
Not Taught in Lecture
Lecture showed Cutout, Mixup, CutMix and PixMix as example images. The formulas for Mixup and the label rule for CutMix come from the original papers (Zhang et al., 2018; Yun et al., 2019).
Intuition
A model should give the same answer for a photo of a bird and for the same photo flipped, slightly rotated, or taken in dimmer light. A network cannot know this unless its architecture or its data say so. A convolutional layer builds in one such fact, that a pattern means the same thing anywhere in the image. Most other facts cannot be built in so easily. Augmentation teaches them through the data: show the network the flipped bird with the label “bird” often enough, and it learns that flipping does not matter. Each transformation is a statement about the task. A useful augmentation is one that is true of the task and is not already guaranteed by the architecture.
Properties
(Augmentation Versus Architecture) Augmentation and architecture are two routes to the same invariances, and augmentation covers the ones the architecture does not.
Weight sharing makes a convolution equivariant to translation, and pooling adds partial invariance. Nothing in a standard CNN makes it invariant to rotation, scale, color or lighting. A network learns these only from examples, so augmentation supplies the examples. Built-in invariance is exact and costs no data, while learned invariance is approximate and holds only for the range of transformations seen in training. Translations are still often augmented, because pooling and strides make CNNs only approximately invariant to them.
(Label Preservation Is Task-Specific) A transformation is a valid augmentation only if it leaves the correct label unchanged for this particular task.
Horizontal flips are safe for photos of animals but not for handwritten text, where a flipped letter may become another letter or no letter at all. Rotating a digit by turns a into a . Color changes are harmful when color is the label, as for ripe and unripe fruit. A random crop can cut away the object that the label names. An augmentation that changes the true label teaches the network something false. The safe set of transformations must therefore be chosen from knowledge of the task, not from a fixed list.
(Mixing Produces Soft Labels) Mixup and CutMix train on targets that spread probability over several classes, which discourages overconfident predictions.
A Mixup example with has a target that puts on one class and on another. The cross-entropy loss is smallest when the predicted probabilities match these values, not when one class gets probability . The network is pushed to change its predictions gradually between examples instead of jumping from one confident answer to another. CutMix keeps every pixel realistic, since each region comes from a real image, while Mixup produces ghostly blends. Cutout, by contrast, keeps the original label and forces the network to classify from the parts of the object that remain.
(Test-Time Augmentation) Averaging the predictions for several transformed copies of a test image makes the final prediction more stable.
Each copy gives a slightly different prediction, because the learned invariance is only approximate. Averaging them cancels part of this variation, much as an ensemble of models does. The cost is one forward pass per copy. The transformations used at test time should be ones used in training, since the network has learned to handle only those.
Examples
(Easy) Where AlexNet's Factor of 2048 Comes From
AlexNet trained on crops taken from images, together with their horizontal mirror images.
How many distinct training inputs can one image produce this way? offsets along each axis, about positions in all. The original paper counts offsets per axis, which gives positions. Each crop can also be mirrored, so one image yields inputs. The intensity changes come on top of this and are continuous, so they add further variety. Neighboring crops overlap almost completely, so the inputs are far less informative than new photographs. They still teach the network that a shift of a few pixels or a mirror flip does not change the class.
The crop can start at
(Medium) A Mixup Training Loss
Mixup combines an image of a cat (class ) and an image of a dog (class ) with . The network predicts the probabilities for the two classes.
Compute the mixed target and the cross-entropy loss. Which prediction would minimize the loss? . The cross-entropy is The loss is minimized when the prediction equals the target, , where it equals the entropy of the target, about . A prediction of would give infinite loss, because it assigns zero probability to a class with weight in the target.
The target is
(Medium) Choosing Augmentations
Three tasks are considered: classifying handwritten digits, classifying traffic signs, and classifying land cover in satellite images taken from directly overhead.
Which of horizontal flips, rotations, small rotations and color jitter are safe for each task? For digits, small rotations are safe. Horizontal flips and rotations are not, since they can turn one digit into another, such as into , or into a non-digit. Color jitter rarely matters for grayscale digits. For traffic signs, small rotations and mild brightness changes are safe. Flips are not, since they reverse arrows and text, and strong color changes are not either, since color is part of a sign's meaning. For overhead satellite images, flips and rotations by any angle are safe, because the ground has no preferred orientation. Color jitter must stay mild if the land-cover classes differ mainly in color, such as crops and bare soil.
See Also
- 4.4. Neural Network Regularization, for the other regularizers.
- 4.4.1. Dropout, augmentation applied inside the network.
- 5.2.1b. Equivariance and Invariance, for the translation equivariance that the architecture provides.
- 5.2.4. CNNs, for AlexNet and its training.