All models

tnt_s_legacy_patch16_224

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

Image classification · 823 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
823
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
m10562
Graph hash
61d23d27ef47a44f1324eee9eeadf821f8ca494a492555c7df561a9e0d7ec4d3
Skeleton hash
2682b13994ccb6c112f01ce105b303963f3ac16862ad3014759f1271d4b3f556
Architecture hash
545caaf594efbb6e41e8ac567b27091fd3770b19674d2ff5018aec2c50b9df44
Diagram SHA-256
5fa17c5a2ff7deb1dff59267ce372d47db9b11a9e4d3ab6f95b4f74ca7d380d2
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_legacy_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.