All models

tnt_s_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
23.8M
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
m10563
Graph hash
9d977d5d0e8834cfc29522b96aa5de680db9271317968333d2dc9a291e8ad371
Skeleton hash
8268e655a92b867b02a767ac6018115d7d0ef313d9aeca45af72af0953119f49
Architecture hash
b4310e25070f43cdcbabe8a335b188a6d7d5a0941c667d672e65a551343a1bcd
Diagram SHA-256
731c2c833a3b33449745fce77076ddeb568f62c8e5a1d4098feddc8386800845
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_s_patch16_224', pretrained=False)

What it is

This model is the small size, TNT-S, for which the paper reports 81.5% top-1 accuracy on ImageNet, 1.7% higher than its DeiT-S baseline.

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.