# Unsupervised Learning of Visual Features by Contrasting Cluster Assignments

###### Abstract

Unsupervised image representations have significantly reduced the gap with supervised pretraining, notably with the recent achievements of contrastive learning methods. These contrastive methods typically work online and rely on a large number of explicit pairwise feature comparisons, which is computationally challenging. In this paper, we propose an online algorithm, SwAV, that takes advantage of contrastive methods without requiring to compute pairwise comparisons. Specifically, our method simultaneously clusters the data while enforcing consistency between cluster assignments produced for different augmentations (or “views”) of the same image, instead of comparing features directly as in contrastive learning. Simply put, we use a “swapped” prediction mechanism where we predict the code of a view from the representation of another view. Our method can be trained with large and small batches and can scale to unlimited amounts of data. Compared to previous contrastive methods, our method is more memory efficient since it does not require a large memory bank or a special momentum network. In addition, we also propose a new data augmentation strategy, multi-crop , that uses a mix of views with different resolutions in place of two full-resolution views, without increasing the memory or compute requirements. We validate our findings by achieving 75.3 % 75.3\% top-1 accuracy on ImageNet with ResNet-50, as well as surpassing supervised pretraining on all the considered transfer tasks.

## 1 Introduction

Unsupervised visual representation learning, or self-supervised learning, aims at obtaining features without using manual annotations and is rapidly closing the performance gap with supervised pretraining in computer vision [ 10 , 24 , 44 ] . Many recent state-of-the-art methods build upon the instance discrimination task that considers each image of the dataset (or “instance”) and its transformations as a separate class [ 16 ] . This task yields representations that are able to discriminate between different images, while achieving some invariance to image transformations. Recent self-supervised methods that use instance discrimination rely on a combination of two elements: (i) a contrastive loss [ 23 ] and (ii) a set of image transformations. The contrastive loss removes the notion of instance classes by directly comparing image features while the image transformations define the invariances encoded in the features. Both elements are essential to the quality of the resulting networks [ 44 , 10 ] and our work improves upon both the objective function and the transformations.

The contrastive loss explicitly compares pairs of image representations to push away representations from different images while pulling together those from transformations, or views, of the same image. Since computing all the pairwise comparisons on a large dataset is not practical, most implementations approximate the loss by reducing the number of comparisons to random subsets of images during training [ 10 , 24 , 58 ] . An alternative to approximate the loss is to approximate the task—that is to relax the instance discrimination problem. For example, clustering-based methods discriminate between groups of images with similar features instead of individual images [ 7 ] . The objective in clustering is tractable, but it does not scale well with the dataset as it requires a pass over the entire dataset to form image “codes” ( i.e ., cluster assignments) that are used as targets during training. In this work, we use a different paradigm and propose to compute the codes online while enforcing consistency between codes obtained from views of the same image. Comparing cluster assignments allows to contrast different image views while not relying on explicit pairwise feature comparisons. Specifically, we propose a simple “swapped” prediction problem where we predict the code of a view from the representation of another view. We learn features by Sw apping A ssignments between multiple V iews of the same image ( SwAV ). The features and the codes are learned online, allowing our method to scale to potentially unlimited amounts of data. In addition, SwAV works with small and large batch sizes and does not need a large memory bank [ 58 ] or a momentum encoder [ 24 ] .

Besides our online clustering-based method, we also propose an improvement to the image transformations. Most contrastive methods compare one pair of transformations per image, even though there is evidence that comparing more views during training improves the resulting model [ 44 ] . In this work, we propose multi-crop that uses smaller-sized images to increase the number of views while not increasing the memory or computational requirements during training. We also observe that mapping small parts of a scene to more global views significantly boosts the performance. Directly working with downsized images introduces a bias in the features [ 53 ] , which can be avoided by using a mix of different sizes. Our strategy is simple, yet effective, and can be applied to many self-supervised methods with consistent gain in performance.

We validate our contributions by evaluating our method on several standard self-supervised benchmarks. In particular, on the ImageNet linear evaluation protocol, we reach 75.3 % 75.3\% top- 1 1 accuracy with a standard ResNet-50, and 78.5 % 78.5\% with a wider model. We also show that our multi-crop strategy is general, and improves the performance of different self-supervised methods, namely SimCLR [ 10 ] , DeepCluster [ 7 ] , and SeLa [ 2 ] , between 2 % 2\% and 4 % 4\% top-1 accuracy on ImageNet. Overall, we make the following contributions: • We propose a scalable online clustering loss that improves performance by + 2 % +2\% on ImageNet and works in both large and small batch settings without a large memory bank or a momentum encoder.

• We introduce the multi-crop strategy to increase the number of views of an image with no computational or memory overhead. We observe a consistent improvement of between 2 % 2\% and 4 % 4\% on ImageNet with this strategy on several self-supervised methods.

• Combining both technical contributions into a single model, we improve the performance of self-supervised by + 4.2 % +4.2\% on ImageNet with a standard ResNet and outperforms supervised ImageNet pretraining on multiple downstream tasks. This is the first method to do so without finetuning the features, i.e ., only with a linear classifier on top of frozen features.

## 2 Related Work

##### Instance and contrastive learning.

Instance-level classification considers each image in a dataset as its own class [ 5 , 16 , 58 ] . Dosovitskiy et al . [ 16 ] assign a class explicitly to each image and learn a linear classifier with as many classes as images in the dataset. As this approach becomes quickly intractable, Wu et al . [ 58 ] mitigate this issue by replacing the classifier with a memory bank that stores previously-computed representations. They rely on noise contrastive estimation [ 22 ] to compare instances, which is a special form of contrastive learning [ 29 , 47 ] . He et al . [ 24 ] improve the training of contrastive methods by storing representations from a momentum encoder instead of the trained network. More recently, Chen et al . [ 10 ] show that the memory bank can be entirely replaced with the elements from the same batch if the batch is large enough. In contrast to this line of works, we avoid comparing every pair of images by mapping the image features to a set of trainable prototype vectors.

##### Clustering for deep representation learning.

Our work is also related to clustering-based methods [ 2 , 4 , 7 , 8 , 30 , 59 , 63 , 68 , 19 , 62 ] . Caron et al . [ 7 ] show that k k -means assignments can be used as pseudo-labels to learn visual representations. This method scales to large uncurated dataset and can be used for pre-training of supervised networks [ 8 ] . However, their formulation is not principled and recently, Asano et al . [ 2 ] show how to cast the pseudo-label assignment problem as an instance of the optimal transport problem. We consider a similar formulation to map representations to prototype vectors, but unlike [ 2 ] we keep the soft assignment produced by the Sinkhorn-Knopp algorithm [ 13 ] instead of approximating it into a hard assignment. Besides, unlike Caron et al . [ 7 , 8 ] and Asano et al . [ 2 ] , we obtain online assignments which allows our method to scale gracefully to any dataset size.

##### Handcrafted pretext tasks.

Many self-supervised methods manipulate the input data to extract a supervised signal in the form of a pretext task [ 14 , 1 , 31 , 34 , 36 , 42 , 45 , 48 , 49 , 55 , 56 , 66 ] . We refer the reader to Jing et al . [ 32 ] for an exhaustive and detailed review of this literature. Of particular interest, Misra and van der Maaten [ 44 ] propose to encode the jigsaw puzzle task [ 46 ] as an invariant for contrastive learning. Jigsaw tiles are non-overlapping crops with small resolution that cover only part ( ∼ 20 % {\sim}20\% ) of the entire image area. In contrast, our multi-crop strategy consists in simply sampling multiple random crops with two different sizes: a standard size and a smaller one.

## 3 Method

Our goal is to learn visual features in an online fashion without supervision. To that effect, we propose an online clustering-based self-supervised method. Typical clustering-based methods [ 2 , 7 ] are offline in the sense that they alternate between a cluster assignment step where image features of the entire dataset are clustered, and a training step where the cluster assignments, i.e ., “codes” are predicted for different image views. Unfortunately, these methods are not suitable for online learning as they require multiple passes over the dataset to compute the image features necessary for clustering. In this section, we describe an alternative where we enforce consistency between codes from different augmentations of the same image. This solution is inspired by contrastive instance learning [ 58 ] as we do not consider the codes as a target, but only enforce consistent mapping between views of the same image. Our method can be interpreted as a way of contrasting between multiple image views by comparing their cluster assignments instead of their features.

More precisely, we compute a code from an augmented version of the image and predict this code from other augmented versions of the same image. Given two image features 𝐳 t \mathbf{z}_{t} and 𝐳 s \mathbf{z}_{s} from two different augmentations of the same image, we compute their codes 𝐪 t \mathbf{q}_{t} and 𝐪 s \mathbf{q}_{s} by matching these features to a set of K K prototypes { 𝐜 1 , … , 𝐜 K } \{\mathbf{c}_{1},\dots,\mathbf{c}_{K}\} . We then setup a “swapped” prediction problem with the following loss function: L ⁡ ( 𝐳 t , 𝐳 s ) \displaystyle L(\mathbf{z}_{t},\mathbf{z}_{s}) = \displaystyle= ℓ ⁡ ( 𝐳 t , 𝐪 s ) + ℓ ⁡ ( 𝐳 s , 𝐪 t ) , \displaystyle\ell(\mathbf{z}_{t},\mathbf{q}_{s})+\ell(\mathbf{z}_{s},\mathbf{q}_{t}), (1) where the function ℓ ⁡ ( 𝐳 , 𝐪 ) \ell({\mathbf{z}},{\mathbf{q}}) measures the fit between features 𝐳 {\mathbf{z}} and a code 𝐪 {\mathbf{q}} , as detailed later. Intuitively, our method compares the features 𝐳 t \mathbf{z}_{t} and 𝐳 s \mathbf{z}_{s} using the intermediate codes 𝐪 t \mathbf{q}_{t} and 𝐪 s \mathbf{q}_{s} . If these two features capture the same information, it should be possible to predict the code from the other feature. A similar comparison appears in contrastive learning where features are compared directly [ 58 ] . In fig. 1 , we illustrate the relation between contrastive learning and our method.

### 3.1 Online clustering

Each image 𝐱 n \mathbf{x}_{n} is transformed into an augmented view 𝐱 n ​ t \mathbf{x}_{nt} by applying a transformation t t sampled from the set 𝒯 \mathcal{T} of image transformations. The augmented view is mapped to a vector representation by applying a non-linear mapping f θ f_{\theta} to 𝐱 n ​ t \mathbf{x}_{nt} . The feature is then projected to the unit sphere, i.e ., 𝐳 n ​ t = f θ ​ ( 𝐱 n ​ t ) / ‖ f θ ​ ( 𝐱 n ​ t ) ‖ 2 \mathbf{z}_{nt}=f_{\theta}(\mathbf{x}_{nt})/\|f_{\theta}(\mathbf{x}_{nt})\|_{2} . We then compute a code 𝐪 n ​ t \mathbf{q}_{nt} from this feature by mapping 𝐳 n ​ t \mathbf{z}_{nt} to a set of K K trainable prototypes vectors, { 𝐜 1 , … , 𝐜 K } \{\mathbf{c}_{1},\dots,\mathbf{c}_{K}\} . We denote by 𝐂 \mathbf{C} the matrix whose columns are the 𝐜 1 , … , 𝐜 k \mathbf{c}_{1},\dots,\mathbf{c}_{k} . We now describe how to compute these codes and update the prototypes online.

##### Swapped prediction problem.

The loss function in Eq. ( 1 ) has two terms that setup the “swapped” prediction problem of predicting the code 𝐪 t \mathbf{q}_{t} from the feature 𝐳 s \mathbf{z}_{s} , and 𝐪 s \mathbf{q}_{s} from 𝐳 t \mathbf{z}_{t} . Each term represents the cross entropy loss between the code and the probability obtained by taking a softmax of the dot products of 𝐳 i \mathbf{z}_{i} and all prototypes in 𝐂 \mathbf{C} , i.e ., ℓ ( 𝐳 t , 𝐪 s ) = − ∑ k 𝐪 s ( k ) log 𝐩 t ( k ) , where 𝐩 t ( k ) = exp ⁡ ( 1 τ ​ 𝐳 t ⊤ ​ 𝐜 k ) ∑ k ′ exp ⁡ ( 1 τ ​ 𝐳 t ⊤ ​ 𝐜 k ′ ) . \ell(\mathbf{z}_{t},\mathbf{q}_{s})=-\sum_{k}\mathbf{q}_{s}^{(k)}\log\mathbf{p}_{t}^{(k)},\quad\text{where}\quad\mathbf{p}_{t}^{(k)}=\frac{\exp\left(\frac{1}{\tau}\mathbf{z}_{t}^{\top}\mathbf{c}_{k}\right)}{\sum_{k^{\prime}}\exp\left(\frac{1}{\tau}\mathbf{z}_{t}^{\top}\mathbf{c}_{k^{\prime}}\right)}. (2) where τ \tau is a temperature parameter [ 58 ] . Taking this loss over all the images and pairs of data augmentations leads to the following loss function for the swapped prediction problem: − 1 N ∑ n = 1 N ∑ s , t ∼ 𝒯 [ 1 τ 𝐳 n ​ t ⊤ 𝐂𝐪 n ​ s + 1 τ 𝐳 n ​ s ⊤ 𝐂𝐪 n ​ t − log ∑ k = 1 K exp ( 𝐳 n ​ t ⊤ ​ 𝐜 k τ ) − log ∑ k = 1 K exp ( 𝐳 n ​ s ⊤ ​ 𝐜 k τ ) ] . -\frac{1}{N}\sum_{n=1}^{N}\sum_{s,t\sim\mathcal{T}}\left[\frac{1}{\tau}\mathbf{z}_{nt}^{\top}\mathbf{C}\mathbf{q}_{ns}+\frac{1}{\tau}\mathbf{z}_{ns}^{\top}\mathbf{C}\mathbf{q}_{nt}-\log\sum_{k=1}^{K}\exp\left(\frac{\mathbf{z}_{nt}^{\top}\mathbf{c}_{k}}{\tau}\right)-\log\sum_{k=1}^{K}\exp\left(\frac{\mathbf{z}_{ns}^{\top}\mathbf{c}_{k}}{\tau}\right)\right]. This loss function is jointly minimized with respect to the prototypes 𝐂 \mathbf{C} and the parameters θ \theta of the image encoder f θ f_{\theta} used to produce the features ( 𝐳 n ​ t ) n , t (\mathbf{z}_{nt})_{n,t} .

##### Computing codes online.

In order to make our method online, we compute the codes using only the image features within a batch. Intuitively, as the prototypes 𝐂 \mathbf{C} are used across different batches, SwAV clusters multiple instances to the prototypes. We compute codes using the prototypes 𝐂 \mathbf{C} such that all the examples in a batch are equally partitioned by the prototypes. This equipartition constraint ensures that the codes for different images in a batch are distinct, thus preventing the trivial solution where every image has the same code. Given B B feature vectors 𝐙 = [ 𝐳 1 , … , 𝐳 B ] \mathbf{Z}=[\mathbf{z}_{1},\dots,\mathbf{z}_{B}] , we are interested in mapping them to the prototypes 𝐂 = [ 𝐜 1 , … , 𝐜 K ] \mathbf{C}=[\mathbf{c}_{1},\dots,\mathbf{c}_{K}] . We denote this mapping or codes by 𝐐 = [ 𝐪 1 , … , 𝐪 B ] \mathbf{Q}=[\mathbf{q}_{1},\dots,\mathbf{q}_{B}] , and optimize 𝐐 \mathbf{Q} to maximize the similarity between the features and the prototypes , i.e ., max 𝐐 ∈ 𝒬 ⁡ Tr ​ ( 𝐐 ⊤ ​ 𝐂 ⊤ ​ 𝐙 ) + ε ​ H ​ ( 𝐐 ) , \max_{\mathbf{Q}\in\mathcal{Q}}\ \text{Tr}\left(\mathbf{Q}^{\top}\mathbf{C}^{\top}\mathbf{Z}\right)+\varepsilon H(\mathbf{Q}), (3) where H H is the entropy function, H ( 𝐐 ) = − ∑ i ​ j 𝐐 i ​ j log 𝐐 i ​ j H(\mathbf{Q})=-\sum_{ij}\mathbf{Q}_{ij}\log\mathbf{Q}_{ij} and ε \varepsilon is a parameter that controls the smoothness of the mapping. We observe that a strong entropy regularization ( i.e . using a high ε \varepsilon ) generally leads to a trivial solution where all samples collapse into an unique representation and are all assigned uniformely to all prototypes. Hence, in practice we keep ε \varepsilon low. Asano et al . [ 2 ] enforce an equal partition by constraining the matrix 𝐐 \mathbf{Q} to belong to the transportation polytope. They work on the full dataset, and we propose to adapt their solution to work on minibatches by restricting the transportation polytope to the minibatch: 𝒬 = { 𝐐 ∈ ℝ + K × B | 𝐐𝟏 B = 1 K 𝟏 K , 𝐐 ⊤ 𝟏 K = 1 B 𝟏 B } , \mathcal{Q}=\left\{\mathbf{Q}\in\mathbb{R}_{+}^{K\times B}~|~\mathbf{Q}\mathbf{1}_{B}=\frac{1}{K}\mathbf{1}_{K},\mathbf{Q}^{\top}\mathbf{1}_{K}=\frac{1}{B}\mathbf{1}_{B}\right\}, (4) where 𝟏 K \mathbf{1}_{K} denotes the vector of ones in dimension K K . These constraints enforce that on average each prototype is selected at least B K \frac{B}{K} times in the batch.

Once a continuous solution 𝐐 ∗ \mathbf{Q}^{*} to Prob. ( 3 ) is found, a discrete code can be obtained by using a rounding procedure [ 2 ] . Empirically, we found that discrete codes work well when computing codes in an offline manner on the full dataset as in Asano et al . [ 2 ] . However, in the online setting where we use only minibatches, using the discrete codes performs worse than using the continuous codes. An explanation is that the rounding needed to obtain discrete codes is a more aggressive optimization step than gradient updates. While it makes the model converge rapidly, it leads to a worse solution. We thus preserve the soft code 𝐐 ∗ \mathbf{Q}^{*} instead of rounding it. These soft codes 𝐐 ∗ \mathbf{Q}^{*} are the solution of Prob. ( 3 ) over the set 𝒬 \mathcal{Q} and takes the form of a normalized exponential matrix [ 13 ] : 𝐐 ∗ = Diag ​ ( 𝐮 ) ​ exp ⁡ ( 𝐂 ⊤ ​ 𝐙 ε ) ​ Diag ​ ( 𝐯 ) , \mathbf{Q}^{*}=\text{Diag}(\mathbf{u})\exp\left(\frac{\mathbf{C}^{\top}\mathbf{Z}}{\varepsilon}\right)\text{Diag}(\mathbf{v}), (5) where 𝐮 \mathbf{u} and 𝐯 \mathbf{v} are renormalization vectors in ℝ K \mathbb{R}^{K} and ℝ B \mathbb{R}^{B} respectively. The renormalization vectors are computed using a small number of matrix multiplications using the iterative Sinkhorn-Knopp algorithm [ 13 ] . In practice, we observe that using only 3 3 iterations is fast and sufficient to obtain good performance. Indeed, this algorithm can be efficiently implemented on GPU, and the alignment of 4 4 K features to 3 3 K codes takes 35 35 ms in our experiments, see § 4 .

##### Working with small batches.

When the number B B of batch features is too small compared to the number of prototypes K K , it is impossible to equally partition the batch into the K K prototypes. Therefore, when working with small batches, we use features from the previous batches to augment the size of 𝐙 \mathbf{Z} in Prob. ( 3 ). Then, we only use the codes of the batch features in our training loss. In practice, we store around 3 3 K features, i.e ., in the same range as the number of code vectors. This means that we only keep features from the last 15 15 batches with a batch size of 256 256 , while contrastive methods typically need to store the last 65 65 K instances obtained from the last 250 250 batches [ 24 ] .

### 3.2 Multi-crop: Augmenting views with smaller images

As noted in prior works [ 10 , 44 ] , comparing random crops of an image plays a central role by capturing information in terms of relations between parts of a scene or an object. Unfortunately, increasing the number of crops or “views” quadratically increases the memory and compute requirements. We propose a multi-crop strategy where we use two standard resolution crops and sample V V additional low resolution crops that cover only small parts of the image. Using low resolution images ensures only a small increase in the compute cost. Specifically, we generalize the loss of Eq ( 1 ): L ⁡ ( 𝐳 t 1 , 𝐳 t 2 , … , 𝐳 t V + 2 ) = ∑ i ∈ { 1 , 2 } ∑ v = 1 V + 2 𝟏 v ≠ i ​ ℓ ​ ( 𝐳 t v , 𝐪 t i ) . L(\mathbf{z}_{t_{1}},\mathbf{z}_{t_{2}},\dots,\mathbf{z}_{t_{V+2}})=\sum_{i\in\{1,2\}}\sum_{v=1}^{V+2}\mathbf{1}_{v\neq i}\ell(\mathbf{z}_{t_{v}},\mathbf{q}_{t_{i}}). (6) Note that we compute codes using only the full resolution crops. Indeed, computing codes for all crops increases the computational time and we observe in practice that it also alters the transfer performance of the resulting network. An explanation is that using only partial information (small crops cover only small area of images) degrades the assignment quality. Figure 3 shows that multi-crop improves the performance of several self-supervised methods and is a promising augmentation strategy.

## 4 Main Results

We analyze the features learned by SwAV by transfer learning on multiple datasets. We implement in SwAV the improvements used in SimCLR, i.e ., LARS [ 64 ] , cosine learning rate [ 40 , 44 ] and the MLP projection head [ 10 ] . We provide the full details and hyperparameters for pretraining and transfer learning in the Appendix.

### 4.1 Evaluating the unsupervised features on ImageNet

We evaluate the features of a ResNet-50 [ 27 ] trained with SwAV on ImageNet by two experiments: linear classification on frozen features and semi-supervised learning by finetuning with few labels. When using frozen features ( fig. 2 left), SwAV outperforms the state of the art by + 4.2 % +4.2\% top-1 accuracy and is only 1.2 % 1.2\% below the performance of a fully supervised model. Note that we train SwAV during 800 800 epochs with large batches ( 4096 4096 ). We refer to fig. 3 for results with shorter trainings and to table 3 for experiments with small batches. On semi-supervised learning ( table 1 ), SwAV outperforms other self-supervised methods and is on par with state-of-the-art semi-supervised models [ 51 ] , despite the fact that SwAV is not specifically designed for semi-supervised learning.

Variants of ResNet-50. Figure 2 (right) shows the performance of multiple variants of ResNet-50 with different widths [ 35 ] . The performance of our model increases with the width of the model, and follows a similar trend to the one obtained with supervised learning. When compared with concurrent work like SimCLR, we see that SwAV reduces the difference with supervised models even further. Indeed, for large architectures, our method shrinks the gap with supervised training to 0.6 % 0.6\% .

### 4.2 Transferring unsupervised features to downstream tasks

We test the generalization of ResNet-50 features trained with SwAV on ImageNet (without labels) by transferring to several downstream vision tasks. In table 2 , we compare the performance of SwAV features with ImageNet supervised pretraining. First, we report the linear classification performance on the Places205 [ 67 ] , VOC07 [ 17 ] , and iNaturalist2018 [ 54 ] datasets. Our method outperforms supervised features on all three datasets. Note that SwAV is the first self-supervised method to surpass ImageNet supervised features on these datasets. Second, we report network finetuning on object detection on VOC07+12 using Faster R-CNN [ 50 ] with a R50-C4 backbone and on COCO [ 38 ] using Mask R-CNN [ 26 ] with a R50-FPN backbone and finally using DETR detector [ 6 ] . DETR is a recent object detection framework that reaches competitive performance with Faster R-CNN while being conceptually simpler and trainable end-to-end. Interestingly, unlike Faster R-CNN [ 50 ] , using a pretrained backbone for DETR is crucial to obtain good results compared to training from scratch [ 6 ] . In table 2 , we show that SwAV outperforms the supervised pretrained model on both VOC07+12 and COCO datasets. Note that this is line with previous works that also show that self-supervision can outperform supervised pretraining on object detection [ 44 , 24 , 19 ] . We report more detection evaluation metrics and results from other self-supervised methods in the Appendix. Overall, our SwAV ResNet-50 model surpasses supervised ImageNet pretraining on all the considered transfer tasks and datasets. We have released this model so other researchers might also benefit by replacing the ImageNet supervised network with our model.

### 4.3 Training with small batches

We train SwAV with small batches of 256 256 images on 4 4 GPUs and compare with MoCov2 and SimCLR trained in the same setup. In table 3 , we see that SwAV maintains state-of-the-art performance even when trained in the small batch setting. Note that SwAV only stores a queue of 3,840 3,840 features. In comparison, to obtain good performance, MoCov2 needs to store 65,536 65,536 features while keeping an additional momentum encoder network. When SwAV is trained using × 160 + × 96 2\!\times\!160+4\!\times\!96 crops, SwAV has a running time 1.2 × 1.2\times higher than SimCLR with × 224 2\!\times\!224 crops and is around 1.4 × 1.4\times slower than MoCov2 due to the additional back-propagation [ 11 ] . Hence, one epoch of MoCov2 or SimCLR is faster in wall clock time than one of SwAV, but these methods need more epochs for good downstream performance. Indeed, as shown in table 3 , SwAV learns much faster and reaches higher performance in 4 × 4\times fewer epochs: 72 % 72\% after 200 200 epochs ( 102 102 hours) while MoCov2 needs 800 800 epochs to achieve 71.1 % 71.1\% . Increasing the resolution and the number of epochs, SwAV reaches 74.3 % 74.3\% with a small batch size, a small number of stored features and no momentum encoder. Finally, note that SwAV could be combined with a momentum mechanism and a large queue [ 24 ] ; we leave these explorations to future work.

## 5 Ablation Study

### 5.1 Clustering-based self-supervised learning

##### Improving prior clustering-based approaches.

In this section, we re-implement and improve previously published clustering-based models in order to assess if they can compete with recent contrastive methods such as SimCLR. In particular, we consider two clustering-based models: DeepCluster-v2 and SeLa-v2, which are obtained by applying various training improvements introduced in other self-supervised learning papers to DeepCluster [ 7 ] and SeLa [ 2 ] . Among these improvements are the use of stronger data augmentation [ 10 ] , MLP projection head [ 10 ] , cosine learning rate schedule [ 44 ] , temperature parameter [ 58 ] , memory bank [ 58 ] , multi-clustering [ 2 ] , etc. Full implementation details can be found in the Appendix. Besides, we also improve DeepCluster model by introducing explicit comparisons to k-means centroids, which increase stability and performance. Indeed, a main issue in DeepCluster is that there is no correspondance between two consecutive cluster assignments. Hence, the final classification layer learned for an assignment becomes irrelevant for the following one and thus needs to be re-initialized from scratch at each epoch. This considerably disrupts the convnet training. In DeepCluster-v2, instead of learning a classification layer predicting the cluster assignments, we perform explicit comparison between features and centroids.

##### Comparing clustering with contrastive instance learning.

In fig. 3 (left), we make a best effort fair comparison between clustering-based and contrastive instance (SimCLR) methods by implementating these methods with the same data augmentation, number of epochs, batch-sizes, etc. In this setting, we observe that SwAV and DeepCluster-v2 outperform SimCLR by 2 % 2\% without multi-crop and by 3.5 % 3.5\% with multi-crop . This suggests the learning potential of clustering-based methods over instance classification.

##### Advantage of SwAV compared to DeepCluster-v2.

In fig. 3 (left), we observe that SwAV performs on par with DeepCluster-v2. In addition, we train DeepCluster-v2 in SwAV best setting (800 epochs - 8 crops) and obtain 75.2 % 75.2\% top-1 accuracy on ImageNet (versus 75.3 % 75.3\% for SwAV). However, unlike SwAV, DeepCluster-v2 is not online which makes it impractical for extremely large datasets ( § 5.4 ). For billion scale trainings for example, a single pass on the dataset is usually performed [ 24 ] . DeepCluster-v2 cannot be trained for only one epoch since it works by performing several passes on the dataset to regularly update centroids and cluster assignments for each image.

As a matter of fact, DeepCluster-v2 can be interpreted as a special case of our proposed swapping mechanism: swapping is done across epochs rather than within a batch. Given a crop of an image DeepCluster-v2 predicts the assignment of another crop, which was obtained at the previous epoch. SwAV swaps assignments directly at the batch level and can thus work online.

### 5.2 Applying the multi-crop strategy to different methods

In fig. 3 (left), we report the impact of applying our multi-crop strategy on the performance of a selection of other methods. Details of how we apply multi-crop to SimCLR loss can be found in the Appendix. We see that the multi-crop strategy consistently improves the performance for all the considered methods by a significant margin of − 4 % 2\!-\!4\% top-1 accuracy. Interestingly, multi-crop seems to benefit more clustering-based methods than contrastive methods. We note that multi-crop does not improve the supervised model.

### 5.3 Impact of longer training

In fig. 3 (right), we show the impact of the number of training epochs on performance for SwAV with multi-crop . We train separate models for 100 100 , 200 200 , 400 400 and 800 800 epochs and report the top-1 accuracy on ImageNet using the linear classification evaluation. We train each ResNet-50 on 64 64 V100 16GB GPUs and a batch size of 4096 4096 . While SwAV benefits from longer training, it already achieves strong performance after 100 100 epochs, i.e ., 72.1 % 72.1\% in 6h15.

### 5.4 Unsupervised pretraining on a large uncurated dataset

We evaluate SwAV on random, uncurated images that have different properties from ImageNet which allows us to test if our online clustering scheme and multi-crop augmentation work out of the box. In particular, we pretrain SwAV on an uncurated dataset of 1 billion random public non-EU images from Instagram. We test if SwAV can serve as a pretraining method for supervised learning. In fig. 4 (left), we measure the performance of ResNet-50 models when transferring to ImageNet with frozen or finetuned features. We report the results from He et al . [ 24 ] but note that their setting is different. They use a curated set of Instagram images, filtered by hashtags similar to ImageNet labels [ 41 ] . We compare SwAV with a randomly initialized network and with a network pretrained on the same data using SimCLR. We observe that SwAV maintains a similar gain of 6 % 6\% over SimCLR as when pretrained on ImageNet ( fig. 2 ), showing that our improvements do not depend on the data distribution. We also see that pretraining with SwAV on random images significantly improves over training from scratch on ImageNet ( + 1.3 % +1.3\% ) [ 8 , 24 ] . This result is in line with Caron et al . [ 8 ] and He et al . [ 24 ] . In fig. 4 (right), we explore the limits of pretraining as we increase the model capacity. We consider the variants of the ResNeXt architecture [ 61 ] as in Mahajan et al . [ 41 ] . We compare SwAV with supervised models trained from scratch on ImageNet. For all models, SwAV outperforms training from scratch by a significant margin showing that it can take advantage of the increased model capacity. For reference, we also include the results from Mahajan et al . [ 41 ] obtained with a weakly-supervised model pretrained by predicting hashtags filtered to be similar to ImageNet classes. Interestingly, SwAV performance is strong when compared to this topline despite not using any form of supervision or filtering of the data.

## 6 Discussion

Self-supervised learning is rapidly progressing compared to supervised learning, even surpassing it on transfer learning, even though the current experimental settings are designed for supervised learning. In particular, architectures have been designed for supervised tasks, and it is not clear if the same models would emerge from exploring architectures with no supervision. Several recent works have shown that exploring architectures with search [ 39 ] or pruning [ 9 ] is possible without supervision, and we plan to evaluate the ability of our method to guide model explorations.

##### Acknowledgement.

We thank Nicolas Carion, Kaiming He, Herve Jegou, Benjamin Lefaudeux, Thomas Lucas, Francisco Massa, Sergey Zagoruyko, and the rest of Thoth and FAIR teams for their help and fruitful discussions. Julien Mairal was funded by the ERC grant number 714381 (SOLARIS project) and by ANR 3IA MIAI@Grenoble Alpes (ANR-19-P3IA-0003).

