Wink Pings

ViT Reads an Image: First Split It into Patches, Then Let a Blank Token Query the Whole Image

An animation breaks down the Vision Transformer from input to classification: patch splitting, linear projection, class token, positional encoding, and an encoder repeated L times. In the comments, some people find the formulas complicated, and some ask how it differs from the Transformer in LLMs.

A Vision Transformer reads an image by first splitting it into patches, not by scanning pixel by pixel. The original poster mathemetica uses an animation to demonstrate this process; the formulas look intimidating, but broken down they are just a few steps.

The image is split into multiple patches. Each patch is flattened and mapped into a token through the same linear projection E. A learnable [class] token is placed at the very front, and then positional embeddings are added to each token:

z₀ = [x_class; x¹E; …; xᴺE] + E_pos

Next come L encoder layers. Each layer first does Norm, then multi-head self-attention, and adds the input back as a residual; then Norm, passes through an MLP, and adds another residual. Repeat L times. Finally, only the output of the class token is fed into the MLP head to predict the class.

The video is below.

In the comments, some people complain that the formula is complicated, saying it could be written in one line, so why draw it in such a roundabout way. Others ask: this structure looks the same as the Transformer in LLMs—what's the difference? Simply put, ViT uses a Transformer encoder with no causal mask, so all patch tokens can see each other; LLMs usually use a decoder with a causal mask, autoregressively generating the next token. ViT does not generate text; it only uses the class token for classification.

Someone else commented that this explains why the flattening process is slow. The more patches there are, the heavier the attention computation, so it is not simply a matter of flattening the image and being done.

Someone asked how the animation was made, and posted an image:

image

The original post connects ViT from input to output very clearly: split into patches, project, add class token, add positional encoding, pass through the encoder, take the class token for classification. Remember this thread, and the formulas will be much less confusing when you look at them again.

发布时间: 2026-11-28 11:30