Paper commentary
Unsupervised Learning of Visual Features by Contrasting Cluster Assignments
SwAV learns visual features by swapping cluster predictions between image views
- Problem Contrastive methods need many explicit pairwise feature comparisons, which is computationally expensive. Clustering methods avoid those comparisons but need a full pass over the dataset to form their training codes.
- Method SwAV clusters images online within each minibatch. Instead of comparing features directly, it predicts one view's cluster code from another view's features, and multi-crop adds low-resolution views.
- Results SwAV reached 75.3% top-1 accuracy on ImageNet with a ResNet-50 under the linear evaluation protocol.
Why pairwise contrast strains scale
Instance discrimination treats each image and its transformations as one class, so training pulls together views of the same image and pushes apart views of different images. Computing every pairwise comparison on a large dataset is impractical, so practical implementations sample random subsets of images, keep a memory bank of earlier representations, or add a momentum encoder.
Clustering avoids pairwise comparisons by grouping images with similar features, but its codes must be formed from a pass over the entire dataset before they can serve as training targets.
The question is whether cluster codes can be computed online and kept consistent across views of the same image, so that training does not depend on explicit pairwise comparisons. The authors state that a method built this way can scale to potentially unlimited amounts of data and works with both small and large batches.
Swapping codes between views
Each augmented view is mapped by the encoder to a feature that is normalized to unit length, and each normalized feature is matched to a set of K trainable prototype vectors to give a code. For two views with features z_t and z_s, the loss is \( L(z_t, z_s) = \ell(z_t, q_s) + \ell(z_s, q_t) \), so each code is predicted from the feature of the other view.
The term \( \ell(z, q) = -\sum_k q^{(k)} \log p^{(k)} \) is a cross entropy between a code and a softmax over the dot products of the feature with all prototypes, where \( p^{(k)}_t = \exp(z_t^\top c_k / \tau) / \sum_{k'} \exp(z_t^\top c_{k'} / \tau) \) and \( \tau \) is a temperature. Summed over all images and over pairs of augmentations, the objective is minimized jointly with respect to the prototypes C and the encoder parameters.
Because the two views are linked only through their codes, the features of one view are never compared directly with the features of the other. This is the contrast with contrastive instance learning, where features from different transformations are compared directly.
Computing codes within a minibatch
The codes maximize \( \max_{Q \in \mathcal{Q}} \operatorname{Tr}(Q^\top C^\top Z) + \varepsilon H(Q) \) over the minibatch, where H is the entropy of Q and \( \varepsilon \) controls how smooth the mapping is. A strong entropy regularization with a high \( \varepsilon \) leads to a trivial solution in which all samples collapse to one representation and are assigned uniformly to all prototypes, so \( \varepsilon \) is kept low.
The feasible set is a transportation polytope restricted to the minibatch, with marginal constraints on the assignment mass of each prototype and of each sample. These constraints give an equal partition of the batch over the prototypes, which keeps the codes of different images in a batch distinct.
In the online setting, the method keeps the soft solution instead of rounding it to discrete codes, because rounding converges quickly but to a worse solution. The soft codes take the form \( Q^* = \mathrm{Diag}(u)\exp(C^\top Z / \varepsilon)\mathrm{Diag}(v) \), where u and v are renormalization vectors computed with three Sinkhorn-Knopp iterations.
The authors report that aligning 4K features to 3K codes takes 35ms on their setup.
When the batch size B is small compared with K, the batch cannot be partitioned equally over the prototypes, so features from earlier batches are added to Z. Only the codes of the current batch features enter the loss, and about 3K features are stored, which is about 15 batches of 256, against the 65K instances from the last 250 batches that contrastive methods typically store.
Multi-crop views
Two full-resolution crops are kept, and V additional low-resolution crops are sampled from the same image. In the loss, \( L(z_{t_1}, \dots, z_{t_{V+2}}) = \sum_{i \in \{1,2\}} \sum_{v=1}^{V+2} \mathbb{1}_{v \neq i}\, \ell(z_{t_v}, q_{t_i}) \), so the codes of the two full-resolution crops serve as targets for the features of all other crops.
Codes are computed only from the full-resolution crops, since computing them for every crop changed the transfer performance.
Comparing random crops captures relations between parts of a scene, but adding standard-size crops raises memory and compute quadratically, so the extra views are kept small in resolution. Jigsaw tiles are non-overlapping small crops covering roughly ∼20% of the image, whereas multi-crop samples random crops at two sizes.
ImageNet linear and semi-supervised results
Under the linear evaluation protocol, a linear classifier trained on frozen ResNet-50 features reached 75.3% top-1 accuracy on ImageNet. With a wider variant of ResNet-50, the same protocol reached 78.5% top-1 accuracy.
The authors report that these frozen features rose by 4.2% over the state of the art on ImageNet with a standard ResNet, and sat 1.2% below a fully supervised model. Accuracy rises with width, and the gap to supervised training shrinks to 0.6% for large architectures.
With 1% of ImageNet labels used for fine-tuning, the ResNet-50 reached 53.9 top-1, and with 10% of labels it reached 70.2. These semi-supervised values are above the self-supervised baselines in the same table, and the authors describe them as on par with FixMatch, which uses RandAugment and label propagation.
Transfer to detection and scene datasets
With frozen features and linear classifiers, SwAV reached 56.7 on Places205 against 53.2 for supervised pretraining, and 48.6 on iNaturalist2018 against 46.7. On VOC07, the mAP was 88.9 against 87.5 for supervised pretraining.
With the backbone fine-tuned, Faster R-CNN with an R50-C4 backbone on VOC07+12 reached 82.6 AP50 against 81.3, and Mask R-CNN with an R50-FPN backbone on COCO reached 41.6 AP against 39.7. With DETR on COCO, the values were 42.1 against 40.8.
The authors describe SwAV as the first self-supervised method to surpass ImageNet supervised features on these scene and species datasets. They note that using a pretrained backbone is crucial for DETR to get good results, unlike Faster R-CNN. Outperforming supervised pretraining on detection is consistent with earlier self-supervised work, according to the authors.
Small-batch training
Training with batches of 256 images on 4 GPUs, SwAV stores a queue of 3,840 features and no momentum encoder. MoCov2 needs to store 65,536 features while also keeping a momentum encoder network.
SwAV reached 72% after 200 epochs in 102 hours, while MoCov2 needed 800 epochs to reach 71.1%.
Clustering versus contrastive methods
The authors rebuilt DeepCluster and SeLa with later training improvements, producing DeepCluster-v2 and SeLa-v2, and replaced the learned classification layer of DeepCluster with explicit comparisons between features and k-means centroids. The authors note that DeepCluster's classification layer must be reinitialized each epoch, because cluster assignments have no correspondence between consecutive epochs.
With 2×224 crops over 400 epochs, SeLa-v2 reached 67.2, DeepCluster-v2 reached 70.2, SwAV reached 70.1, and SimCLR reached 68.2, while supervised training reached 76.5.
At 800 epochs with 8 crops, DeepCluster-v2 reached 75.2% top-1 accuracy, against 75.3% for SwAV. The authors argue that DeepCluster-v2 is not online, since it needs several passes over the dataset to refresh its centroids and assignments, and cannot be trained for a single epoch.
Multi-crop on other methods
Applied to SimCLR, DeepCluster and SeLa, multi-crop improves ImageNet top-1 accuracy by between 2% and 4%. The gain is reported as consistent across the methods considered, with the clustering-based methods benefiting more than the contrastive ones.
Multi-crop does not improve the supervised model.
Uncurated Instagram pretraining
The authors pretrained SwAV on 1 billion random public non-EU Instagram images, without labels. With frozen features, a random initialization reached 15.0 top-1, SimCLR reached 60.4, and SwAV reached 66.5 on ImageNet. With fine-tuned features, the values were 76.5 for random initialization, 77.2 for SimCLR, and 77.8 for SwAV. The authors report a gain of 6% over SimCLR on this data.
Compared with training from scratch on ImageNet, SwAV pretraining on the random images added 1.3%. He et al. used a curated Instagram set filtered by hashtags, so their setting differs from this one.
Across ResNeXt variants, SwAV outperformed supervised models trained from scratch on ImageNet by a clear margin at every capacity. The authors also compare with a weakly supervised model from Mahajan et al. that was pretrained on hashtag-filtered images.
Limitations
With minibatches, discrete codes perform worse than soft codes, so the online method keeps the soft solution. Codes are computed only from the full-resolution crops, because computing them for all crops increased compute and altered transfer performance.
SwAV has a higher per-epoch running time than SimCLR and MoCov2, so one epoch of those methods is faster in wall-clock time, although SwAV needs fewer epochs for good downstream performance.
Combining SwAV with a momentum mechanism and a large queue was not tested and is left to future work. SwAV was not designed for semi-supervised learning, and the semi-supervised comparison sets it against FixMatch, which uses RandAugment. The architectures used were designed for supervised tasks, and whether the same models would emerge from unsupervised architecture search was not tested.
Paper info
- Authors
- Mathilde Caron, Ishan Misra, Julien Mairal, Priya Goyal, Piotr Bojanowski, Armand Joulin
- Venue
- arXiv · Preprint
- First published
- 2020-6-17
- Added
- 2026-11-12
- Updated
- 2021-1-8
- Version
- v5
- arXiv
- 2006.09882
- Category
- cs.CV
- 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
Mathilde Caron, Ishan Misra, Julien Mairal, Priya Goyal, Piotr Bojanowski, Armand Joulin (2020). Unsupervised Learning of Visual Features by Contrasting Cluster Assignments. arXiv:2006.09882v5. https://arxiv.org/abs/2006.09882v5
BibTeX
@misc{caron2020unsupervised,
title = {{Unsupervised Learning of Visual Features by Contrasting Cluster Assignments}},
author = {Mathilde Caron and Ishan Misra and Julien Mairal and Priya Goyal and Piotr Bojanowski and Armand Joulin},
year = {2020},
eprint = {2006.09882},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2006.09882v5}
}