Going deeper with Image Transformers

Hugo Touvron, Matthieu Cord, Alexandre Sablayrolles, Gabriel Synnaeve, Hervé JégouICCV 2021

Abstract

Transformers have been recently adapted for large scale image classification, achieving high scores shaking up the long supremacy of convolutional neural networks. However the optimization of image transformers has been little studied so far. In this work, we build and optimize deeper transformer networks for image classification. In particular, we investigate the interplay of architecture and optimization of such dedicated transformers. We make two transformers architecture changes that significantly improve the accuracy of deep transformers. This leads us to produce models whose performance does not saturate early with more depth, for instance we obtain 86.5% top-1 accuracy on Imagenet when training with no external data, we thus attain the current SOTA with less FLOPs and parameters. Moreover, our best model establishes the new state of the art on Imagenet with Reassessed labels and Imagenet-V2 / match frequency, in the setting with no additional training data. We share our code and models.

Introduction

While Vision Transformers (ViTs) have emerged as powerful alternatives to Convolutional Neural Networks (CNNs), they have historically struggled with a phenomenon known as "depth saturation." Unlike CNNs, which consistently benefit from increased depth, standard ViT architectures often experience diminishing returns or optimization failures when scaled beyond 12 to 24 layers. This limitation has prevented Transformers from reaching their full potential in large-scale image classification.

This research identifies two primary bottlenecks: optimization instability in deep networks and the interference caused by the early introduction of the class token. To address these, the authors introduce two architectural innovations: LayerScale and Class-Attention in Image Transformers (CaiT). Together, these modifications allow ViTs to scale effectively to 48 layers and beyond, achieving state-of-the-art performance on ImageNet-1k without the need for massive external datasets.

Overcoming Optimization Instability with LayerScale

As Transformers grow deeper, training dynamics become increasingly volatile. The authors propose LayerScale to stabilize the optimization process. In a standard Transformer block, the output of a residual branch is added directly to the main path. LayerScale modifies this by multiplying the output of each residual block—both the Self-Attention and the Feed-Forward Network—by a learnable diagonal matrix.

These diagonal values are initialized to a very small constant (typically $10^{-5}$ or $10^{-6}$ depending on depth). This initialization forces the network to behave nearly like an identity function at the start of training, allowing the model to gradually integrate the contributions of the residual branches. Unlike previous methods like ReZero, which use a single scalar for the entire layer, LayerScale provides per-channel scaling. This added granularity offers more degrees of freedom, which the researchers found essential for successfully training very deep Transformer architectures.

Decoupling Features and Classification: The CaiT Architecture

In standard ViT designs, a "class token" is prepended to the image patches at the first layer. This forces the network to perform two distinct tasks simultaneously throughout its entire depth: modeling the spatial relationships between image patches and summarizing that information for the final classifier. This dual objective can lead to "contradictory objectives" that hamper feature extraction.

The proposed CaiT architecture solves this by separating the processing into two distinct stages:

  1. Self-Attention Stage: The model processes only the image patches through the majority of the network's layers. By excluding the class token from these early layers, the self-attention mechanism can focus entirely on modeling spatial relationships and extracting rich visual features.
  2. Class-Attention Stage: The class token is introduced only in the final few layers (typically the last two). In this stage, the class token "attends" to the patches to extract the information necessary for classification. Crucially, the patches themselves are kept frozen during this stage; they provide information to the class token but are no longer updated.

This encoder-decoder style approach prevents the classification objective from "polluting" the early feature extraction process, leading to more efficient and effective learning.

Experimental Results and Benchmarks

The researchers evaluated their models primarily on ImageNet-1k, using the standard 1.2 million images without any external data (such as JFT-300M). They also tested robustness using ImageNet-Real and ImageNet-V2.

Performance Highlights

  • State-of-the-Art Accuracy: The CaiT-M48 model achieved a 86.5% top-1 accuracy on ImageNet-1k. This is particularly notable as it surpasses previous benchmarks without relying on additional training data.
  • Efficiency: CaiT models demonstrate superior efficiency compared to massive concurrent models like NFNet-F6, achieving higher accuracy with significantly fewer parameters and FLOPs.
  • Scaling Success: With LayerScale, the authors successfully trained models with up to 48 layers, proving that ViTs can indeed benefit from extreme depth when the optimization path is properly stabilized.
  • Robustness: The models established new state-of-the-art results on reassessed labels (ImageNet-Real), suggesting that deeper architectures generalize better and are less susceptible to label noise.

Conclusion

The introduction of LayerScale and Class-Attention marks a significant step forward in the evolution of Vision Transformers. By addressing the fundamental issues of optimization stability and objective interference, this work demonstrates that Transformers can be scaled to depths previously reserved for CNNs. The resulting CaiT models not only set new performance records on ImageNet but also provide a more efficient blueprint for future transformer-based architectures in computer vision. The separation of "processing" and "summarizing" stages in CaiT offers a promising direction for tasks beyond classification, such as object detection and semantic segmentation, where maintaining spatial integrity is paramount.

Summary updated

BibTeX
@inproceedings{touvron2021going,
  author = {Hugo Touvron and Matthieu Cord and Alexandre Sablayrolles and Gabriel Synnaeve and Hervé Jégou},
  title = {{Going deeper with Image Transformers}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2021},
  url = {https://openreview.net/forum?id=3MZoHWMZKNa},
}
Figure