The short answer
Neither is better in every case. A CNN (convolutional neural network) often works well with smaller datasets and moderate computing budgets, because its built-in assumptions suit images. A ViT (Vision Transformer) can reach very strong results, but it usually needs a lot of training data, or large-scale pretraining, before it pulls ahead. The right choice depends on your data, your compute, and your task.
How a CNN sees an image
A CNN uses convolutional layers, which slide small filters across the image. Each filter looks at a local patch, and the same filter is reused across the whole image. That builds in two assumptions: nearby pixels are related, and a pattern means the same thing wherever it appears. Researchers call these built-in assumptions inductive biases. They reduce how much a model has to learn from scratch, which often helps when examples are limited. The mechanics are covered in how do convolutional layers work in deep learning neural networks.
How a ViT sees an image
A Vision Transformer was introduced in 2020 in a paper titled An Image Is Worth 16x16 Words. It splits an image into fixed-size patches, such as 16×16 pixels, turns each patch into a vector, and processes the sequence of vectors with self-attention. Self-attention lets every patch relate to every other patch, even in the first layer.
Because the architecture assumes less about image structure, the model has to learn those patterns from data. That is one reason it tends to need more data.
Data: the biggest practical difference
With small or mid-sized datasets trained from scratch, CNNs often do better. ViTs tend to show their strength when they are pretrained on very large image collections and then fine-tuned on the task at hand. Some hybrid designs add convolution to transformers to get the benefits of both.
Compute and speed
Compute cost depends on the model’s size, the image resolution, and how the model is built. Standard self-attention cost grows quickly as the number of patches grows, so very high-resolution images can make a ViT expensive. Real speed also depends on your hardware and software, so measure it on the setup you plan to use.
Accuracy
Both families have produced top results on standard image benchmarks, and the leading results keep changing as new models appear. Treat any single leaderboard with caution, and check recent results on a task close to yours.
How to choose
- Small dataset or limited compute: start with a CNN, ideally a pretrained one.
- Very large dataset or access to a large pretrained ViT: a ViT is a strong option.
- Small devices: compare model size and speed. Many compact CNNs are designed for this.
- Unsure: test a pretrained model from each family on a held-out validation set that matches your task.
Within the CNN family
The same logic applies inside a family of models. A question such as which is better, VGG16 or Resnet50? depends on accuracy needs, memory limits, and speed, so the answer changes from model to model.
Bottom line
Neither is universally better. CNNs are a strong default for many image tasks, especially with limited data and compute. ViTs can match or beat them with large-scale pretraining and more compute. If you can, test both on your own data.