Profile

Settings

Loading…

← Papers

Help

FAQ

Which features require signing in?

You can read the commentary, paper info, Model Structure and related papers of public papers without signing in. Sign in to manage your account or contact us about your inquiries.

Can I upload a PDF file?

Upload papers with an arXiv or DOI link; the commentary is public to everyone. Papers whose source and terms of use can't be verified, so the commentary can't be made public, can't be uploaded. Uploading PDF files and keeping papers private are for subscribers only, and a paper uploaded as a file is saved as private only. Searching for official info by title runs only when you press the button.

Are the figures and AI commentary accurate?

Figures come only from the original paper, and only those whose terms of use are verified are shown. The commentary is written by AI and may be wrong. Check important claims, numbers and figure context against the evidence in the original paper.

I want to report a copyright issue.

Terms of use and the source of the original paper are on the Paper info tab. If there's a problem, choose "Paper content, figures and copyright" under Contact us and send the paper link, the part in question, and evidence that you hold the rights. Receiving your report doesn't confirm any rights or remove anything right away. You can see the result of the review under My inquiries.

I forgot my password.

If you signed up with email, use Forgot password in the sign-in window to reset it with your verified email. If you signed up with Google, Naver or Kakao, change your password with that service.

What should I include in an inquiry?

Tell us which screen you were on and what you were doing when the problem happened, along with the paper link. Don't include personal information such as passwords, API keys, verification codes or phone numbers. Inquiries and replies are stored in Refivu and you can see them under My inquiries.

How do I delete my account?

In Settings, under My account, press Delete account. Review what will be deleted and complete identity verification to delete your account. For other requests, choose "Account" under Contact us.

Paper commentary

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

  • Problem Transformers have become the standard in language processing, but computer vision still relies mainly on convolutional networks, and it is unclear whether a plain Transformer can classify images well.
  • Method Splits each image into fixed-size patches, maps them linearly to vectors, adds a class token and position embeddings, and runs the sequence through a standard Transformer encoder that is pre-trained on large supervised datasets and then fine-tuned.
  • Results Reached 88.55 ± 0.04 accuracy on ImageNet with ViT-H/14 pre-trained on JFT-300M, as the mean over three fine-tuning runs.

Why use a plain Transformer on images

In language processing the usual recipe is to learn broadly from a large body of text first and then adapt the same network to a narrower task. Vision research still builds mostly on convolutional networks. Attention has been added to them, or used to replace parts of them. Designs that drop convolutions entirely look efficient in theory, but their specialized attention patterns have not scaled well on modern hardware accelerators.

The authors ask whether a standard Transformer, changed as little as possible, can work on images once each image is cut into patches and every patch is handled like a token. Trained on mid-sized data such as ImageNet without strong regularization, this setup lands a few percentage points below ResNets of comparable size. The authors attribute this to Transformers lacking inductive biases such as translation equivariance and locality, which hurts generalization when training data is insufficient.

With pre-training on 14M-300M images the picture changes, and the authors find that large-scale training outweighs the inductive bias.

Turning an image into a token sequence

An image of height H, width W and C channels is reshaped into a sequence of flattened 2D patches, each of size P by P. The number of patches is N = HW/P², and N also sets the effective input length for the Transformer. Formally, \(x \in \mathbb{R}^{H\times W\times C}\) becomes \(x_p \in \mathbb{R}^{N\times(P^2\cdot C)}\), so each row of \(x_p\) is one flattened patch.

Figure 1 summarizes this path from patches to the encoder and the classification head.

A trainable linear projection E maps each flattened patch to D dimensions, and the outputs are the patch embeddings. The latent width D stays constant through all layers. A learnable class embedding is prepended to the sequence, and learnable position embeddings are added to every entry, giving the input sequence below. The position embeddings are learned in one dimension, since the authors found no significant gain from more advanced 2D-aware variants.

During pre-training the head is an MLP with one hidden layer, and during fine-tuning it is a single linear layer.

Encoder layers and where image structure enters

The encoder alternates multiheaded self-attention (MSA) blocks and MLP blocks, with layer normalization placed before each block and a residual connection after each one. \[ z'_\ell = MSA(LN(z_{\ell-1})) + z_{\ell-1}, \quad \ell = 1 \ldots L \] \[ z_\ell = MLP(LN(z'_\ell)) + z'_\ell, \quad \ell = 1 \ldots L \]

In ViT only the MLP layers are local and translation-equivariant, while self-attention is global. The two-dimensional structure enters at two points: the cut into patches at the start, and the interpolation of position embeddings when the input resolution changes during fine-tuning.

As an alternative to raw patches, the input sequence can be built from CNN feature maps, with the patch embedding projection E applied to patches taken from the feature map. A 1x1 patch size on the feature map flattens its spatial dimensions and projects them to the Transformer width. In the hybrid models of the experiments, the intermediate feature maps of a ResNet are fed into ViT with a patch size of one pixel on that map.

Fine-tuning, resolution and training settings

For a downstream task the pre-trained prediction head is removed and a zero-initialized feedforward layer of size D×K is attached, where K is the number of downstream classes. Fine-tuning at a higher resolution keeps the patch size, so the sequence gets longer. The pre-trained position embeddings are then 2D-interpolated according to each patch's location in the original image.

All models, including the ResNets, are trained with Adam using beta1 = 0.9, beta2 = 0.999, a batch size of 4096 and a weight decay of 0.1, with a linear learning rate warmup and decay. Fine-tuning uses SGD with momentum and a batch size of 512 for all models. For the ImageNet results in Table 2, ViT-L/16 was fine-tuned at resolution 512 and ViT-H/14 at 518, with Polyak averaging at a factor of 0.9999.

A name such as ViT-L/16 gives the size and the patch size, and because the sequence length goes with the inverse square of the patch size, smaller patches cost more compute. The CNN baseline is ResNet (BiT), a ResNet with Group Normalization in place of Batch Normalization and standardized convolutions.

Benchmark results against CNN baselines

ViT-H/14 pre-trained on JFT-300M reached 88.55 ± 0.04 on ImageNet, 90.72 ± 0.05 on ImageNet ReaL, 94.55 ± 0.04 on CIFAR-100 and 77.63 ± 0.23 on the VTAB suite. These are means and standard deviations over three fine-tuning runs, and the pre-training cost was 2.5k TPUv3-core-days.

ViT-L/16 pre-trained on JFT-300M reached 87.76 ± 0.03 on ImageNet, 93.90 ± 0.05 on CIFAR-100 and 76.28 ± 0.46 on VTAB, at 0.68k TPUv3-core-days. BiT-L, pre-trained on the same dataset, is listed at 87.54 ± 0.02 on ImageNet and at 9.9k TPUv3-core-days. The text says ViT-L/16 on JFT-300M outperforms BiT-L on all tasks, but the VTAB entries in Table 2 are 76.28 for ViT-L/16 and 76.29 for BiT-L.

ViT-L/16 pre-trained on ImageNet-21k reached 85.30 ± 0.02 on ImageNet, 93.25 ± 0.05 on CIFAR-100 and 72.72 ± 0.21 on VTAB, at 0.23k TPUv3-core-days. The authors estimate that this model could be trained on a standard cloud TPUv3 with 8 cores in about 30 days.

The authors describe Noisy Student as the state of the art on ImageNet at the time, and BiT-L as the best on the other datasets reported. All models were trained on TPUv3 hardware, and cost is counted as the number of cores, two per chip, times training days.

Figure 2 splits VTAB into Natural, Specialized and Structured groups and compares ViT-H/14 with BiT, VIVI and S4L. ViT-H/14 outperforms BiT-R152x4 and the other methods on the Natural and Structured tasks, while the top two models are similar on the Specialized tasks.

How pre-training dataset size changes the picture

The first series pre-trains on ImageNet, ImageNet-21k and JFT-300M, with weight decay, dropout and label smoothing tuned to help the smaller datasets. On ImageNet, ViT-Large models underperform ViT-Base models despite moderate regularization. With ImageNet-21k their performance is similar, and only JFT-300M shows the full benefit of the larger models.

Early stopping is used, the best validation accuracy during training is reported, and few-shot linear accuracy stands in for full fine-tuning to save compute. The authors read this as evidence that a convolutional inductive bias helps on smaller datasets, while learning patterns directly from data is enough, and even beneficial, on larger ones.

Performance against pre-training compute

The scaling study pre-trains 7 ResNets, 6 Vision Transformers and 5 hybrids on JFT-300M, mostly for 7 epochs, with a few of the larger models pre-trained for 14 epochs.

Vision Transformers dominate ResNets on the performance-compute trade-off, using 2-4× less compute to reach the same average transfer performance over five datasets. Performance is plotted against total pre-training compute in exaFLOPs, and the figure shows Vision Transformers generally above ResNets at the same budget.

Vision Transformers do not appear to saturate within the range tried, which the authors take as motivation for future scaling efforts.

What the learned representations encode

The top principal components of the learned RGB embedding filters of ViT-L/32 look like plausible basis functions for the fine structure within a patch. The figure also shows the cosine similarity of position embeddings for ViT-L/32, and the attention distance per head and layer for ViT-L/16.

The learned position embeddings encode distance within the image, so closer patches have more similar embeddings. Patches in the same row or column also have similar embeddings. A sinusoidal structure is sometimes visible for larger grids. The authors connect this 2D topology encoding to the lack of gains from hand-crafted 2D-aware embedding variants.

Attention distance is the average distance in image space across which a head integrates information, computed from its attention weights, and it is analogous to receptive field size in CNNs. Some heads already attend to most of the image in the lowest layers, while other heads keep small attention distances in the low layers. This localized attention is less pronounced in hybrid models, and attention distance grows with network depth.

Self-supervised pre-training

A preliminary branch applies masked patch prediction, modelled on the masked language modeling task used in BERT, to ViT-B/16 before fine-tuning on ImageNet. ViT-B/16 reaches 79.9% accuracy on ImageNet with this self-supervised pre-training, about 2% above training from scratch and about 4% below supervised pre-training. Contrastive pre-training was left to future work.

Limitations

The authors note that pre-training efficiency may depend on the training schedule, optimizer and weight decay as well as on the architecture, so the compute comparisons do not isolate architecture alone. The 30-day training estimate for ViT-L/16 on ImageNet-21k is the authors' own estimate.

Experiments cover ImageNet, CIFAR-10 and CIFAR-100, Oxford-IIIT Pets, Oxford Flowers-102 and the 19-task VTAB suite. Detection and segmentation were not tested, and the authors list them as challenges for ViT. The self-supervised experiment is preliminary, and the gap to large-scale supervised pre-training is still large. Few-shot and low-data results are described as promising, and further analysis of few-shot properties is left to future work.

Paper info

Authors
Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, Matthias Minderer, Georg Heigold, Sylvain Gelly, Jakob Uszkoreit, Neil Houlsby
Venue
arXiv · Preprint
First published
2020-10-22
Added
2026-10-20
Updated
2021-6-3
Version
v2
arXiv
2010.11929
Category
cs.CV · cs.AI · cs.LG
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

Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, Matthias Minderer, Georg Heigold, Sylvain Gelly, Jakob Uszkoreit, Neil Houlsby (2020). An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale. arXiv:2010.11929v2. https://arxiv.org/abs/2010.11929v2

BibTeX
@misc{dosovitskiy2020image,
  title = {{An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale}},
  author = {Alexey Dosovitskiy and Lucas Beyer and Alexander Kolesnikov and Dirk Weissenborn and Xiaohua Zhai and Thomas Unterthiner and Mostafa Dehghani and Matthias Minderer and Georg Heigold and Sylvain Gelly and Jakob Uszkoreit and Neil Houlsby},
  year = {2020},
  eprint = {2010.11929},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2010.11929v2}
}

See related papersBrowse other papers

Paper preview
Account security

Connect Google account

If you connect a Google account, you can sign in with it too.

Refivu

Delete account

Refivu
Refivu

Sign up