arXiv(opens in a new tab)Computer ScienceOct 2020Cited by 367 papers on PaperVantageClassic Paper

Manuscript Offprint

arXiv:2010.11929

An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale

Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, M. Minderer, G. Heigold, S. Gelly, Jakob Uszkoreit, N. Houlsby

Abstract

While the Transformer architecture has become the de-facto standard for natural language processing tasks, its applications to computer vision remain limited. In vision, attention is either applied in conjunction with convolutional networks, or used to replace certain components of convolutional networks while keeping their overall structure in place. We show that this reliance on CNNs is not necessary and a pure transformer applied directly to sequences of image patches can perform very well on image classification tasks. When pre-trained on large amounts of data and transferred to multiple mid-sized or small image recognition benchmarks (ImageNet, CIFAR-100, VTAB, etc.), Vision Transformer (ViT) attains excellent results compared to state-of-the-art convolutional networks while requiring substantially fewer computational resources to train.

1 Introduction

Self-attention-based architectures, in particular Transformers (Vaswani et al., 2017), have become the model of choice in natural language processing (NLP). The dominant approach is to pre-train on a large text corpus and then fine-tune on a smaller task-specific dataset (Devlin et al., 2019). Thanks to Transformers’ computational efficiency and scalability, it has become possible to train models of unprecedented size, with over 100B parameters (Brown et al., 2020; Lepikhin et al., 2020). With the models and datasets growing, there is still no sign of saturating performance.

In computer vision, however, convolutional architectures remain dominant (LeCun et al., 1989; Krizhevsky et al., 2012; He et al., 2016). Inspired by NLP successes, multiple works try combining CNN-like architectures with self-attention (Wang et al., 2018; Carion et al., 2020), some replacing the convolutions entirely (Ramachandran et al., 2019; Wang et al., 2020a). The latter models, while theoretically efficient, have not yet been scaled effectively on modern hardware accelerators due to the use of specialized attention patterns. Therefore, in large-scale image recognition, classic ResNet-like architectures are still state of the art (Mahajan et al., 2018; Xie et al., 2020; Kolesnikov et al., 2020).

Inspired by the Transformer scaling successes in NLP, we experiment with applying a standard Transformer directly to images, with the fewest possible modifications. To do so, we split an image into patches and provide the sequence of linear embeddings of these patches as an input to a Transformer. Image patches are treated the same way as tokens (words) in an NLP application. We train the model on image classification in supervised fashion.

When trained on mid-sized datasets such as ImageNet without strong regularization, these models yield modest accuracies of a few percentage points below ResNets of comparable size. This seemingly discouraging outcome may be expected: Transformers lack some of the inductive biases inherent to CNNs, such as translation equivariance and locality, and therefore do not generalize well when trained on insufficient amounts of data.

However, the picture changes if the models are trained on larger datasets (14M-300M images). We find that large scale training trumps inductive bias. Our Vision Transformer (ViT) attains excellent results when pre-trained at sufficient scale and transferred to tasks with fewer datapoints. When pre-trained on the public ImageNet-21k dataset or the in-house JFT-300M dataset, ViT approaches or beats state of the art on multiple image recognition benchmarks. In particular, the best model reaches the accuracy of 88.55%88.55\% on ImageNet, 90.72%90.72\% on ImageNet-ReaL, 94.55%94.55\% on CIFAR-100, and 77.63%77.63\% on the VTAB suite of 19 tasks.

References (55)

  • Quantifying attention flow in transformers
  • Learning representations by maximizing mutual information across views
  • Adaptive input representations for neural language modeling
  • Attention augmented convolutional networks
  • Are we done with imagenet? arXiv, 2020
  • End-to-end object detection with transformers
  • Generative pretraining from pixels
  • A simple framework for contrastive learning of visual representations
  • UNITER: UNiversal Image-TExt Representation Learning
  • Generating long sequences with sparse transformers
  • On the relationship between self-attention and convolutional layers
  • Imagenet: A large-scale hierarchical image database
  • BERT: Pre-training of deep bidirectional transformers for language understanding
  • On robustness and transferability of convolutional neural networks
  • Deep residual learning for image recognition
  • Momentum contrast for unsupervised visual representation learning
  • Axial attention in multidimensional transformers
  • Relation networks for object detection
  • Local relation networks for image recognition
  • Ccnet: Criss-cross attention for semantic segmentation
  • Data-efficient image recognition with contrastive predictive coding
  • Batch normalization: Accelerating deep network training by reducing internal covariate shift
  • Kingma and Jimmy Ba
  • Big transfer (BiT): General visual representation learning
  • Imagenet classification with deep convolutional neural networks
  • Backpropagation applied to handwritten zip code recognition
  • Gshard: Scaling giant models with conditional computation and automatic sharding
  • VisualBERT: A Simple and Performant Baseline for Vision and Language
  • Object-centric learning with slot attention
  • ViLBERT: Pretraining Task-Agnostic Visiolinguistic Representations for Vision-and-Language Tasks
  • Exploring the limits of weakly supervised pretraining
  • Automated flower classification over a large number of classes
  • Cats and dogs
  • Image transformer
  • Acceleration of stochastic approximation by averaging (opens the publisher in a new tab)
  • Weight standardization (opens arXiv in a new tab)
  • Improving language understanding with unsupervised learning
  • Language models are unsupervised multitask learners
  • Stand-alone self-attention in vision models
  • Revisiting unreasonable effectiveness of data in deep learning era
  • Videobert: A joint model for video and language representation learning
  • Fixing the train-test resolution discrepancy
  • Fixing the train-test resolution discrepancy: Fixefficientnet (opens arXiv in a new tab)
  • Self-supervised learning of video-induced visual invariances
  • Attention is all you need
  • Axial-deeplab: Stand-alone axial-attention for panoptic segmentation
  • Axial-deeplab: Stand-alone axial-attention for panoptic segmentation (opens arXiv in a new tab)
  • Learning deep transformer models for machine translation
  • Non-local neural networks
  • Scaling autoregressive video models
  • Visual transformers: Token-based image representation and processing for computer vision
  • Group normalization
  • Self-training with noisy student improves imagenet classification
  • S4L: Self-Supervised Semi-Supervised Learning
  • Exploring self-attention for image recognition

Cited by (367)