Skip to content
AI360Xpert
Beta

Mixup Augmentation

Blend two photos and blend their labels with the same weight. The model learns smooth transitions instead of memorizing sharp borders.

Mixup blends pixels with weight 0.7 and blends labels with the same 0.7, so 180 and 60 become 144 carrying label 0.7 and 0.3.
Mixup blends pixels with weight 0.7 and blends labels with the same 0.7, so 180 and 60 become 144 carrying label 0.7 and 0.3.

Why Does This Exist?

One hot labels claim every photo is fully one thing. Real decision borders are softer, and models trained on hard corners grow overconfident between them. A 0.51 dog still reports 0.99 dog, which breaks ranking and thresholding downstream.

Mixup builds the soft middle directly. Take two labeled photos, blend every pixel with weight λ\lambda, and train on the blended label with the same λ\lambda. The network must output 0.7 dog for a 0.7 blend, which smooths the border. It complements cutout, which erases instead of blending, and the family overview is image augmentation.

You need one idea first. A label can be a distribution, not a single spike. Mixup manufactures those distributions from pairs you already have.

Think of It Like This

Two paint cans poured together

Pour 70 percent white and 30 percent gray into one bucket and the result is light gray, honestly labeled 0.7 and 0.3. Nobody calls it pure white.

Mixup pours pixels the same way. The blended photo is 0.7 first class and 0.3 second, and the loss grades that exact claim. Where the analogy stops: paint mixes physically, while pixels blend numerically with no new scene behind them.

How It Actually Works

The blend rule

Draw λ\lambda from Beta(α,α)\text{Beta}(\alpha, \alpha) with α\alpha often 0.20.2 to 1.01.0. Given images xA,xBx_A, x_B and one hot labels yA,yBy_A, y_B:

x~=λxA+(1−λ)xB,y~=λyA+(1−λ)yB\tilde{x} = \lambda x_A + (1 - \lambda) x_B, \quad \tilde{y} = \lambda y_A + (1 - \lambda) y_B

Training minimizes cross entropy against y~\tilde{y}, which equals λ\lambda times the loss on AA plus (1−λ)(1 - \lambda) times the loss on BB. No box moves, because every pixel is a mix.

A worked pixel and label

λ=0.7\lambda = 0.7, pixel a=180a = 180, pixel b=60b = 60:

v~=0.7×180+0.3×60=126+18=144\tilde{v} = 0.7 \times 180 + 0.3 \times 60 = 126 + 18 = 144

Label [1,0][1, 0] and [0,1][0, 1] become [0.7,0.3][0.7, 0.3]. The model must report 70 percent first class on this ghost, which is the smoothing supervision hard labels never give.

Setting alpha

Small α\alpha near 0.20.2 keeps λ\lambda near 0 or 1, so blends stay readable. α=1.0\alpha = 1.0 samples λ\lambda uniformly and makes stronger ghosts. Start at 0.20.2 for small datasets and raise only if calibration stays poor.

Code

import numpy as np

def mixup_pair(a: np.ndarray, b: np.ndarray, lam: float) -> np.ndarray:    """Convex blend of two float images with weight lam."""    return lam * a + (1.0 - lam) * b  # same lam blends the labels

a = np.array([180.0])b = np.array([60.0])print(mixup_pair(a, b, 0.7).tolist())  # -> [144.0]

Watch Out For

Ghosts near one half confuse small objects

At λ\lambda near 0.50.5 neither class dominates, and a tiny bird blended half with sky becomes unlearnable noise with a confident 0.5 tag. The symptom is stalled tail accuracy while head classes smooth nicely. Keep α\alpha small or skip mixup on tiny object slices.

Applying mixup to boxes without a plan

Blended pixels carry two scenes, but one box file cannot hold both truths. Naively keeping box AA teaches box BB as background. Use mixup for classification first, and reach for CutMix with area labels when boxes matter.

The Quick Version

  • Mixup blends two images with weight lambda and blends their labels with the same lambda.
  • A 0.7 blend of 180 and 60 gives pixel 144 with label 0.7 and 0.3.
  • Lambda comes from a Beta distribution, often with alpha 0.2 for gentle blends.
  • Keep alpha small on tiny objects and avoid mixup where boxes need exact labels.