Built independently by an author, for readers. Read the story and support ChapterPal

keyword

Transformer in Transformer

Transformer in Transformer is a visual neural network architecture that captures both fine-grained local details and global structural relationships by utilizing nested transformer modules. Standard vision transformers partition an input image into a sequence of coarse patches and apply self-attention exclusively across those patches, which can miss localized sub-patch features. To address this, Transformer in Transformer further divides each coarse patch into smaller sub-patches, employing an inner transformer block to compute self-attention among the sub-patches within a single patch while an outer transformer block models the interactions across all coarse patches. By combining these nested inner and outer representations, the architecture effectively learns multi-scale visual features for tasks such as image recognition without incurring substantial computational overhead.

1 item

Transformer in Transformer

Transformer in Transformer

Kai Han, An Xiao, Enhua Wu, Jianyuan Guo, Chunjing Xu, Yunhe Wang

OrganizationsHuaweiInstitute of Software, Chinese Academy of SciencesUniversity of Macau

Why you should read this

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.

Transformer is a new kind of neural architecture which encodes the input data as powerful features via the attention mechanism. Basically, the visual transformers first divide the input images into several local patches and then calculate both representations and their relationship. Since natural images are of high complexity with abundant detail and color information, the granularity of the patch dividing is not fine enough for excavating features of objects in different scales and locations. In this paper, we point out that the attention inside these local patches are also essential for building visual transformers with high performance and we explore a new architecture, namely, Transformer iN Transformer (TNT). Specifically, we regard the local patches (e.g., 16×\times16) as "visual sentences" and present to further divide them into smaller patches (e.g., 4×\times4) as "visual words". The attention of each word will be calculated with other words in the given visual sentence with negligible computational costs. Features of both words and sentences will be aggregated to enhance the representation ability. Experiments on several benchmarks demonstrate the effectiveness of the proposed TNT architecture, e.g., we achieve an 81.5% top-1 accuracy on the ImageNet, which is about 1.7% higher than that of the state-of-the-art visual transformer with similar computational cost. The PyTorch code is available at this https URL, and the MindSpore code is available at this https URL.

Added

2026-09-16