Computer Vision · Advanced level

Advanced level · Module 5 of 10 · 14 guided hours

Attention Mechanisms and Vision Transformers

Attention in vision: channel and spatial attention in CNNs, the Vision Transformer (patches, position embeddings and self-attention), its data and compute needs, and practical use of pretrained ViTs.

Learning objectives

  • Explain attention mechanisms used in vision models
  • Explain how Vision Transformers process images
  • Fine-tune or apply a pretrained ViT and compare it with CNNs

Topics

  • channel and spatial attention
  • self-attention recap
  • patch embeddings and position embeddings
  • the class token and ViT encoder
  • data and compute needs
  • ViT versus CNN in practice

Lessons

  1. Lesson 1 Attention in Convolutional Networks

    Learners study squeeze-and-excitation style channel attention and spatial attention, and add a channel-attention block to a CNN.

    channel attentionglobal average poolinggating with sigmoidspatial attentionattention as re-weighting

  2. Lesson 2 How Vision Transformers See Images

    Learners follow an image through a Vision Transformer: patches, linear embeddings, position embeddings, a class token and transformer encoder layers.

    image patches (16×16)patch embeddingposition embeddingclass tokentransformer encoder

  3. Lesson 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.

    data efficiencypretraining scalemodel sizeattention mapspractical choice

Practical activity

Implement channel attention, walk through a ViT forward pass, and compare a pretrained ViT with a CNN on the capstone task with a practical recommendation.

Expected outcomes

  • Understanding of attention and Vision Transformers
  • Practical architecture judgement

Assessment

Implementation and walkthrough (50%) and comparison report (50%).

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.