One training step of MixMatch proceeds in the following order, as in Algorithm 1 of the paper. The same number B of labeled and unlabeled images is drawn.
- Apply augmentation (horizontal flip and crop) once to each labeled image xb to obtain x^b.
- Apply augmentation K times (K=2 in the paper) to each unlabeled image ub to obtain u^b,1,…,u^b,K.
- Pass each u^b,k through the model and compute the average prediction qˉb.
- Sharpen qˉb with temperature T (0.5 in the paper) to obtain the guessed label qb. No gradient flows through the guessed label.
- Gather all augmented labeled pairs (x^b,pb) and unlabeled pairs (u^b,k,qb), shuffle them, and form the pool of mixing partners W.
- Mix the labeled pairs and the unlabeled pairs each with examples from W using MixUp to form X′ and U′.
- Compute the cross-entropy on X′ and the squared error on U′, and add them with a weight.
Steps 3 and 4 are given by the following equations (Eqs. (6)(7)).
qˉb=K1k=1∑Kpmodel(y∣u^b,k;θ),Sharpen(p,T)i=∑j=1Lpj1/Tpi1/T
L is the number of classes. As T approaches 0, the guessed label approaches a one-hot vector.
The MixUp in step 6 mixes two examples (x1,p1) and (x2,p2) as follows (Eqs. (8)–(11)).
λ∼Beta(α,α),λ′=max(λ,1−λ),x′=λ′x1+(1−λ′)x2,p′=λ′p1+(1−λ′)p2
Unlike standard MixUp, λ′=max(λ,1−λ) ensures that the mixed result always stays closer to x1. This way, after mixing, labeled examples can still be handled by the labeled loss and unlabeled examples by the unlabeled loss.
Finally, the loss in step 7 is as follows (Eqs. (3)–(5)).
LX=∣X′∣1x,p∈X′∑H(p, pmodel(y∣x;θ)),LU=L∣U′∣1u,q∈U′∑∥q−pmodel(y∣u;θ)∥22,L=LX+λULU
H is the cross-entropy, and λU is the weight of the unlabeled loss, which is raised linearly from 0 over the first 16,000 steps.
According to the paper, the unlabeled loss uses squared error (MSE) rather than cross-entropy because it is bounded and less sensitive to completely wrong predictions. Guessed labels are uncertain targets built from the model's own predictions, so a loss that does not blow up when they are wrong is helpful.