ConViT: Improving Vision Transformers with Soft Convolutional Inductive Biases

Stéphane d'Ascoli, Hugo Touvron, Matthew L. Leavitt, Ari S. Morcos, Giulio Biroli, Levent Sagun

TL;DR

ConViT introduces a "soft" convolutional inductive bias into Vision Transformers (ViTs) through a new mechanism called Gated Positional Self-Attention (GPSA). By initializing layers to act like convolutions and allowing them to learn when to "escape" locality, ConViT achieves significantly better sample efficiency and higher accuracy than standard ViTs, especially on smaller datasets.

What Problem Does This Paper Address?

For years, Computer Vision was dominated by Convolutional Neural Networks (CNNs). CNNs possess "hard" inductive biases—specifically locality (pixels near each other are related) and weight sharing—which make them incredibly efficient at learning from limited data. However, these same biases can act as a "performance ceiling" because they restrict the model's ability to capture global context.

Vision Transformers (ViTs) recently challenged this dominance by using global self-attention, which has almost no spatial prior. While ViTs can outperform CNNs on massive datasets (like JFT-300M), they are notoriously data-hungry. Without millions of images, they struggle to learn the basic spatial structure of images that CNNs get for free. The authors of ConViT ask: Can we get the sample efficiency of a CNN and the high performance ceiling of a Transformer in one architecture?

Conceptual comparison of hard vs. soft inductive biases across dataset and model sizes.

Methods

The authors introduce Gated Positional Self-Attention (GPSA). This is the "secret sauce" of ConViT.

  1. Convolutional Initialization: Instead of starting with random weights, the GPSA layers are initialized so that each attention head mimics a specific part of a convolutional kernel. For example, one head might focus on the patch to the left, another on the patch above, and so on.
  2. Gating Mechanism: The paper introduces a learnable gating parameter ($\lambda$). This parameter allows each attention head to decide the balance between positional information (the "convolutional" part) and content information (the "transformer" part).
  3. Soft Bias: Unlike a standard CNN where locality is forced by the architecture, this bias is "soft." If the data suggests that global context is more important than local pixels, the model can simply learn to ignore the positional gate and behave like a standard Transformer.

The architecture of ConViT replaces early self-attention layers with these GPSA layers, allowing the model to dynamically choose between local and global processing.

Datasets

The models were primarily evaluated on:

  • ImageNet-1k: The standard benchmark for image classification.
  • Subsampled ImageNet: To test sample efficiency, the authors trained on fractions of the dataset (5%, 10%, 30%, and 50%).
  • CIFAR-100: Used to verify performance on smaller-scale datasets.

Key Insights and Ideas

  • The "Best of Both Worlds" is Real: Hard biases (CNNs) are helpful when data is scarce but can become harmful when data is plentiful. Soft biases (ConViT) remain helpful in low-data regimes but "vanish" when they are no longer needed, allowing the model to reach higher accuracy.
  • Locality is for the Young (Layers): The authors found that locality is most beneficial in the early layers of the network. In ConViT, the first 10 layers are GPSA, while the final layers remain standard global self-attention.
  • Transformers Want to be Local: Interestingly, the authors observed that even standard ViTs naturally try to become "local" during the first few epochs of training. ConViT simply gives them a "head start" by initializing them that way.
  • Interpretability: The gating parameter provides a window into the model’s "thought process." By looking at $\lambda$, researchers can see exactly at which layer and in which head the model decides to stop looking at local pixels and start looking at the whole image.

Key Results

ConViT consistently outperforms the Data-efficient Image Transformer (DeiT), which was the previous state-of-the-art for training ViTs on ImageNet without massive external data.

  • Accuracy: ConViT-S achieves 81.3% top-1 accuracy on ImageNet, outperforming DeiT-S (79.8%) with a similar number of parameters.
  • Sample Efficiency: This is where ConViT shines. When trained on only 10% of ImageNet, ConViT-S reaches 59.6% accuracy, while DeiT-S lags far behind at 48.0%.
  • Parameter Efficiency: ConViT models generally achieve higher accuracy than CNNs (like ResNet) and other ViTs for a given parameter count.
Sample and parameter efficiency of ConViT compared to DeiT and other baselines.

Limitations and Future Work

  • Throughput: While ConViT is parameter-efficient, the GPSA layers are computationally more complex than standard self-attention. This results in a lower "throughput" (images processed per second) compared to vanilla ViTs.
  • Class Token: The authors noted that the standard "class token" approach doesn't play well with positional attention, requiring them to append the class token only after the GPSA layers.
  • Future Directions: The authors suggest exploring whether initializing Transformers with pre-trained convolutional weights (rather than just the convolutional structure) could further boost performance. They also propose applying this "soft bias" concept to other domains beyond computer vision.

Summary updated

BibTeX
@inproceedings{dascoli2021convit,
  author = {Stéphane d'Ascoli and Hugo Touvron and Matthew L. Leavitt and Ari S. Morcos and Giulio Biroli and Levent Sagun},
  title = {{ConViT: Improving Vision Transformers with Soft Convolutional Inductive Biases}},
  booktitle = {International Conference on Machine Learning},
  year = {2021},
  url = {https://openreview.net/forum?id=fnxCDgrKBT5},
}
Figure