Computer Vision · Advanced level

Advanced level · Module 5: Attention Mechanisms and Vision Transformers · Lesson 3 of 3

ViTs versus CNNs in Practice

Learners compare a pretrained ViT with a CNN on their task for accuracy, data efficiency, size and CPU latency, and visualise attention.

In this lesson you will

  • Compare ViT and CNN on a real task
  • Interpret attention maps cautiously

Key concepts

data efficiencypretraining scalemodel sizeattention mapspractical choice

The lesson

ViTs need large pretraining datasets to beat CNNs; once pretrained, they transfer well. On small local datasets with modest hardware, a small CNN is often the better practical choice, but this should be measured.

Base-sized ViTs have tens of millions of parameters and are slow on CPUs. Fine-tune them on a free notebook GPU if available, or compare inference only.

Attention maps (for example, attention from the class token to patches) show where the model looked, but like Grad-CAM they are evidence, not proof.

Step by step

  1. Fine-tune or evaluate a pretrained ViT on the produce or capstone task.
  2. Compare with the best CNN on accuracy, size and latency.
  3. Visualise class-token attention for five images.
  4. Write a practical recommendation.

Practice activity

Write a ViT versus CNN comparison and recommendation for the capstone.

Expected result: Measured comparison and a practical, justified recommendation.

Check your understanding

  1. When do ViTs tend to outperform CNNs?

    Show answer

    When they are pretrained on very large datasets.

  2. Why may a CNN be the better choice for a small local project?

    Show answer

    It is smaller, faster on CPU and data-efficient.

Further learning

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.