All models

tnt_b_patch16_224

A vision transformer that runs attention inside each patch as well as between patches.

Image classification · 835 operations Checked

100%

Showing the top corner; full diagram not loaded yetShowing a small copy; full diagram not loaded yetLarge diagram, not loaded yet

Open SVG

Loading diagram (28 KB)

Open in a new tab

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.

At a glance

Family
tnt
Parameters
65.4M
Operations
835
Framework
PyTorch
Recurrent
No
Published
2021
License
Apache-2.0
Checked
Passed: the trace was replayed operation by operation and matched the model's own output for this input.

Files

The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.

Details
Stable ID
m10561
Graph hash
9d977d5d0e8834cfc29522b96aa5de680db9271317968333d2dc9a291e8ad371
Skeleton hash
8268e655a92b867b02a767ac6018115d7d0ef313d9aeca45af72af0953119f49
Architecture hash
1d2548322ce31c1925b5a9dfdb6c2eb659a5325df805a345ed5b2416365e7cfe
Diagram SHA-256
7af58e7283c7a18b41acc467a9bdf33c581f6a8a62eb8779a192ec3bc4f8d906
TorchLens version
2.35.3
Renderer
graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
Check
Forward pass replayed in PyTorch

How this diagram was made

timm.create_model('tnt_b_patch16_224', pretrained=False)

What it is

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.

  • TNT
  • transformer in transformer
  • transformer-in-transformer
  • visual words
  • visual sentences
  • visual transformer
  • image classification
  • TNT-S
  • TNT-B

AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.