HyperAIHyperAI

Command Palette

Search for a command to run...

3 months ago

Transformer in Transformer

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

Transformer in Transformer

Abstract

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$\times$16) as "visual sentences" and present to further divide them into smaller patches (e.g., 4$\times$4) 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 https://github.com/huawei-noah/CV-Backbones, and the MindSpore code is available at https://gitee.com/mindspore/models/tree/master/research/cv/TNT.

Benchmarks

BenchmarkMethodologyMetrics
fine-grained-image-classification-on-oxfordTNT-B
Accuracy: 99.0%
PARAMS: 65.6M
fine-grained-image-classification-on-oxford-1TNT-B
Accuracy: 95.0%
PARAMS: 65.6M
image-classification-on-cifar-10TNT-B
Percentage correct: 99.1
image-classification-on-cifar-100TNT-B
PARAMS: 65.6M
Percentage correct: 91.1
image-classification-on-imagenetTNT-B
Hardware Burden:
Number of params: 65.6M
Operations per network pass:
Top 1 Accuracy: 83.9%

Build AI with AI

From idea to launch — accelerate your AI development with free AI co-coding, out-of-the-box environment and best price of GPUs.

AI Co-coding
Ready-to-use GPUs
Best Pricing
Get Started

Hyper Newsletters

Subscribe to our latest updates
We will deliver the latest updates of the week to your inbox at nine o'clock every Monday morning
Powered by MailChimp
Transformer in Transformer | Papers | HyperAI