TL;DR
Vision Transformers (ViTs) typically require massive datasets to outperform Convolutional Neural Networks (CNNs) because they lack built-in "inductive biases" like spatial locality. This paper introduces a simple, self-supervised auxiliary task—predicting the relative distance between image patches—that allows ViTs to learn spatial relationships efficiently. This approach leads to massive accuracy gains (up to 45%) when training on small-to-medium datasets.
The Problem: The "Data Hunger" of Transformers
While CNNs have spatial awareness baked into their architecture via sliding windows that look at local pixels, standard Vision Transformers treat an image like a sequence of independent tokens.
Because ViTs don't inherently "know" that adjacent patches in an image are related, they have to learn these spatial rules from scratch. This makes them incredibly data-hungry; the original ViT required hundreds of millions of images to beat a standard ResNet. For researchers and engineers working with niche or small datasets (like medical imaging or specific industrial parts), ViTs were often impractical compared to tried-and-true CNNs.
Methods: Dense Relative Localization
The authors propose a "plug-and-play" regularization technique called Dense Relative Localization ($\mathcal{L}_{drloc}$).
- The Task: During training, the model is given a standard supervised task (like classifying an image as a "dog"). Simultaneously, it is given a self-supervised "pretext" task: look at two random patches (tokens) from the image and guess how far apart they are in 2D space.
- The Mechanism: The final grid of token embeddings is used. The authors randomly sample $m$ pairs of tokens. These pairs are concatenated and passed through a small, two-layer Multi-Layer Perceptron (MLP) that predicts their normalized horizontal and vertical distance.
- The Loss: An $L_1$ loss is calculated between the predicted distance and the actual geometric distance. This loss is added to the standard cross-entropy classification loss.
- Why it works: To guess the distance between two patches, the network is forced to encode both local details (to identify what the patch is) and global context (to understand where that patch sits in the overall "map" of the image).
Datasets Evaluated
The authors conducted an extensive evaluation across 11 different datasets to prove the method's robustness:
- Standard Benchmarks: ImageNet-1K and its subset ImageNet-100.
- Small-scale Datasets: CIFAR-10, CIFAR-100, SVHN (digits), and Oxford Flowers102.
- DomainNet: A collection of six diverse domains (ClipArt, Infograph, Painting, Quickdraw, Real, Sketch) used to test how well the models handle significant "domain shifts."
Key Insights
- Learning the Bias: Instead of hard-coding convolutional layers into the Transformer, this method teaches the model the spatial logic it lacks.
- Sample Efficiency: Because the task is "dense"—meaning you can sample dozens of pairs from a single image—the model gets much more "signal" out of every single training image compared to standard classification.
- Architecture Agnostic: The authors tested this on three major ViT variants (Swin, T2T, and CvT). In all cases, the auxiliary task improved performance without requiring changes to the core Transformer blocks.
- The "Aha" Moment: Even "hybrid" Transformers (like CvT, which already uses some convolutions) still benefit significantly from this task, proving that explicit spatial supervision is more powerful than just adding a few convolutional layers.
Key Results
- Dramatic Accuracy Boosts: When training from scratch on the "Quickdraw" dataset, a Swin-Transformer's accuracy jumped from 24.08% to 69.41%—a staggering 45-point increase.
- Beating ResNets: With this new loss, ViTs were finally able to match or exceed the performance of ResNet-50 on small datasets, effectively closing the gap that previously made CNNs the default choice for small data.
- Faster Convergence: The models reached higher accuracy levels in fewer training epochs. For example, on ImageNet-100, models trained with $\mathcal{L}_{drloc}$ for 100 epochs often outperformed baseline models trained for 300 epochs.
- Robust Fine-tuning: Even when starting with a model pre-trained on ImageNet, adding the relative localization task during fine-tuning on a new, smaller dataset consistently improved final accuracy.
Limitations and Future Work
- Grid Sensitivity: The authors found that using a very high-resolution grid (e.g., 14x14) for the localization task actually slowed down convergence and introduced noise. They found a 7x7 grid to be the "sweet spot."
- Model Scale: The study primarily focused on models comparable in size to a ResNet-50 (~25M parameters). Whether these gains hold up for "Giant" Transformers (billions of parameters) remains an open question.
- Future Directions: The authors suggest exploring other types of self-supervised tasks that could be "plugged in" to ViTs to further reduce their reliance on massive labeled datasets.
Summary updated