Paper commentary
A Simple Framework for Contrastive Learning of Visual Representations
- Problem Pixel-level generative models are expensive, and hand-designed discriminative pretext tasks may limit how general the learned features are.
- Method Trains an encoder by maximizing agreement between two random augmentations of each image, using a projection head and the NT-Xent loss over each minibatch, and discards the head afterwards.
- Results Reached 76.5% top-1 accuracy under linear evaluation on ImageNet with the ResNet-50 (4×) encoder.
Why pretext design limits representations
Label-free visual learning has mostly split into generative and discriminative approaches. Generating pixels is costly, and it may not be needed just to learn useful features. Discriminative methods built on hand-designed pretext tasks depend on heuristics, which can narrow what the learned features cover.
Contrastive methods in latent space had produced strong results, but many of them depended on specialized architectures or a memory bank. The aim here is a contrastive method that avoids both requirements while still outperforming earlier self-supervised methods on the same ImageNet linear evaluation.
How the SimCLR pipeline works
SimCLR learns by maximizing agreement between two stochastic augmentations of the same example, measured through a contrastive loss in a latent space. The pipeline has four parts: an augmentation module, a base encoder, a projection head and a contrastive loss.
The augmentation module draws two operators from one family and applies them to each image, giving a positive pair. The default family combines random crop with resizing, random flip, color distortion and Gaussian blur.
The encoder is a ResNet-50, and its average-pooled output h is the representation used downstream. The projection head is a small MLP with one hidden layer and a ReLU, given by \(z_i = g(h_i) = W^{(2)}\sigma(W^{(1)}h_i)\), and in the default setting it projects to a 128-dimensional space.
Each minibatch of N images yields 2N views, and the loss for a positive pair (i, j) is the negative log of a softmax-style ratio over all other views in the batch. \[\ell_{i,j} = -\log \frac{\exp(\mathrm{sim}(z_i,z_j)/\tau)}{\sum_{k=1}^{2N} \mathbf{1}_{[k\neq i]}\exp(\mathrm{sim}(z_i,z_k)/\tau)}\] Here sim is the cosine similarity between normalized vectors and \(\tau\) is the temperature; the other 2(N-1) augmented examples act as negatives.
The total loss averages the pair losses over both orderings (i, j) and (j, i) for every image in the minibatch.
Training minimizes this averaged loss with the LARS optimizer, which keeps large batches stable. Global batch normalization is used, because local batch statistics on one device would let positive partners exploit shared information instead of learning better representations. After training, the projection head is discarded and the encoder is kept for downstream evaluation.
Which augmentation compositions define the task
Random cropping with resizing of target images can define a family of tasks that includes both of these, while leaving the architecture free.
To isolate augmentation effects, the ablation always crops and resizes first, then applies the targeted augmentation to one branch only, with the other branch left as the identity. The studied augmentations are cropping with flipping, rotation, cutout, color distortion, Gaussian blur and Sobel filtering.
Composing augmentations made the contrastive task harder, but the representation quality improved substantially. Figure 5 reports the linear evaluation accuracy for single transformations on the diagonal and their pairs off the diagonal.
Random cropping combined with color distortion stands out among the compositions. The authors conjecture that cropping alone lets a network use color as a shortcut, since patches from one image share a similar color distribution and color histograms can separate images.
Color strength against supervised training
Table 1 varies color distortion strength from 1/8 to 1, with and without Gaussian blur, and includes AutoAugment as a comparison policy. For the unsupervised ResNet-50, linear evaluation rose from 59.6 at strength 1/8 to 64.5 at strength 1 with blur, which is the default policy. Supervised accuracy stayed between 75.4 and 77.0 across the five strength settings, and it was 77.1 with AutoAugment.
Stronger color augmentation does not improve supervised training, and in some settings it hurts it. The supervised models were trained for 90 epochs, and the authors note that longer training improves the stronger augmentation by about 0.5%.
AutoAugment, a policy found with supervised learning, reached 61.1 with the unsupervised model, below the 64.5 of simple cropping with stronger color distortion and blur. The authors conclude that contrastive learning benefits from stronger color augmentation than supervised learning does. Earlier work reported that augmentation helps self-supervised learning in general, but the authors' point is narrower: augmentation with no accuracy gain for supervised training can still help contrastive training considerably.
Where the projection head helps
Three head designs were compared: identity mapping, a linear projection and the default nonlinear projection with one hidden layer and ReLU. The nonlinear head was about 3% better than the linear head and more than 10% better than no projection, and similar results held across output dimensionalities when a head was used. The sweep covered projection output dimensionalities from 32 to 2048, with h being 2048-dimensional.
Even with the nonlinear head, the representation before it, h, is more than 10% better under linear evaluation than z = g(h). The authors conjecture that the contrastive loss trains z to be invariant to transformations, so g can discard information such as color or object orientation that a downstream task may need.
To test this, additional MLPs were trained to predict the transformation applied during pretraining, once from h and once from g(h). For predicting rotation, the probe reached 67.6 from h and 25.6 from g(h), against a random guess of 25. For color vs grayscale, the probe reached 99.3 from h and 97.4 from g(h), against a random guess of 80, and both representations are 2048-dimensional.
Table 3 also reports original versus corrupted images and original versus Sobel filtered images, where h reached 99.5 and 96.6 and g(h) reached 59.6 and 56.3.
Loss choice and batch size
NT-Xent was compared with a logistic loss and a margin loss. The authors note that normalization with temperature weights examples by their hardness, while the other objectives do not weigh negatives by relative hardness.
Margin and logistic losses improved only with semi-hard negative mining, which uses negatives that lie within the margin and are closest but farther than the positive. In Table 4, linear top-1 was 50.9 for Margin, 51.6 for NT-Logi, 57.5 for Margin with semi-hard mining, 57.9 for NT-Logi with semi-hard mining and 63.9 for NT-Xent.
With ℓ2 normalization, linear top-1 was 59.7 at τ = 0.05, 64.4 at τ = 0.1, 60.7 at τ = 0.5 and 58.0 at τ = 1. Without normalization, contrastive accuracy was 91.7 at τ = 10 and 92.1 at τ = 100, yet linear top-1 was only 57.2 and 57.0. Without normalization, the contrastive task is easier, yet the representation is worse under linear evaluation.
The batch size N was varied from 256 to 8192, and at 8192 each positive pair has 16382 negatives from both views. When training runs for 100 epochs, larger batches have a clear advantage, and the gaps shrink with more epochs as batches are resampled. The authors attribute this to larger batches supplying more negative examples per step, which speeds convergence in contrastive learning.
The linear learning-rate scaling used here is noted as a condition, and an appendix figure reports that square-root scaling improves small batches.
ImageNet, few-label and transfer results
Compared with prior self-supervised methods, SimCLR's linear evaluation accuracy on ImageNet is 7% higher in relative terms than the previous state of the art. Width variants of ResNet-50 were trained for 1000 epochs, reaching 69.3 top-1 at 1×, 74.2 at 2× and 76.5 at 4×, with the 4× model also reaching 93.2 top-5.
With 1% and 10% of ILSVRC-12 labels, sampled class-balanced at about 12.8 and about 128 images per class, the whole base network is fine-tuned without regularization. Top-5 accuracy at 1% was 75.5 for the 1× model, 83.0 for the 2× model and 85.8 for the 4× model. At 10%, top-5 accuracy was 87.8, 91.2 and 92.6 for the 1×, 2× and 4× models.
Transfer was tested on 12 natural image datasets with the ResNet-50 (4×) model, and hyperparameters were chosen on a validation set for each model-dataset pair. When fine-tuned, SimCLR was significantly better than the supervised baseline on 5 datasets, worse on Pets and Flowers, and statistically tied on the remaining 5.
Limits of the reported comparisons
The default 100-epoch setting does not reach maximum performance, so the ablation numbers are useful for comparison but are not the best achievable values. The 1000-epoch results use wider ResNet-50 variants, so they are not controlled comparisons with the 100-epoch ablations.
The supervised ResNets in the depth and width study were trained for 90 epochs. The authors report that training the supervised ResNets longer does not improve them.
The asymmetric ablation applies augmentation to only one branch, which lowers absolute accuracy, and the authors expect the relative effects to hold. The ablations use ImageNet, and CIFAR-10 pretraining is reported only in an appendix. Transfer covers 12 datasets, and the semi-supervised results cover only 1% and 10% of labels.
Paper info
- Authors
- Ting Chen, Simon Kornblith, Mohammad Norouzi, Geoffrey Hinton
- Venue
- arXiv · Preprint
- First published
- 2020-2-13
- Added
- 2026-10-20
- Updated
- 2020-7-1
- Version
- v3
- arXiv
- 2002.05709
- Category
- cs.LG · cs.CV · stat.ML
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Ting Chen, Simon Kornblith, Mohammad Norouzi, Geoffrey Hinton (2020). A Simple Framework for Contrastive Learning of Visual Representations. arXiv:2002.05709v3. https://arxiv.org/abs/2002.05709v3
BibTeX
@misc{chen2020simple,
title = {{A Simple Framework for Contrastive Learning of Visual Representations}},
author = {Ting Chen and Simon Kornblith and Mohammad Norouzi and Geoffrey Hinton},
year = {2020},
eprint = {2002.05709},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2002.05709v3}
}