Vision Transformer Models: How They Read Images
A vision transformer reads an image by cutting it into small patches and learning how they relate. Here is how it works, where it beats older ones, and how to start.
On this page
Short answer
A vision transformer model is a neural network that reads an image by cutting it into small square patches and learning how those patches relate to each other. Instead of scanning the image with small filters, it looks at all the patches at once and weighs which ones matter for the task. It is used for classifying images, finding objects and reading documents.
What is a vision transformer model?
A vision transformer model is a neural network that reads an image by cutting it into small square patches and learning how those patches relate to each other. It takes the same transformer design that language models use for sentences and applies it to pictures: the image becomes a sequence of patches, and the model learns which patches matter for the task at hand.
The idea was introduced in a 2020 paper by researchers at Google, which showed that a transformer trained on a large set of images could match the best convolutional networks of the time. The model treats each patch as a word in a sentence: a patch showing a wheel means little on its own, but together with patches showing a body and windows it points to a car.
Vision transformers are now a standard tool for image work. They classify photos, find objects in a scene, read scanned documents and check products on a line. They are not magic: they need a lot of training images, and they work best when a pretrained model is adapted to a specific task. Computer vision covers the wider field; see computer vision in logistics for how image models are used on real work.
How does a vision transformer read an image?
A vision transformer reads an image in five steps: it cuts the image into patches, turns each patch into a vector, adds position data, weighs the patches, and reads the result.
| Step | What happens | Why it matters |
|---|---|---|
| Split into patches | The image is cut into small squares, often 16 by 16 | Turns a picture into a readable sequence |
| Flatten and embed | Each patch is flattened into a number vector | Gives every patch a workable form |
| Add position | A position code is added to each vector | Tells the model where each patch sits |
| Self-attention | Each patch is weighed against the others | Links distant parts, such as head and tail |
| Read the output | A final layer turns the patches into a label or boxes | Produces the answer |
The key step is self-attention. A convolutional network looks at small areas one at a time and builds up a picture of the whole image layer by layer.
A vision transformer looks at all the patches from the start, so it can link a patch in one corner with one in the opposite corner in a single step. That suits tasks where the answer depends on the whole image, such as telling a wolf from a dog by its shape.
The cost of that view is data. A transformer has few built-in assumptions about images, so it needs many examples to learn what a convolutional network gets from its design. In practice teams start from a pretrained model and adapt it to their own task.
How is it different from a convolutional network?
A vision transformer differs from a convolutional network in how it sees: the transformer weighs all parts of the image at once, while the convolutional network scans small areas and builds up. Both can classify images well, and the right choice depends on the data and the task.
| Question | Vision transformer | Convolutional network |
|---|---|---|
| How it sees | All patches at once, weighed against each other | Small areas scanned in turn, built up layer by layer |
| Training data needed | A lot, unless starting from a pretrained model | Less, because the design assumes nearby pixels relate |
| Long-range links | Strong from the first layer | Grows with depth, needs many layers |
| Speed on small images | Slower, more computation per image | Faster, fewer operations per image |
| Best use | Large datasets, whole-image tasks | Small datasets, local detail tasks |
The practical rule is simple: if you have a small set of labelled images, a convolutional network is usually the safer start, because its design does some of the learning for you. If you have a large set, or you can start from a pretrained transformer, the transformer often wins on accuracy, especially where the whole image matters.
Many teams now mix the two. A convolutional layer can handle the early detail and a transformer can handle the whole-image links. The choice is a trade-off between data, speed and accuracy, not a contest with one winner. A step-by-step build guide is in how to implement computer vision.
Where are vision transformers used?
Vision transformers are used wherever a machine must read a whole image and decide what it shows. The common uses are image classification, object detection, medical image reading, document understanding and quality inspection.
In retail, they sort product photos, match a photo a shopper uploads to the same item in a catalogue, and check that shelf photos show the right products. In medicine, they read scans and slides, flagging areas a specialist should look at. The model never makes the final call on its own: a person reviews anything that affects a patient or a customer.
In industry, they inspect parts on a line, spotting cracks, missing pieces or wrong labels that a rule-based check would miss. In documents, they read forms and drawings, linking text in one corner with a diagram in another. Property teams use the same idea on photos; see computer vision in real estate for how image models sort and tag listing photos.
The pattern across all of these is the same: the model does the fast first pass over many images, and a person handles the cases the model flags or the cases that carry risk. A team that lets a model decide alone is a team that will miss the one case that matters.
Example: sorting product photos
Example (hypothetical): an online shop receives 1,200 new product photos a month. A staff member checks each photo by hand, taking about 2 minutes per photo to confirm it matches the product and meets the style rules, which adds up to 2,400 minutes a month, or 40 hours.
The shop tries a vision transformer trained to flag photos that do not match the product or break a style rule. The model flags 180 of the 1,200 photos, and a staff member reviews only those, taking 5 minutes each, which adds up to 900 minutes, or 15 hours. The other 1,020 photos pass without review.
The shop saves 25 hours a month, but the saving depends on the flag rate. If the model flagged 600 photos, the review time would be 3,000 minutes, or 50 hours, which is worse than checking by hand. The team sets a bar: the flag rate must stay under 20 percent, or about 240 photos, for the model to be worth running.
The team also checks the model's mistakes each week. In the first month it misses 12 photos that break a style rule, mostly photos with a busy background. The team adds 200 such photos to the training set, and the miss rate falls the next month. The model improves only when its mistakes are fed back into it.
What are the common mistakes?
The most common mistakes with vision transformers are training on too little data, trusting the model without checking its errors, and picking a transformer when a simpler model would do.
- Training from scratch on a small set. A transformer trained on a few hundred images will memorise them and fail on new ones. Start from a pretrained model and adapt it with your own images.
- Ignoring the error pattern. A model that is right 95 times in 100 can still be wrong on the same kind of image every time. Look at the mistakes, not just the average score.
- Choosing a transformer by default. For a small dataset or a task about local detail, a convolutional network is often faster and more accurate. Pick the model that fits the data, not the newest one.
- Forgetting the cost. Transformers need more computation than convolutional networks, both in training and in use. Check the running cost before committing to one.
- Letting it decide alone. A model that flags photos or reads scans should hand its uncertain cases to a person. The final call on anything that affects a customer stays with a human.
- Dirty training data. Mislabeled images teach the model the wrong thing. Spend time cleaning the labels before training, and the model will repay it.
How do you start using one?
You start using a vision transformer by picking one narrow task, gathering a labelled set of images, and adapting a pretrained model to it. The work is mostly data and measurement, not model design.
- Pick one task. Choose a single job, such as sorting product photos or flagging damaged parts. A narrow task is easier to measure and fix.
- Gather labelled images. Collect a few hundred to a few thousand examples with correct labels. A wrong label teaches the model the wrong thing.
- Pick a pretrained model. Use a well-known model trained on a large image set and adapt it to your task. Do not train from scratch unless you have a very large dataset.
- Split the data. Keep a test set the model never sees. If you test on the training images, the score will look better than the model really is.
- Measure the errors. Look at which images the model gets wrong, not just the average score. Fix the labels or add examples for the kinds of images it misses.
- Run a small pilot. Use the model on real images for two weeks with a person reviewing its output. If the error pattern is stable and the time saved is real, widen the use.
Keep the pilot small enough that one person can review every flagged case. A model that runs without review is how a wrong label reaches a customer. Business teams can compare image models with other tools in machine learning in business analytics.
Key takeaways
- A vision transformer cuts an image into patches and weighs them against each other
- Self-attention links distant parts of an image in a single step
- It needs a lot of training data, so teams start from a pretrained model
- A convolutional network is often the better start on a small dataset
- Measure the error pattern, not just the average score, before widening use
Frequently asked questions
What size are the patches in a vision transformer?
The common size is 16 by 16 pixels, from the original 2020 design. A larger image cut into 16-pixel patches gives more patches to weigh, which costs more computation. Some models use larger patches for speed, at the cost of fine detail.
Do vision transformers need more data than convolutional networks?
Yes, when trained from scratch, because they have fewer built-in assumptions about images. In practice teams start from a model pretrained on millions of images and adapt it with a smaller set of their own labelled images.
Can a vision transformer read text in an image?
It can help, but reading text is usually done by pairing it with a text-recognition model. The transformer finds where the text sits and what it looks like, and the text model reads the characters.
Are vision transformers slower than convolutional networks?
Often, yes, because self-attention compares every patch with every other patch. For small images or tasks that need fast answers, a convolutional network is usually quicker. The trade-off is speed against whole-image accuracy.
What is the difference between a ViT and a vision transformer?
There is none. ViT is the short name for the vision transformer model introduced in the 2020 paper. The two names refer to the same design: an image cut into patches and read by a transformer.
Can I use a vision transformer without training one?
Yes. Well-known pretrained models are available and can be adapted to a new task with a few hundred labelled images. You only need to train from scratch if your images are very different from anything the pretrained model has seen.