Lesson 5.6advanced2 h 30 min

Segmentation

Every pixel gets a label — FCN, U-Net, Mask R-CNN and Segment Anything

Segmentation asks the finest question in vision — which pixels belong to what — and it powers medical imaging, autonomous driving, satellite analysis and photo editing. Its workhorse, the U-Net, is also the denoising backbone inside Stable Diffusion (8.9 Generative models II: Diffusion and flow matching), so its encoder–decoder-with-skips design is worth knowing cold. Segment Anything showed that promptable foundation models apply to pixels too, foreshadowing the multimodal systems of 8.10 Multimodal models.

You'll be able to

  • Distinguish semantic, instance and panoptic segmentation and their metrics (mIoU, Dice, PQ)
  • Explain FCN upsampling, U-Net skip connections and why they recover localization
  • Derive the soft Dice loss, relate Dice to IoU, and justify combined losses for imbalanced masks
  • Describe Mask R-CNN's mask head and RoIAlign, and Segment Anything's promptable design
  • Choose a segmentation model and dataset format for a practical task

Key ideas

  1. Semantic = class per pixel; instance = mask per object; panoptic = both. Metrics: mIoU, per-class Dice, PQ = SQ × RQ.
  2. FCNs replace FC layers with 1×1 convs and upsample; skip connections from shallow layers restore boundaries (deep = what, shallow = where).
  3. U-Net mirrors an encoder with a decoder and concatenates encoder features at each resolution; it trains from tiny datasets and is the backbone of diffusion models.
Show 4 more key ideas
  1. Dice = 2|A∩B|/(|A|+|B|) = 2·IoU/(1+IoU); soft Dice loss 1 − (2Σp·g + ε)/(Σp + Σg + ε) is immune to background imbalance; BCE + Dice is the standard recipe.
  2. Mask R-CNN = Faster R-CNN + per-class sigmoid mask head; RoIAlign's bilinear sampling (no quantization) is what makes masks accurate.
  3. Segment Anything: one heavy image embedding, cheap prompt encoder and mask decoder, trained on 1.1 B masks via a data engine; zero-shot, promptable, class-agnostic.
  4. Label maps must use nearest-neighbour interpolation and identical geometric augmentations to the image.

Suggested path through this lesson