
tnt (MMPretrain)
Image classification82 ops731.4K params
A vision transformer that runs attention inside each patch as well as between patches.
Image classification · 835 operations Checked
Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.
The file opened in a new tab. Use your browser's Save command there to keep it.
The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.
How this diagram was made
timm.create_model('tnt_b_patch16_224', pretrained=False) This model is the base size, TNT-B, for which the paper reports 65.6M parameters and 14.1B FLOPs on a 224×224 image.
About this model's family
Transformer in Transformer (TNT) is a vision transformer that applies attention inside each image patch as well as between patches. The paper argues that, for natural images with abundant detail and color information, ordinary patch division is not fine enough to pick out features of objects at different scales and locations.
TNT treats each 16×16 patch as a visual sentence and divides it further into 4×4 patches called visual words. In each block, an inner transformer block models the relationships between the words of one sentence, and an outer transformer block works on the sequence of sentences. In every layer the word embeddings are linearly projected and added into the sentence embedding, and at the end a classification token serves as the image representation.
The paper defines three sizes, TNT-Ti, TNT-S and TNT-B, and reports 6.1M, 23.8M and 65.6M parameters for them. On ImageNet it reports 81.5% top-1 accuracy for TNT-S, 1.7% higher than its DeiT-S baseline. It also notes that every transformer-based model in its comparison was still behind EfficientNet.
Key idea. Transformer in Transformer computes attention among the small visual words inside each patch as well as among the patches, and aggregates the features of both.
AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.