Intermediate level · Module 5: Image Segmentation · Lesson 3 of 3
Semantic Segmentation with Pretrained Networks
Learners apply a pretrained torchvision segmentation model, understand encoder-decoder and U-Net designs and evaluate masks with IoU and Dice.
In this lesson you will
- Run pretrained semantic segmentation
- Evaluate masks with IoU and Dice
Key concepts
semantic vs instance segmentationencoder-decoderU-Net skip connectionstorchvision.models.segmentationIoU and Dice
The lesson
Semantic segmentation assigns a class to every pixel; instance segmentation also separates individual objects. Encoder-decoder networks shrink the image to learn context and then expand it back to full resolution; U-Net adds skip connections that pass fine detail from encoder to decoder.
torchvision provides pretrained models such as deeplabv3_mobilenet_v3_large, which run on a CPU for single images. Their classes come from their training data, so check that the classes you need exist. The torchvision documentation notes that pretrained weights may carry their own licence terms from the datasets used.
Evaluate with IoU (intersection over union) = overlap / union of the predicted and true masks, and Dice = 2 × overlap / (sum of both areas). Report them per class, and mean IoU across classes.
Step by step
- Load a pretrained segmentation model and its preprocessing transforms.
- Segment five street or field images and display the masks.
- Draw ground-truth masks for two images and compute IoU and Dice.
- Identify classes that the model does not have.
Practice activity
Evaluate a pretrained segmentation model on hand-labelled images and report IoU per class.
Expected result: Correct IoU and Dice values and a clear statement of the model's class coverage and failures.
Check your understanding
-
How is IoU calculated?
Show answer
The overlap of predicted and true masks divided by their union.
-
What do U-Net skip connections provide?
Show answer
Fine spatial detail from the encoder to the decoder.
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.