arXiv(opens in a new tab)Computer ScienceApr 2021Cited by 7 papers on PaperVantage

Manuscript Offprint

arXiv:2104.02057

An Empirical Study of Training Self-Supervised Vision Transformers

Xinlei Chen, Saining Xie, Kaiming He

Abstract

This paper does not describe a novel method. Instead, it studies a straightforward, incremental, yet must-know baseline given the recent progress in computer vision: self-supervised learning for Vision Transformers (ViT). While the training recipes for standard convolutional networks have been highly mature and robust, the recipes for ViT are yet to be built, especially in the self-supervised scenarios where training becomes more challenging. In this work, we go back to basics and investigate the effects of several fundamental components for training self-supervised ViT. We observe that instability is a major issue that degrades accuracy, and it can be hidden by apparently good results. We reveal that these results are indeed partial failure, and they can be improved when training is made more stable. We benchmark ViT results in MoCo v3 and several other self-supervised frameworks, with ablations in various aspects. We discuss the currently positive evidence as well as challenges and open questions. We hope that this work will provide useful data points and experience for future research.

Code: https://github.com/facebookresearch/moco-v3

1 Introduction

Unsupervised pre-training has revolutionized natural language processing (NLP) [37, 15, 38, 4]. In computer vision, the un-/self-supervised pre-training paradigms differ from their NLP counterparts in at least two aspects: (i) the learners in NLP are masked auto-encoders, while in vision the recently popular choices are Siamese networks (e.g., [20, 10, 18, 7]); (ii) the backbone architectures in NLP are self-attentional Transformers [43], while in vision the common choice is convolutional [28]—yet non-attentional—deep residual networks (ResNets) [21]. To complete the big picture of self-supervised learning in vision, and towards closing the gap of pre-training methodology between vision and language, it is of scientific merit to investigate these differences.

This work focuses on training Transformers with the leading self-supervised frameworks in vision. This investigation is a straightforward extension given the recent progress on Vision Transformers (ViT) [16]. In contrast to prior works [9, 16] that train self-supervised Transformers with masked auto-encoding, we study the frameworks that are based on Siamese networks, including MoCo [20] and others [10, 18, 7].

Unlike standard convolutional networks whose training practice has been extensively studied thanks to continuous community effort, ViT models are new and their recipes are yet to be established. In this work, we go back to basics and investigate the fundamental components of training deep neural networks: the batch size, learning rate, and optimizer. We find that under various cases, instability is a major issue that impacts self-supervised ViT training.

Interestingly, we observe that unstable ViT training may not result in catastrophic failure (e.g., divergence); instead, it can cause mild degradation in accuracy (e.g., 1∼\scriptstyle\sim3%). Such a degree of degradation may not be noticeable, unless a more stable counterpart is available for comparison. To the best of our knowledge, this phenomena is rare in the literature of training convolutional networks, and we believe this problem and its hidden degradation are worth noticing.

frameworkmodelparamsacc. (%)
linear probing:
iGPT [9]iGPT-L1362M69.0
iGPT [9]iGPT-XL6801M72.0
MoCo v3ViT-B86M76.7
MoCo v3ViT-L304M77.6
MoCo v3ViT-H632M78.1
MoCo v3ViT-BN-H632M79.1
MoCo v3ViT-BN-L/7304M81.0
end-to-end fine-tuning:
masked patch pred. [16]ViT-B86M79.9†
MoCo v3ViT-B86M83.2
MoCo v3ViT-L304M84.1

Table 1: State-of-the-art Self-supervised Transformers in ImageNet classification, evaluated by linear probing (top panel) or end-to-end fine-tuning (bottom panel). Both iGPT [9] and masked patch prediction [16] belong to the masked auto-encoding paradigm. MoCo v3 is a contrastive learning method that compares two (224×\times224) crops. ViT-B, -L, -H are the Vision Transformers proposed in [16]. ViT-BN is modified with BatchNorm, and “/7” denotes a patch size of 7×\times7. †: pre-trained in JFT-300M.

To demonstrate the possible harm of instability, we investigate a simple trick that can improve stability in practice. Based on an empirical observation on gradient changes, we freeze the patch projection layer in ViT, i.e., we use fixed random patch projection. We empirically show that this trick alleviates the instability issue in several scenarios and consistently increases accuracy.

We benchmark and ablate self-supervised ViT in a variety of cases. We provide ViT results in several self-supervised frameworks. We conduct ablations on architecture designs and discuss the implications. Furthermore, we explore scaling up the ViT models, including the non-trivial ViT-Large and ViT-Huge [16] — the latter has 40×\times more computation than ResNet-50 [21]. Based on these experimental results, we discuss both the currently positive evidence as well as the challenges and open questions.

We report that self-supervised Transformers can achieve strong results using a contrastive learning framework, compared against masked auto-encoding (Table 1). This behavior of Transformers differs from the existing trend in NLP. Moreover, as a promising signal, our bigger self-supervised ViT can achieve better accuracy, unlike the ImageNet-supervised ViT in [16] whose accuracy degrades if getting bigger. For instance, for the very big ViT-Large, our self-supervised pre-training can outperform its supervised pre-training counterpart for transfer learning in certain cases. This presents a proof-of-concept scenario where self-supervised pre-training is needed.

In addition, we report that our self-supervised ViT models have competitive results vs. the big convolutional ResNets in prior art [11, 18]. On one hand, this comparison shows the potential of ViT, especially considering that it achieves these results using relatively “fewer inductive biases” [16]. On the other hand, we suggest that there could be room for self-supervised ViT models to further improve. As one example, we observe that removing the position embedding in ViT only degrades accuracy by a small margin. This reveals that self-supervised ViT can learn strong representations without the positional inductive bias, but it also implies that the positional information has not been sufficiently exploited.

In summary, we believe that the evidence, challenges, and open questions in this study are worth knowing, if self-supervised Transformers will close the gap in pre-training between vision and language. We hope our data points and experience will be useful to push this frontier.

References (46)

  • Layer Normalization
  • Learning representations by maximizing mutual information across views
  • Signature verification using a “Siamese” time delay neural network
  • Language models are few-shot learners
  • Gcnet: Non-local networks meet squeeze-excitation networks and beyond
  • End-to-end object detection with Transformers
  • Unsupervised learning of visual features by contrasting cluster assignments
  • Emerging Properties in Self-Supervised Vision Transformers
  • Generative pretraining from pixels
  • A simple framework for contrastive learning of visual representations
  • Big self-supervised models are strong semi-supervised learners
  • Improved baselines with momentum contrastive learning (opens arXiv in a new tab)
  • Exploring simple Siamese representation learning
  • ImageNet: A large-scale hierarchical image database
  • BERT: Pre-training of deep bidirectional transformers for language understanding
  • An image is worth 16x16 words: Transformers for image recognition at scale
  • Accurate, large minibatch SGD: Training ImageNet in 1 hour (opens arXiv in a new tab)
  • Bootstrap your own latent - a new approach to self-supervised learning
  • Dimensionality reduction by learning an invariant mapping
  • Momentum contrast for unsupervised visual representation learning
  • Deep residual learning for image recognition
  • Learning deep representations by mutual information estimation and maximization
  • Batch normalization: Accelerating deep network training by reducing internal covariate shift
  • Big Transfer (BiT): General visual representation learning
  • One weird trick for parallelizing convolutional neural networks
  • Backpropagation applied to handwritten zip code recognition
  • Selective kernel networks
  • SGDR: Stochastic gradient descent with warm restarts
  • Decoupled weight decay regularization
  • Rectified linear units improve restricted boltzmann machines
  • Automated flower classification over a large number of classes
  • Representation Learning with Contrastive Predictive Coding
  • Cats and dogs
  • Improving language understanding by generative pre-training
  • Language models are unsupervised multitask learners
  • Stand-alone self-attention in vision models
  • Weight normalization: A simple reparameterization to accelerate training of deep neural networks
  • Video Google: a text retrieval approach to object matching in videos
  • Training data-efficient image transformers & distillation through attention
  • Attention is all you need
  • Non-local neural networks
  • Unsupervised feature learning via non-parametric instance discrimination
  • Unsupervised embedding learning via invariant and spreading instance feature
  • Large batch training of convolutional networks (opens arXiv in a new tab)
  • Large batch optimization for deep learning: Training bert in 76 minutes
  • Exploring self-attention for image recognition