MixUp
MixUp blends training examples and their targets to reduce overfitting. It creates soft class labels for classification and keeps boxes for detection.
MixUp is a data augmentation technique that blends two training examples into one and combines their targets. In image classification, the same ratio controls both blends: if one image contributes 70% of the pixel blend, its class gets 70% of the target weight. Training on these in-between examples encourages the model's predictions to change gradually between samples.
How MixUp Works#
Standard MixUp draws a weight between zero and one from a symmetric Beta distribution parameterized by alpha. Below 1, draws favor the endpoints, so one image typically dominates. At 1, intervals of equal width are equally likely. Above 1, draws concentrate near 0.5, producing more even blends. The mixing ratio determines how much each sample contributes; a separate application probability, when available, determines how often the transform runs.
Hongyi Zhang, Moustapha Cissé, Yann N. Dauphin, and David Lopez-Paz introduced the technique in mixup: Beyond Empirical Risk Minimization, first posted in 2017 and presented at ICLR 2018. In their 200-epoch CIFAR-10 experiment with a pre-activation ResNet-18 and weight decay of 0.0001, MixUp with alpha=1 reduced the median test error over the final 10 epochs from 5.53% to 4.24%.
MixUp for Image Classification#
An image classification label is often stored as an integer class ID. MixUp combines class vectors instead: when the images come from different classes, the result is a soft target with two weights that sum to one. When both images belong to the same class, that class keeps its full weight. With cross-entropy loss, using the soft target is equivalent to computing the loss against each original label from the same blended-image prediction, then taking a weighted sum of the two losses.
Torchvision's batch MixUp transform applies a shared mixing weight across a batch. The example uses the cat and coffee images from scikit-image's sample collection.
import torch
from skimage import data
from torchvision.transforms import v2
resize = v2.Resize((128, 128))
to_image = v2.ToImage()
cat = resize(to_image(data.chelsea()))
coffee = resize(to_image(data.coffee()))
images = torch.stack((cat, coffee)).float() / 255
labels = torch.tensor([0, 1])
mixup = v2.MixUp(alpha=1.0, num_classes=2)
mixed_images, mixed_targets = mixup(images, labels)
print(mixed_targets)Each printed row shows the cat and coffee weights for one blended image. The weights swap between rows because the transform reverses the roles of the two images in this batch.
How Object Detection Handles Mixed Labels#
An object detection target contains a bounding box and a class for each object. Averaging two boxes could put the resulting box between the objects. Ultralytics YOLO's MixUp transform blends the images while keeping both sets of boxes and class IDs as separate targets. The mixup setting controls how often the transform runs and defaults to 0.0; the pixel ratio is sampled separately from Beta(32, 32), yielding near-even blends, and the close_mosaic training cutoff also switches MixUp off when it takes effect.
How MixUp Compares With Other Augmentations#
MixUp acts as regularization by training the model on combinations of examples it could otherwise memorize. Full-image blending can also create patterns that resemble a third class. In one MNIST experiment, a blend of handwritten digits 1 and 5 resembled an 8, even though the target assigned 53% to 1 and 47% to 5. The image thus provided visual evidence for a class that received zero target weight.
- CutMix replaces a rectangular region with a patch from another image. In classification, the target weights follow the area each image contributes.
- Mosaic arranges multiple images on a single canvas and remaps their annotations to the new layout.
- Label smoothing redistributes some target weight across classes while leaving the input unchanged.
Manifold Mixup moves the interpolation from the raw inputs to a hidden layer of the network. It still uses the same mixing weight for the hidden activations and the class targets.














