TL;DR
FixMatch is a semi-supervised image classifier, published at NeurIPS 2020, that learns from unlabeled images by combining two older ideas: Pseudo-Labeling, where the model's own confident prediction becomes a training label, and Consistency Regularization, where the model must give the same answer under different distortions of one image. It uses a light augmentation to make the label and a heavy augmentation to make the prediction it is trained on. The paper shows that this simple recipe beats more complicated methods on most standard benchmarks, with 94.93% accuracy on CIFAR-10 using 250 labeled images.
Builds on: Consistency Regularization, Pseudo-Labeling · Leads to: the family of weak-to-strong consistency methods, where a strong augmentation such as Mixup can replace the one FixMatch uses.
Why it mattered
The paper's claim is that a method can be simpler and more accurate at the same time. Before FixMatch, the strongest semi-supervised image methods, such as MixMatch, UDA and ReMixMatch, stacked several loss terms, sharpening steps, annealed weights and extra self-supervised objectives. FixMatch keeps only two terms, both standard Cross-Entropy Loss, and reports better numbers on most benchmarks. That is why the paper is useful to a beginner: the whole training objective fits in a few lines of code, and every piece can be tested.
The setting also matters. Labels for images often need experts. The paper's broader-impact section mentions medical scans, where an expert's time is expensive and unlabeled scans are cheap. Results with 40 labels (4 per class on CIFAR-10) show how far the method can push that idea, and the paper is open about where it still fails: with one label per class, accuracy varies a lot with which image is chosen.
The problem
Deep networks learn well from large labeled datasets, but labels cost money and expert time. Unlabeled data is cheap, so semi-supervised learning tries to use it. Before FixMatch, the two most successful families were:
- Pseudo-labeling (see Pseudo-Labeling): train on the model's own hard guesses for unlabeled inputs, keeping only confident ones. Simple, but on its own it was not competitive with newer methods.
- Consistency regularization (see Consistency Regularization): the model should give similar predictions to two random perturbations of the same image. Strong perturbations work best, but the methods that used them had many moving parts.
The question was whether the two ideas could be combined without that extra machinery, and whether the simple version would stay accurate once the many hyperparameters of earlier work were examined carefully.
How it works
The algorithm runs on each training step. A labeled batch and an unlabeled batch are drawn, and the loss has two parts. The labeled part is ordinary supervised training. The unlabeled part is where FixMatch differs.
flowchart LR U[Unlabeled image] --> W[Weak augmentation: flip and shift] W --> P[Model predicts class probabilities] P --> C[Keep only if top probability is at least 0.95] C --> L[Pseudo-label: the top class as a one-hot target] U --> S[Strong augmentation: RandAugment or CTAugment, then Cutout] S --> Q[Model predicts on the strong copy] L --> H[Cross-entropy: strong prediction against pseudo-label] Q --> H
Here is one tiny instance traced through. The classes are cat, dog and bird. For readability the threshold is set to 0.9 instead of the paper's 0.95; the logic is the same.
- Take an unlabeled photo and make a light copy. The light copy is a horizontal flip and a small shift. Call the original and the light copy . Nothing about the content changes, only the pixel layout. Check: the flipped photo still shows the same animal.
- Ask the model for probabilities on the light copy. Suppose it returns cat 0.93, dog 0.05, bird 0.02. These are the model's current beliefs. Check: the three numbers add up to 1.
- Decide whether the guess is confident enough. The top probability is 0.93, which is at least 0.9, so the guess is kept. The pseudo-label becomes the one-hot target cat. Check: a guess of cat 0.50, dog 0.30, bird 0.20 would be thrown away, because 0.50 is below 0.9.
- Make a heavy copy of the same photo. Apply a strong augmentation: RandAugment or CTAugment picks several random colour, contrast and geometric changes, then Cutout blacks out a square patch. Call this . Check: the heavy copy is much harder to look at, but it is still a picture of the same animal.
- Ask the model for probabilities on the heavy copy. Suppose it returns cat 0.60, dog 0.25, bird 0.15. The model is less sure, because the image is harder. Check: this is the prediction that will be trained.
- Score the heavy prediction against the pseudo-label. The loss is the cross-entropy between the one-hot target cat and the heavy prediction. With the target being one-hot, this is minus the log of the probability of cat, which is . Check: a perfect match, cat 1.0, would give .
- Repeat for every unlabeled image in the batch and add the labeled loss. An image whose light guess was below the threshold contributes zero, but still counts in the average. The total loss is the supervised loss plus the unlabeled loss, with a fixed weight of 1 in the paper.
The key idea is in steps 2 and 5. The label is produced from the light copy, and the model is trained to match it on the heavy copy. Because the heavy copy is harder, the model cannot just copy its own answer; it has to learn features that survive heavy changes. The threshold in step 3 keeps wrong labels out, so the model mostly teaches itself with answers it is already sure about.
Three unlabeled images, threshold , weak-view predictions as follows.
- Image A: cat 0.93, dog 0.05, bird 0.02. The top value is 0.93, and , so the mask is 1. The pseudo-label is cat.
- Image B: cat 0.50, dog 0.30, bird 0.20. The top value is 0.50, and , so the mask is 0. No pseudo-label.
- Image C: cat 0.06, dog 0.91, bird 0.03. The top value is 0.91, and , so the mask is 1. The pseudo-label is dog.
Two of the three images are kept. Interpretation: the threshold throws away the uncertain image without looking at its true label, which the algorithm never sees.
Four unlabeled images, threshold , and the heavy-view probability on the true pseudo-label for each kept image.
- Image A is kept (from the example above, cat). The heavy-view probability on cat is 0.60, so its loss is .
- Image B is masked out, so its loss is .
- Image C is kept (dog). The heavy-view probability on dog is 0.80, so its loss is .
- Image D is masked out, so its loss is .
- Sum the four losses: .
- Divide by all four images, not by the two kept ones: .
- Add the supervised loss, here taken as , with : total .
Interpretation: the average divides by the batch size, so the loss is about half what you would get if you divided by the two kept images. Early in training most images are masked, so the unlabeled term is small. As the model grows more confident, more images pass the threshold and the term grows. This is the "natural curriculum" the paper describes.
The math
FixMatch has two cross-entropy terms. For two probability vectors and over classes, the cross-entropy is
When is a one-hot target, with and all other entries 0, this reduces to , the negative log of the probability given to the target class. That is the quantity in step 6 above.
Write for the probability vector the model gives for input , and for an indicator that is 1 when its condition is true and 0 otherwise.
Steps 2 and 3 in symbols. The light copy gives the guess . The pseudo-label is the arg max, , and the mask is , which is 1 if the top probability reaches the threshold .
Steps 1 and 2 in symbols (supervised part). For a labeled batch of examples , where is the one-hot label, the supervised loss is
Here is the light augmentation, applied to labeled images too.
Steps 4 to 6 in symbols (unlabeled part). The unlabeled batch has images, where is the ratio of unlabeled to labeled images in the batch. The unlabeled loss is
The average divides by all images, including the masked ones. That is what makes a low-confidence batch produce a small loss rather than a large one.
Step 7 in symbols (total loss).
with in the paper's main setting.
Learning rate schedule. The paper uses stochastic gradient descent with momentum and a cosine decay. If is the initial learning rate, the current step and the total number of steps, the rate at step is
With the rate starts at 0.03 and ends at .
- η cos(7πk/16K), with x = k/K
Augmentation strength and threshold. The threshold is the only new hyperparameter of the pseudo-labeling part. The paper uses . A softer variant replaces the arg max with a sharpened distribution using a temperature , as in Softmax Temperature; the paper tests this and finds no gain once thresholding is used.
Results
CIFAR-10, CIFAR-100, SVHN, STL-10. All methods are run in the same codebase with the same network. For CIFAR-10 at 40 / 250 / 4000 labels, FixMatch with CTAugment has mean errors of 11.39%, 5.07% and 4.31%, and FixMatch with RandAugment has 13.81%, 5.07% and 4.26%. On CIFAR-100 at 2500 labels, ReMixMatch is slightly better, 27.43% against 28.64% for FixMatch with CTAugment, so the paper does not claim a win everywhere. On STL-10 with 1000 labels, FixMatch with CTAugment reaches 5.17% against ReMixMatch's 5.23%, a tie within the spread.
ImageNet (10% of labels, ResNet-50). Top-1 error is 28.54 ± 0.52%, which the paper reports as 2.68 points better than UDA. Top-5 error is 10.87 ± 0.28%.
Barely supervised learning (one label per class on CIFAR-10). Four random label sets give test accuracies from 48.58% to 85.32%, with a median of 64.28%. The label set matters: the most representative images give a median of 78%, the middle of the ranking gives 65%, and the least representative images fail to converge, staying at 10%.
Ablations (on one 250-label split, default error 4.84%):
- Confidence threshold: 0.95 gives the lowest error. Accuracy drops by more than 1.5 points with a small threshold. The paper's reading is that pseudo-label quality matters more than quantity.
- Sharpening instead of thresholding: no significant difference once a threshold is used, and it adds a temperature hyperparameter.
- Strong augmentation: the two variants that change the strong augmentation in the ablation table both reach 6.15% error. The paper concludes that both the Cutout step and the CTAugment policy are needed.
- Weak-for-strong swap: using a strong augmentation on the light branch made training diverge early. Using no augmentation on the light branch let the model overfit its own guesses. Using a weak augmentation on the heavy branch peaked at 45% accuracy and then collapsed to 12%.
- Distribution alignment: adding it from ReMixMatch brings FixMatch to 40.14% error on CIFAR-100 with 400 labels, against 44.28% for ReMixMatch.
Limits the paper states. At 4 labels per class the variance over folds is large: 3.35 points for CIFAR-10 at 4 labels per class, against 0.33 at 25 labels per class. Random seeds matter too. Across five seeds on CIFAR-10 with 40 labels, error ranges from 5.46% to 13.32%. The paper also finds that weight decay and the choice of optimizer change results a lot, so two papers that use the same algorithm can still differ in reported accuracy.
Reading guide
- Introduction. Why labels are expensive and what semi-supervised learning promises. Needs Semi-Supervised Learning.
- Section 2, FixMatch. The core method. Needs Pseudo-Labeling, Consistency Regularization, Cross-Entropy Loss, and Data Augmentation for the light and heavy copies. The optimizer details in section 2.4 need Stochastic Gradient Descent, Momentum, Cosine Annealing, L2 Regularization and Exponential Moving Average.
- Section 2.5, Extensions. Shows how the method can be combined with Mixup or with adversarial perturbations; read it after section 2.
- Section 3, Related work and Table 1. A comparison of how each method makes its artificial label and what post-processing it applies. The table is the fastest way to see what FixMatch removes.
- Section 4, Experiments. Benchmarks, error-rate tables, and the ImageNet and barely-supervised results. Needs the ideas above and a feel for what an error rate over five splits means.
- Section 5, Ablations. The most useful part for understanding why the method works. Needs Softmax Temperature for the sharpening comparison.
- Conclusion and broader impact. Short. The paper lists the risks of making semi-supervised learning easy to use.
Check yourself
QuestionWhat is the one-line summary of how FixMatch makes its training target?Show answer
QuestionSuppose the model gives probabilities cat 0.97, dog 0.02, bird 0.01 on the light copy and the threshold is 0.95. Is the image used, and what is its pseudo-label?Show answer
QuestionA batch has eight unlabeled images and the mask keeps only two of them, with per-image unlabeled losses of 0.40 and 0.60. What is the unlabeled loss , and why is it not ?Show answer
QuestionWhy does the paper argue that thresholding makes sharpening unnecessary, and what does it cost to use sharpening anyway?Show answer
Sources
- Sohn, K., Berthelot, D., Li, C.-L., Zhang, Z., Carlini, N., Cubuk, E. D., Kurakin, A., Zhang, H., Raffel, C. (2020). FixMatch: Simplifying Semi-Supervised Learning with Consistency and Confidence. arXiv:2001.07685. arxiv.org/abs/2001.07685
- Official code: github.com/google-research/fixmatch
- Background: Semi-supervised learning (Wikipedia)