Mixup, CutMix & Vicinal Risk
Training on blends of examples, and what it does to boundaries and calibration.
Mixup trains on images that never existed: weighted averages of two training images, labeled with the same weighted average of their labels. It is a two-line change to a training loop, and it often improves accuracy, calibration and robustness. Why should training on blends help? This lesson derives what mixup actually optimizes: label-smoothed risk on data shrunk toward its mean, plus a data-dependent penalty on input gradients, a penalty that, surprisingly, does nothing at all for linear least squares with an intercept.
What you’ll learn
- Define vicinal risk minimization, derive mixup and CutMix as vicinal distributions, and show that the mixed cross-entropy equals cross-entropy with the soft label.
- Prove that mixup's risk is empirical risk on mean-shrunk, label-smoothed data plus zero-mean perturbations (Carratino et al., 2022), and compute the implied label smoothing for a given .
- State the second-order expansion of the mixup loss (Zhang et al., 2021), and prove that mixup leaves linear least squares with an intercept unchanged.
- Explain mixup's effects on calibration and decision boundaries, manifold mixup and manifold intrusion, and what CutMix changes.
Vicinal risk minimization
Empirical risk minimization trusts the training points exactly: it puts all probability on the observed pairs. Chapelle, Weston, Bottou and Vapnik (2001) proposed instead to spread each training example into a vicinity distribution and minimize the vicinal risk:
Mixup (Zhang, Cisse, Dauphin & Lopez-Paz, 2018) builds the vicinity from pairs of examples. Draw (a mixing weight, unrelated to weight decay) and a partner uniformly at random, and train on
import numpy as np
import torch
import torch.nn.functional as F
def mixup_loss(model, x, y, alpha=0.2):
lam = float(np.random.beta(alpha, alpha))
perm = torch.randperm(x.size(0)) # pair each example with another in the batch
logits = model(lam * x + (1 - lam) * x[perm])
# cross-entropy is linear in the target, so this IS cross-entropy with the soft label
return lam * F.cross_entropy(logits, y) + (1 - lam) * F.cross_entropy(logits, y[perm])Pairs are formed within the mini-batch, with one per batch, as Zhang et al. suggested. The last line uses : no soft-label tensor is ever built.
Mixup is label-smoothed, perturbed ERM
The mixup risk averages over ordered pairs and . The Beta distribution is symmetric about , so the half of the mass with becomes the other half after renaming and swapping . Hence one may always put the larger weight on the first example:
Add and subtract to split each mixed input into its shrunk version and the rest; the identity is exact:
Since and are independent, and , the perturbation has mean zero; the labels work identically:
Read off the consequences. With one-hot labels and balanced classes, , so the shrunk target is : label smoothing with . The inputs are shrunk toward the data mean by the same factor, so Carratino et al. recommend applying to test inputs too, and undoing the label shrinkage on the outputs, a one-line change they found improves both accuracy and calibration. On top of that sit the zero-mean perturbations, correlated between input and label, which they show act as further regularizers, among them a reduction of the estimator's Lipschitz constant.
With , is uniform on , so is uniform on . What label-smoothing strength does mixup imply for balanced classes?
Show the answer
0.25
, so : much stronger than the typical of explicit label smoothing. Smaller smooths less: numerically, for and for , i.e. and .
A second-order view, and a surprise
Take with squared loss and residuals . Because is affine and inputs and labels are mixed with the same weight, the mixed residual is exactly the mix of residuals:
Average over independent uniform and , using with , and write and for the mean and variance of the residuals over the training set:
The intercept can make without changing , which depends on only, so the minimizer is the ordinary least-squares solution: mixup merely rescales the objective, as a direct numerical check on simulated data confirms. In the expansion above, collapse to plus a constant. Mixup's regularization must therefore come from a curved loss ( varying, as for cross-entropy) or a nonlinear , not from the blending of inputs as such.
You fit a linear regression with an intercept by minimizing the mixup loss with instead of the ordinary squared loss. How does the fitted slope compare with ordinary least squares?
- It is shrunk toward zero, as in ridge regression
- It is shrunk by the factor
- It depends on which pairs happened to be mixed
- It is exactly the least-squares slope
Show the answer
D. It is exactly the least-squares slope
The mixup loss equals , minimized by the least-squares slope with the intercept setting . Shrinking inputs and labels by the same factor leaves a regression slope unchanged.
Boundaries, calibration and representations
Zhang et al. (2018) described mixup as encouraging the model "to behave linearly in-between training examples": predictions along a segment between two training points are pulled toward the straight-line blend of their labels, which smooths decision boundaries and lowers confidence away from the data.
Calibration. Thulasidasan et al. (2019) found networks trained with mixup significantly better calibrated than standard training, on benchmarks up to ImageNet, and less prone to confident predictions on out-of-distribution and random-noise inputs. Their ablations point at the labels: mixing the inputs while keeping hard labels did not give the same benefit, so the label smoothing inside mixup, which the Carratino decomposition makes explicit, plays a significant role.
Manifold mixup (Verma et al., 2019) mixes hidden representations at a randomly chosen layer instead of raw inputs. In their experiments it flattened class representations and smoothed boundaries further, and improved generalization and robustness to single-step adversarial attacks over input mixup, Cutout and dropout.
Manifold intrusion (Guo, Mao & Zhang, 2019) is the failure mode. A blend of two examples can land on, or very near, a real example of a third class, yet it carries a soft label that contradicts that example. Such conflicts over-regularize and cause underfitting; their AdaMixUp learns the mixing policy to avoid them. It is one reason a moderate usually works best.
Thulasidasan et al. (2019) found mixup-trained networks better calibrated. Their ablation mixed the inputs but kept hard (one-hot) labels. What did it show?
- Mixing inputs alone gave the full calibration benefit
- Mixing inputs alone did not give the same benefit: the soft, smoothed labels matter
- Calibration got worse with mixup in every setting
- Calibration depends only on the network architecture
Show the answer
B. Mixing inputs alone did not give the same benefit: the soft, smoothed labels matter
Without label mixing the calibration gains largely disappeared. That fits the decomposition: mixup includes label smoothing toward the mean label, and smoothed targets discourage overconfident logits.
CutMix, and mixing in practice
CutMix (Yun et al., 2019) mixes by cutting and pasting: a rectangle from replaces the same region of , and the label is mixed in proportion to area. With a binary mask that is inside the box:
CutMix pastes a -pixel patch of a cat image into a dog image. What weight does the cat label get in the soft target?
Show the answer
0.1875
The patch covers of the pixels, so the cat gets and the dog . The weight follows the area, whether or not the patch happens to contain much of the cat, a known weakness that later variants try to fix by weighting with saliency. Clipping has a second, quieter effect: since the box center is uniform and boxes near the border are cut off, the pasted area is on average smaller than , and the source keeps about two thirds of the label rather than half (a Monte Carlo estimate in the continuous square gives 68%).
In practice the two are combined. DeiT trained vision transformers on ImageNet alone with a recipe that included RandAugment, mixup, CutMix and random erasing among its regularizers (Touvron et al., 2021). Mixing is most established for classification; for regression, structured outputs or text, what a "blend" of two examples means is less obvious, and mixing is usually done on embeddings or hidden states, if at all.
Key takeaways
- Mixup is vicinal risk minimization with , , ; because cross-entropy is linear in the target, the mixed loss is the -weighted sum of two ordinary losses.
- Mixup's risk equals ERM on data shrunk toward the mean by , , plus zero-mean perturbations: label smoothing with ( at ) and input noise (Carratino et al., 2022).
- To second order, mixup adds curvature-weighted penalties on input gradients and Hessians (Zhang et al., 2021); for linear least squares with an intercept it changes nothing, so its effect comes from curved losses and nonlinear models.
- Mixup tends to improve calibration, largely through its soft labels (Thulasidasan et al., 2019); manifold mixup mixes hidden states, and manifold intrusion, blends colliding with real examples of other classes, can cause underfitting.
- CutMix pastes a box and weights the labels by area; modern image recipes such as DeiT's combine it with mixup, RandAugment and random erasing.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
What happens to mixup as ?
- concentrates on and , and mixup reduces to ordinary empirical risk minimization
- concentrates near , so every example is an even blend
- The labels become uniform over the classes
- Mixup becomes equivalent to adding Gaussian input noise
Show the answer
A. concentrates on and , and mixup reduces to ordinary empirical risk minimization
with small is U-shaped and piles its mass at the endpoints, so each "mixed" example is almost exactly one training example with its own label.
According to Carratino et al. (2022), mixup with balanced one-hot labels trains on which targets, before the zero-mean perturbations?
- The original one-hot targets
- Uniform targets
- Smoothed targets , with the mean of
- Targets drawn at random from the training labels
Show the answer
C. Smoothed targets , with the mean of
Shrinking every label toward the label mean by is label smoothing with ; for , .
What is "manifold intrusion" in mixup?
- Mixed examples that lie far from every training example
- Hidden representations collapsing onto a low-dimensional manifold
- Mixed examples leaking from the training set into the test set
- A blend of two examples that lands on or near a real example of another class, while carrying a soft label that contradicts it
Show the answer
D. A blend of two examples that lands on or near a real example of another class, while carrying a soft label that contradicts it
Guo, Mao and Zhang (2019) showed that such conflicting labels over-regularize and can cause underfitting, and proposed learning the mixing policy to avoid them.
How does CutMix differ from Cutout?
- CutMix fills the removed region with a patch from another image and mixes the labels by area; Cutout blanks the region and keeps the label
- CutMix blends all pixels of two images; Cutout blends only a rectangle
- They are the same method under two names
- CutMix keeps the original label; Cutout mixes the labels
Show the answer
A. CutMix fills the removed region with a patch from another image and mixes the labels by area; Cutout blanks the region and keeps the label
Both remove a rectangle of the image. Cutout leaves a blank, so those pixels carry no information; CutMix fills them with another training image and makes the label say so, in proportion to the area.
Further reading
- H. Zhang, M. Cisse, Y. N. Dauphin & D. Lopez-Paz, "mixup: beyond empirical risk minimization," ICLR (2018).
- O. Chapelle, J. Weston, L. Bottou & V. Vapnik, "Vicinal risk minimization," NeurIPS (2000; proceedings 2001).
- L. Carratino, M. Cissé, R. Jenatton & J.-P. Vert, "On mixup regularization," Journal of Machine Learning Research 23 (2022).
- L. Zhang, Z. Deng, K. Kawaguchi, A. Ghorbani & J. Zou, "How does mixup help with robustness and generalization?," ICLR (2021).
- S. Thulasidasan, G. Chennupati, J. Bilmes, T. Bhattacharya & S. Michalak, "On mixup training: improved calibration and predictive uncertainty for deep neural networks," NeurIPS (2019).
- S. Yun, D. Han, S. J. Oh, S. Chun, J. Choe & Y. Yoo, "CutMix: regularization strategy to train strong classifiers with localizable features," ICCV (2019).