Vision Transformer
Cutting a photo into pieces and treating it like text
- A Vision Transformer cuts a photo into same-size pieces and lines them up in a row, handling them the way text handles words.
- Every piece gets a tag telling it where it originally sat. Without that, position information is gone.
- Unlike scanning outward from nearby spots, it compares distant pieces against each other from the very first step.
- It carries no built-in habits about photos, so it needs a lot of data before it performs well.
- More pieces means the number of pairs to compare grows far faster, so computation gets heavier.
Contents
1The analogy
Cargo arriving at a port never gets moved as one solid mass. It gets packed into same-size containers, and every container gets a number. From that point on, the control room isn't working with the cargo itself — it's working with a numbered list of containers.
A Vision Transformer doesn't look at a photo as a whole either. It cuts the photo into same-size square pieces, lines them up in a row, and tags every piece with a number saying where it originally came from.
Treat it as a list and distance disappears. A container at one end of the dock and a container at the other end are still just two lines on the same list, so the control room can set them side by side and compare them directly. No need to walk across the yard.
2In detail
Cutting the photo into same-size pieces
The first step is cutting. The photo gets sliced into tight squares, a dozen-odd pixels on a side. A large photo comes apart into a few hundred pieces this way. The pieces don't overlap and leave no gaps, so put back together they fill the original photo exactly.
Each piece is a small bundle of colored dots. That bundle gets flattened into a single row of numbers. After this step, one photo has become a few hundred rows of numbers.
Here's the key part: a few hundred rows of numbers look exactly like the result of chopping a sentence into pieces. That's why a structure originally built for text can be reused almost without modification — and it's exactly why this gets called a Vision Transformer.
Skip the position tag and position is lost
The moment pieces get lined up in a row, a problem appears. On that line, which piece sat at the top left of the photo and which sat at the bottom right is gone. Shuffle the order of the pieces and the calculation comes out exactly the same.
So a number bundle telling each piece where it sits gets added in — the same role a number tag plays on a shipping container. Only once this tag is attached can pieces from the top be told apart from pieces at the bottom.
Comparing distant pieces directly
This is where it splits from a CNN. A CNN slides a small window across the photo and only ever looks at immediately neighboring pixels together. Because what one step can see is narrow, reaching all the way across the photo takes stacking many layers on top of each other.
A Vision Transformer has every piece compare against every other piece from the very first step. It works out directly how related the top-left piece is to the bottom-right one. A single object split across two ends of a photo can be tied together as one thing right from the start.
In exchange, it gives up an advantage a CNN gets for free. That nearby points tend to be closely related, and that an object shifted a little is still the same object — a CNN already knows both facts, baked into its structure. A Vision Transformer has to learn all of that from data.
The price of knowing nothing in advance
That's why, with too little data, it can actually do worse than a CNN. Train it on a data set of only a few tens of thousands of photos, and it fails to properly grasp the relationships between pieces and wobbles. Having no built-in habits means freedom — and it also means everything has to be learned from scratch.
Flip it around, though: after first learning broadly from a huge pile of photos, it often ends up beating a CNN afterward. A built-in habit helps as much as it limits. That's why the common approach now is to take something already trained on a large data set and fine-tune it for whatever specific job is needed.
Piece count is cost
Because every piece compares against every other piece, doubling the pieces quadruples the pairs to compare. Push the resolution higher and you either cut pieces finer or add more of them — and the moment you do, computation balloons. That's a real burden anywhere high resolution matters.
That's why later architectures mix in an approach where nearby pieces get compared first, and pieces get merged into fewer, bigger ones as you go up. Starting fine and progressively grouping into something bigger closely resembles what a CNN was already doing. The two families have moved closer by borrowing each other's strengths.
3More precisely
A Vision Transformer splits a photo into non-overlapping square patches, turns each patch into a single vector, adds position information, and runs the result through self-attention blocks. When used for classification, one extra slot is added alongside the pieces to hold a summary, and only that slot's value gets pulled out at the end to decide the label. Strip away the cutting and the position tagging, and the rest of the calculation is nearly identical to a transformer built for text.
The analogy breaks down in a few places. Cargo inside a container stays as it is if you open it up, but a cut piece gets pressed into a number bundle and keeps changing as it passes through layer after layer — there's no need to turn it back into the original picture. And while a control room worker scans a list line by line, attention calculates the relevance of every pair all at once. Above all, a container's number is a rule a person set, but the position tag attached to a piece is a value that gets refined right alongside training.
4Try it yourself
5Common misconceptions
It's easy to think a Vision Transformer has fully replaced the CNN, but actually CNN-style architectures still have the edge wherever data is scarce or computation is tight.
It's easy to assume cutting a photo into pieces breaks the relationships between them, but actually every piece gets compared against every other piece after cutting, so distant spots end up connected in one step, if anything.
It's easy to think cutting pieces finer is always better, but actually more pieces means the pairs to compare grow far faster, and computation can quickly become unmanageable.
7One-line summary
In shortA Vision Transformer cuts a photo into same-size pieces, lines them up like words, and compares every piece against every other, so it can connect distant spots in one step from the very start.
Spotted an error or have a better analogy? Suggest an edit · Last updated2026-09-02