Vision Transformer · Computer Vision
ViT — split image into PATCHES, treat each patch like a TOKEN, run Transformer
SWIN Transformer: hierarchical ViT with shifted windows — efficient for detection and segmentation
P
Patches — treating image regions like tokens
ViT splits an image into fixed-size patches (originally 16x16 pixels), flattens each patch, and projects it into an embedding with an added position embedding — treating each patch essentially like a "word" token fed into a standard Transformer encoder.
Example: a 224x224 pixel image being split into a grid of 16x16 pixel patches, each treated as one token, exactly as described in the original "An Image Is Worth 16x16 Words" paper (Dosovitskiy et al., 2020).
G
Global context from layer 1 — unlike CNNs
Because self-attention lets any patch attend to any other patch immediately, ViT has access to global image context starting from its very first layer, unlike CNNs which build up context gradually through successive convolutional layers.
Example: a ViT relating a patch in the top-left corner directly to a patch in the bottom-right corner in its very first attention layer, something a CNN would need many layers of convolutions to achieve.
The tradeoff — needs more data than CNNs
Because ViT lacks CNNs' built-in inductive bias for locality (the assumption that nearby pixels are related), it typically needs significantly more training data to perform well.
Example: a ViT trained on a relatively small image dataset underperforming compared to a CNN, unless trained on a much larger dataset that compensates for ViT's lack of built-in spatial assumptions.
S
SWIN Transformer — a hierarchical, efficient alternative
SWIN Transformer introduces a hierarchical structure with shifted windows, achieving efficient complexity for high-resolution images, making it the dominant backbone choice for object detection and segmentation tasks specifically.
Example: SWIN Transformer being used as the backbone for a state-of-the-art object detection system, chosen specifically for its efficiency advantages with high-resolution images over standard ViT.
1
A team is deciding between a CNN and a ViT for an image classification task, but only has access to a relatively small labeled dataset.
2
Ask: which architecture is likely to perform better given the limited data? A CNN, since ViT typically needs more training data to compensate for its lack of built-in spatial inductive biases.
3
If the team instead had access to a very large labeled dataset, ViT's advantage of immediate global context from its very first layer could give it an edge over a comparable CNN.
4
For a detection or segmentation task specifically involving high-resolution images, SWIN Transformer's hierarchical, shifted-window structure would be a natural choice, given it's become the dominant, more efficient backbone for those particular tasks.

Exams test whether you understand ViT's core mechanism (splitting images into patches treated as tokens) and its key tradeoff versus CNNs (immediate global context, but needing more training data due to lacking CNN-style inductive biases). Also expect a note on SWIN Transformer as the efficient, hierarchical variant dominant for detection/segmentation.

The most common trap is assuming ViT is a strictly superior replacement for CNNs in every situation. ViT's lack of built-in spatial inductive biases means it typically needs significantly more training data to match or exceed CNN performance — on smaller datasets, CNNs often still perform better.

1. How does ViT process an image?
By splitting it into fixed-size patches (originally 16x16 pixels), flattening and embedding each patch, and treating each patch like a token in a standard Transformer.
Tap to reveal / hide
2. What advantage does ViT have over CNNs regarding context?
ViT has global image context available from its very first layer, unlike CNNs which build up context gradually through successive layers.
Tap to reveal / hide
3. What is a key disadvantage of ViT compared to CNNs?
It typically needs more training data, since it lacks CNN's built-in spatial inductive biases.
Tap to reveal / hide
4. What does SWIN Transformer add on top of standard ViT?
A hierarchical structure with shifted windows, achieving efficient complexity for high-resolution images.
Tap to reveal / hide
5. What tasks is SWIN Transformer particularly dominant for?
Object detection and segmentation, especially with high-resolution images.
Tap to reveal / hide