Foundations to Frontier
Tests
E. Deep Learning › E4 Regularization Techniques (one page each)

Mixup

Mixup trains on convex blends of pairs of examples, x̃ = λxᵢ + (1 − λ)xⱼ, with the same blend of their labels, where λ is drawn from a Beta(α, α) distribution. It encourages the network to behave linearly between training examples, which smooths the decision boundary, improves calibration and robustness, and is a standard ingredient of modern image-classification recipes. This page covers the method, the role of α, its loss as a blend of two ordinary losses, its vicinal-risk interpretation and its variants. In the exercises you verify the loss identity and the shape of the Beta distribution, then train a small network on 100 points and find mixup cut the test cross-entropy threefold and the calibration error from 0.108 to about 0.04.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Train on blends of examples

Take two training examples, say a picture labelled “cat” and one labelled “dog”, and blend them: 70% of one picture plus 30% of the other, labelled “70% cat, 30% dog”. Mixup trains on such blends of random pairs. It sounds strange, since nobody photographs a cat-dog blend, but it teaches the network that between examples its answer should change gradually, not jump. That gives smoother decisions and much more honest confidence.

Regularisation lab: a small network on 40 noisy points
test cross-entropy during training
lowest test loss 0.214 at epoch 238
train accuracy 0.925 · test accuracy 0.907 · final test cross-entropy 0.231
With no regularisation the network fits all 40 noisy training points with a contorted boundary, and its test loss rises after an early minimum (the dot): overfitting. Each regulariser trades some training fit for a smoother boundary. Early stopping keeps the weights from the dot (here the test loss stands in for a validation set, which makes it look slightly better than it would in practice). Try the strength slider: too little does nothing, too much underfits. Results vary with the data, so press "new data" before trusting a comparison.
Why engineers care

Mixup and its cousin CutMix are part of almost every modern recipe for training image classifiers, including vision transformers. Better calibration matters for any system that acts on a model’s confidence, such as a robot deciding whether to trust a detection.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Mixup trains on…
  2. 2. A 70/30 blend of cat and dog is labelled…
  3. 3. Mixup notably improves…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Mix: λ ~ Beta(α, α); x̃ = λxᵢ + (1 − λ)xⱼ, ỹ = λyᵢ + (1 − λ)yⱼ (one-hot labels).
  • Example: x₁ = (0, 2), x₂ = (4, 0), y₁ = (1, 0), y₂ = (0, 1), λ = 0.75: x̃ = (1, 1.5), ỹ = (0.75, 0.25).
  • Loss: cross-entropy with a soft target is linear in the target, so CE(p, ỹ) = λ·CE(p, yᵢ) + (1 − λ)·CE(p, yⱼ). Example: losses 1 and 3 with λ = 0.25 give 2.5.
  • Role of α: Beta(α, α) has mean 0.5 and variance 1/(4(2α + 1)).
    • α = 1 gives a uniform λ (variance 1/12).
    • Small α (0.1–0.4) puts most λ near 0 or 1, so most mixed examples are close to a real one.
  • Typical values: α = 0.2 for ImageNet; up to 1 for small datasets.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Beta(1, 1) is…
  2. 2. Mixed loss for CE 1 and 3 at λ = 0.25:
  3. 3. Small α makes most mixed examples…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Mixup in code

Exercise 1.

  • The mixed batch equalled λxᵢ + (1 − λ)xⱼ with labels summing to 1.
  • The loss identity held exactly.
  • With α = 0.2, 67% of λ values lay within 0.1 of 0 or 1.

Practice.

  • Mix within the shuffled mini-batch (pair each example with another in the same batch), which costs almost nothing.
  • Use soft-target cross-entropy, or equivalently the blend of the two losses.
  • Some recipes switch mixup off for the last few epochs; many combine it with CutMix by choosing one of the two per batch (timm’s Mixup class).
  • Report accuracy on clean test data; mixup is a training-time transform only.
lam = np.random.beta(alpha, alpha); idx = torch.randperm(x.size(0))
x_mix = lam * x + (1 - lam) * x[idx]
loss = lam * F.cross_entropy(model(x_mix), y) + (1 - lam) * F.cross_entropy(model(x_mix), y[idx])
🐍 Exercise 1: the mixup identity
Implement mixup on a batch, check the loss identity, and examine Beta(α, α) for small α.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Mixup partners are usually taken from…
  2. 2. Typical ImageNet α:
  3. 3. Test accuracy with mixup is measured on…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Vicinal risk minimisation. Empirical risk puts all probability on the training points. Mixup replaces it with a “mixup vicinal distribution” over line segments between pairs (Zhang et al., 2018). The model is asked to fit the line segments, not just the endpoints.

Linear behaviour between examples. Fitting blended labels along a segment encourages the network’s outputs to change linearly between training points. That penalises sharp transitions and over-confident regions far from data.

A regularisation view. Expanding the mixup loss for small mixing shows it adds terms penalising the network’s input gradients and Hessian, a data-dependent smoothness penalty (Zhang, Deng et al., 2021; Carratino et al., 2022). It also relates to label smoothing: mixed targets are never one-hot.

Calibration. Thulasidasan et al. (2019) found mixup-trained networks are markedly better calibrated, mostly because of the soft targets; exercise 2 shows the same.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Mixup's vicinal distribution lives on…
  2. 2. Mixup encourages outputs to be…
  3. 3. Mixup's calibration gain comes mostly from…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Mixup on a small network

History.

  • H. Zhang, M. Cisse, Y. Dauphin and D. Lopez-Paz (2018) introduced mixup.
  • V. Verma et al. (2019) introduced Manifold Mixup, which mixes hidden representations.
  • S. Thulasidasan et al. (2019) studied mixup’s calibration.
  • S. Yun et al. (2019) introduced CutMix (E4-9); DeiT and later recipes combined both.

Exercise 2. A 2–64–64–2 ReLU network trained with Adam (2000 mini-batch steps) on 100 noisy two-moons points and tested on 2000. Means of three seeds:

mixup α test accuracy test cross-entropy ECE
none 0.864 1.036 0.108
0.2 0.869 0.331 0.036
1.0 0.882 0.308 0.042
  • Mixup cut the test cross-entropy about threefold and the expected calibration error from 0.108 to about 0.04.
  • Accuracy rose by about 2 points at α = 1; at α = 0.2 the change was within seed noise.
  • Lesson: mixup is a cheap way to get better probabilities, and a modest accuracy gain, from a small dataset.
🐍 Exercise 2 (research): mixup on a small network
Train a small network with no mixup and with mixup at α = 0.2 and 1, and compare accuracy, cross-entropy and calibration.

Mixup in AI, robotics and aerospace

  • Image classifiers for inspection and perception use mixup and CutMix in their training recipes.
  • Calibrated confidence for downstream decisions (when to hand control to a human, when to re-observe) benefits from mixup’s soft targets.
  • Small tabular and sensor datasets: mixup variants are used where natural augmentations are hard to define.

References

  1. H. Zhang, M. Cisse, Y. N. Dauphin, D. Lopez-Paz (2018). “mixup: beyond empirical risk minimization.” Proc. ICLR.
  2. V. Verma et al. (2019). “Manifold mixup: better representations by interpolating hidden states.” Proc. ICML.
  3. S. Thulasidasan, G. Chennupati, J. Bilmes, T. Bhattacharya, S. Michalak (2019). “On mixup training: improved calibration and predictive uncertainty for deep neural networks.” Advances in NeurIPS.
  4. L. Zhang, Z. Deng, K. Kawaguchi, A. Ghorbani, J. Zou (2021). “How does mixup help with robustness and generalization?” Proc. ICLR.