MixUp reduces overfitting by changing both the training inputs and loss instead of penalizing network weights. It blends two inputs with a random λ between 0 and 1, encouraging proportional predictions rather than overconfident class scores. section 14.3 section 14.5
Implement MixUp by treating a shuffled batch as its paired batch:
- Sample λ from Beta(α, α), where α controls mixing strength. section 14.3.2
- Shuffle a batch with torch.randperm(B), then compute x̃ = λx + (1 − λ)x[permutation]. section 14.3.2
- Keep both label tensors and calculate λℓ(ŷ, yi) + (1 − λ)ℓ(ŷ, yj). section 14.3.2
- Place mixing in a DataLoader collate function and wrap the ordinary loss; the optimizer and scheduler can remain unchanged. section 14.3.2
PyTorch training setup
Use DataLoader(..., collate_fn=MixupCollator()), then train with MixupLoss(loss). A collator samples λ, applies torch.randperm, mixes inputs, and returns the original and shuffled labels. section 14.3.2
Figure 14.7 With MixUp, there is not the same incentive to overpredict. Instead, the model tries to reach a target percentage based on how much of two different classes was selected. MixUp mixes the labels and the inputs so there is a signal for each class proportional to the MixUp percentage λ.
Shows how MixUp changes the target from an overconfident single-class prediction to percentages proportional to λ. section 14.3
