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.
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.
- 1. Mixup trains on…
- 2. A 70/30 blend of cat and dog is labelled…
- 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.
- 1. Beta(1, 1) is…
- 2. Mixed loss for CE 1 and 3 at λ = 0.25:
- 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])- 1. Mixup partners are usually taken from…
- 2. Typical ImageNet α:
- 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.
- 1. Mixup's vicinal distribution lives on…
- 2. Mixup encourages outputs to be…
- 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.
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
- H. Zhang, M. Cisse, Y. N. Dauphin, D. Lopez-Paz (2018). “mixup: beyond empirical risk minimization.” Proc. ICLR.
- V. Verma et al. (2019). “Manifold mixup: better representations by interpolating hidden states.” Proc. ICML.
- 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.
- L. Zhang, Z. Deng, K. Kawaguchi, A. Ghorbani, J. Zou (2021). “How does mixup help with robustness and generalization?” Proc. ICLR.