Skip to main content

10.4.1 Segmentation Roadmap: Pixel-Level Regions

Segmentation is finer than detection. Instead of a box, it outputs a mask that says which pixels belong to a class or instance.

See the Mask Workflow First

Image segmentation chapter learning order diagram

Semantic segmentation mask example

Semantic segmentation IoU and boundary map

The main object in this chapter is the mask. The main failure is often boundary quality, tiny objects, occlusion, or class confusion.

Run a Mask IoU Check

This script compares two tiny binary masks.

truth = [
[1, 1, 0],
[1, 0, 0],
[0, 0, 0],
]

pred = [
[1, 0, 0],
[1, 1, 0],
[0, 0, 0],
]

intersection = 0
union = 0
for y in range(3):
for x in range(3):
intersection += truth[y][x] == 1 and pred[y][x] == 1
union += truth[y][x] == 1 or pred[y][x] == 1

print("mask_iou:", round(intersection / union, 3))

Expected output:

mask_iou: 0.5

Segmentation reports should show masks, metrics, and boundary errors, not only a colored overlay.

Learn in This Order

StepReadPractice Output
1Semantic segmentationPredict one class for every pixel
2Instance segmentationSeparate different objects of the same class
3Segmentation practiceCompare masks, IoU/Dice, boundary errors, and failed samples

Pass Check

You pass this chapter when you can create or inspect a mask, compute a simple overlap metric, and explain one boundary or class-confusion failure.