All models

vit_b_32

Vision Transformer: a Transformer encoder that classifies an image from a sequence of patch embeddings.

Image classification · 442 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 (34 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
ViT
Parameters
88.2M
Operations
442
Framework
PyTorch
Recurrent
No
License
BSD-3-Clause
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
m10924
Graph hash
b6a9789c7337fef7a8fd20d61129e4e9b2ce0e9718bbba544b1673a058ad369a
Skeleton hash
0168ed7b9edf30ecc7c13aed5dbebca620771f844ffd83797da224e166d1956e
Architecture hash
9c15e67193fe733c950c44f768f8ab21cf62933212135a2101617ccff4a7ec84
Diagram SHA-256
e5199d5396bb41811e617c9b8a0e0c7b0292a70bec9babdbb8489e413ccaa10d
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

torchvision.models.get_model('vit_b_32', weights=None)

What it is

This model is built by torchvision's vit_b_32 builder. In the paper's notation, that name denotes the Base size with 32 × 32 input patches.

About this model's family

The Vision Transformer (ViT) is a pure transformer applied directly to sequences of image patches for image classification. The paper's argument is that vision models do not need to rely on CNNs. An image is split into patches, and the patches are treated the same way as word tokens in a language model.

The design follows the original Transformer as closely as possible. A learnable embedding is prepended to the sequence of embedded patches, and a classification head is attached to its state at the encoder's output. Learnable 1D position embeddings are added to the patch embeddings to retain positional information. Inside the encoder, layer normalization is applied before every block and residual connections after every block. The paper notes that Transformers lack inductive biases inherent to CNNs, such as translation equivariance and locality, and do not generalize well when trained on insufficient data.

The paper defines Base, Large and Huge sizes with 12, 24 and 32 layers. Models with a smaller patch size see a longer sequence and are computationally more expensive. The paper reports that its best model reaches 88.55% accuracy on ImageNet and 94.55% on CIFAR-100. In torchvision, all the model builders rely on one VisionTransformer base class, and by default no pre-trained weights are used.

Key idea. The paper shows that a pure transformer applied directly to sequences of image patches can classify images without relying on CNNs.

  • Vision Transformer
  • ViT
  • vit_b_16
  • vit_b_32
  • vit_l_16
  • vit_l_32
  • vit_h_14
  • An Image is Worth 16x16 Words
  • image classification
  • image patches

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