60-second card
Segmentation
Segmentation labels every pixel, giving exact outlines instead of boxes.
- Semantic: every pixel gets a class (road, car, sky).
- Instance: separate objects of one class get separate masks.
- U-Net is popular, especially for medical images.
import numpy as np
pred = np.array([[1, 1], [0, 0]])
true = np.array([[1, 0], [0, 0]])
inter = ((pred == 1) & (true == 1)).sum()
union = ((pred == 1) | (true == 1)).sum()
print(inter / union)Prints
0.5Remember: Use segmentation when the exact shape matters.
Common mistake: Judging a mask by pixel accuracy when 90% of the image is background. Use IoU per class.