Transformer in Transformer
Kai HanAn XiaoEnhua WuJianyuan GuoChunjing XuYunhe Wang
Introduces the Transformer in Transformer architecture to model fine-grained interactions within local image sub-patches alongside global patch representations, improving image classification accuracy with minimal computational overhead.
Modern computer vision models are rapidly shifting from traditional convolutional networks to transformer-based architectures that rely on self-attention mechanisms. However, standard vision transformers divide images into relatively coarse patches, treating them as simple sequences. This coarse division fails to capture fine-grained internal details and subtle color variations, creating a performance bottleneck when recognizing complex objects across different scales.
The article aims to demonstrate that embedding a secondary, fine-grained sub-transformer within standard vision transformer architectures significantly enhances visual feature extraction and overall recognition accuracy with minimal added computational cost.
To achieve this, the researchers introduced the Transformer-in-Transformer architecture, which conceptualizes coarse image patches as visual sentences and subdivides each patch into smaller sub-patches termed visual words. The system uses an inner transformer block to model local word interactions and an outer transformer block to model broader sentence interactions, fusing the representations layer by layer. The authors evaluated this design on the ImageNet benchmark containing over 1.2 million training images, as well as downstream tasks including image classification, object detection on the COCO dataset, and semantic segmentation on ADE20K.
The evaluation yielded several key findings. First, the small variant of the model achieved an 81.5% top-1 accuracy on ImageNet, outperforming comparable state-of-the-art vision transformers by 1.7% while requiring only an 8% increase in parameters and a 14% increase in computational operations. Second, across downstream tasks, the architecture consistently outperformed baseline transformers, raising object detection performance by 3.5 Average Precision on COCO and semantic segmentation by 1.0% mean Intersection over Union on ADE20K. Third, ablation analyses confirmed that modeling both global patch positions and local word positions is vital, as omitting position information resulted in an accuracy drop of up to 1.0%. Finally, throughput tests showed that selectively applying fine-grained blocks achieves high processing speeds (over 800 images per second) while maintaining strong accuracy.
These findings indicate that internal patch structures contain valuable visual cues that standard transformers discard. By capturing these local details without a severe computational penalty, the proposed method establishes a more effective balance between accuracy, model size, and execution speed. Although it outperforms standard convolutional baselines like ResNet, pure transformer architectures still trail specialized convolutional designs like EfficientNet in peak computational efficiency, highlighting that local feature modeling in transformers remains an active optimization area.
For engineering and product teams deploying computer vision systems, adopting nested transformer architectures offers a practical route to higher accuracy in visual classification, object detection, and segmentation. Practitioners should evaluate replacing standard vision transformer backbones with this nested approach, taking advantage of hybrid configurations—such as mixing nested blocks with standard transformer blocks—to meet strict latency requirements in production environments.
Readers should note that while the empirical evidence is strong across multiple standardized vision benchmarks, training these models requires substantial computational resources, including specialized graphics hardware, which carries associated energy and financial costs. Further evaluation in domain-specific, real-world deployment scenarios is recommended before full-scale operational rollout.
- Paper: An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale, Alexey Dosovitskiy et al. (2021). Reading the original Vision Transformer paper is essential because the source directly builds upon its patch-based image tokenization framework.
- Paper: Tokens-to-Token ViT: Training Vision Transformers from Scratch on ImageNet, Li Yuan et al. (2021). This paper introduces the Tokens-to-Token module, providing foundational context on how to capture local structures in vision transformers that the source refines further.
- Paper: VMamba: Visual State Space Model, Yue Liu et al. (2024). This work continues the quest for efficient multi-scale visual representations by extending transformer and state-space concepts to achieve linear computational scaling.
- Paper: ViLT: Vision-and-Language Transformer Without Convolution or Region Supervision, Wonjae Kim et al. (2021). This paper builds on lightweight patch-processing paradigms by introducing minimal vision-and-language architectures that eliminate complex region supervision.
