TL;DR
The Transformer in Transformer (TNT) architecture introduces a nested hierarchical approach to computer vision. By treating image patches as "visual sentences" and further dividing them into "visual words," TNT captures fine-grained local details that standard Vision Transformers (ViT) often overlook, leading to significant accuracy gains with minimal computational overhead.
The Problem: Coarse Granularity in Vision Transformers
Since the introduction of the Vision Transformer (ViT), the computer vision community has rapidly adopted attention-based models. However, standard ViTs possess a structural limitation: they divide an image into a grid of patches (typically 16x16 pixels) and treat these patches as the fundamental, indivisible units of information.
The authors of TNT argue that this "patch-level" granularity is too coarse. Natural images are incredibly complex; a single 16x16 patch can contain critical textures, edges, and color gradients. By treating these patches as atomic units, standard transformers fail to model the internal local structure and relationships within each patch. TNT aims to "excavate" these hidden features to build a more robust representation of the visual world.
Methods: The Nested Transformer Architecture
The core innovation of this paper is the TNT block, which consists of two nested transformer components designed to process information at two different scales:
- Inner Transformer Block ($T_{in}$): This block operates on "visual words"—smaller sub-patches (e.g., 4x4 pixels) within a larger patch. It models the relationships between these sub-patches to capture local details.
- Outer Transformer Block ($T_{out}$): This functions as the standard transformer block, modeling the relationships between the larger "visual sentences" (the 16x16 patches) to capture global context.
The magic happens in the interaction between the two blocks. In each layer, the word-level features from the inner block are linearly projected and added to the sentence-level features. This ensures that the global representation is constantly augmented by fine-grained local information. Furthermore, TNT uses position encodings at both levels: sentence-level encodings track where a patch is in the image, while word-level encodings track where a sub-patch is within its parent patch.
Crucially, the inner transformer block is shared across all visual sentences in a layer. This design choice keeps the increase in parameters and FLOPs (floating-point operations) remarkably low—costing only about 1.14x the computational overhead of a standard transformer.
Key Insights and Results
The authors evaluated TNT across a wide range of benchmarks, including ImageNet-1K for pre-training, and various downstream tasks like object detection (COCO 2017) and semantic segmentation (ADE20K).
- ImageNet Performance: TNT-S achieved an impressive 81.5% top-1 accuracy, outperforming the baseline DeiT-S by 1.7% with similar computational costs. The larger TNT-B reached 82.9%.
- Downstream Superiority: On the COCO detection task, a TNT-S backbone outperformed a PVT-Small backbone by 3.5 AP (Average Precision) with a similar parameter count.
- Preserving Local Structure: Visualizations demonstrate that TNT preserves local information much better than DeiT (Data-efficient Image Transformer). In deeper layers, while standard transformers become overly abstract, TNT maintains richer, more diverse feature maps.
Limitations and Future Work
While TNT outperforms most standard transformers and ResNets, it still trails behind highly optimized CNNs like EfficientNet in terms of raw accuracy-per-FLOP. The authors note that beating EfficientNet with a "pure" transformer remains an ongoing challenge. Additionally, although the FLOP increase is small, the nested structure can introduce some latency in practical deployments compared to highly parallelized standard transformers.
Future directions suggested by the authors include exploring more exquisite image-dividing methods and potentially integrating TNT with other architectural improvements, such as pyramid structures or hybrid convolution-transformer designs.
Summary updated