Labelled data is often either expensive or hard to obtain. As such, there has been a plethora of work to make better use of unlabelled data in machine learning, with paradigms such as unsupervised learning, semi-supervised learning, and more recently, self-supervised learning. FixMatch is an approach to semi-supervised learning (SSL) that combines two common approaches of SSL: 1. consistency regularisation and 2. pseudo-labelling.

Consistency Regularisation

Consistency regularisation is an approach that utilises unlabelled data, and its core assumption is: the model should output similar predictions when fed perturbed versions of the same input sample. Formally, what this means is that given a model and input sample , for some perturbation function . For example, for a given image, the model should return the same prediction for any perturbed version of that image (e.g. colour jittering, or affine transform).

The vanilla loss term when enforcing consistency is given by:

where is the model, is an unlabelled example, and is a stochastic perturbation function. The -norm can be swapped out for other norms or metrics, but the key idea is that perturbed versions of the same input should produce similar predictions.

Pseudo-Labelling

The idea behind pseudo-labeling is to use the model itself to produce artificial labels for unlabelled data. Such pseudo-labels are usually made to be hard labels (i.e. argmax of the model’s predicted class distribution), since this encourages the model to be confident in its predictions.

The vanilla loss term when employing pseudo-labelling is given by:

where , is a one-hot pseudo-label, is cross-entropy, and is a threshold parameter.

The Model

fixmatch1

Consistency regularisation is enforced through the use of two data augmentation strategies. The first is weak augmentation, which is a simple flip-and-shift strategy whereby images are randomly flipped horizontally with probability , and randomly translated up to % horizontally and vertically. The second is strong augmentation, which is implemented using either RandAugment or CTAugment. Both of these strong augmentation strategies employ a stronger form of distortion on to the source images, such as colour distortion and other affine transformations such as shearing.

Loss Function

The loss function for the FixMatch model consist of two terms: a supervised term and an unsupervised term . Additionally, since FixMatch is an SSL algorithm, the loss is computed using a labelled batch of images, as well as a larger unlabelled batch of images. Note that is a weak augmentation function, and is a strong augmentation function.

The supervised term is standard cross-entropy on weakly-augmented versions of the images in the batch:

where is the number of the images in the batch, and is the labelled example.

The unsupervised term relies on a model-generated pseudo-label. To compute this one-hot label, we first compute the model’s class distribution on weakly-augmented versions of the images: . The pseudo-label is then given by: . The actual loss term is then standard cross-entropy using this pseudo-label as the ground truth vs. predictions on strongly-augmented versions of the images:

where (typically ), and denotes the threshold above which we will retain the generated pseudo-label.

The full final loss function is then given by , where is a parameter that controls the weight given to the unlabelled loss term.

Results

fixmatch2

The key results from the paper can be seen in the above picture. It is also interesting to note that FixMatch manages to achieve % accuracy on CIFAR-10 with only 1 image per class.

Important Considerations

The paper notes that careful attention has to be given to various factors of the deep learning pipeline in label-sparse settings such as SSL. In particular, SSL methods are disproportionately affected by factors such as optimiser choice, learning rate schedule, and regularisation. The recommendations from the paper include using vanilla SGD with momentum instead of Adam, weight decay regularisation (parameter norm penalties), and a specific cosine-based learning rate schedule.