Formula
IoU(A, B) = area(A ∩ B) ÷ area(A ∪ B)area(A ∪ B) = area(A) + area(B) − area(A ∩ B)Worked example
A ground truth box spans x 0–10 and y 0–10 (area 100). The prediction is shifted right and spans x 5–15, y 0–10 (also area 100). They share a 5 × 10 strip, so the intersection is 50 and the union is 100 + 100 − 50 = 150.
IoU = 50 ÷ 150 ≈ 0.33Half of each box overlaps the other, yet IoU is only a third: the metric is strict, which is why thresholds sit well below 1.
How thresholds turn IoU into hits and misses
Detection metrics count a prediction as a true positive when its IoU with an unmatched ground truth object of the same class reaches a threshold. Pascal VOC uses 0.5. The COCO evaluation averages over ten thresholds from 0.50 to 0.95 in steps of 0.05, which rewards tight boxes. That is the difference between AP50 and mean average precision over 0.50–0.95.
Common pitfalls
- Small objects: a two-pixel offset on a 10-pixel box drops IoU sharply, so per-size breakdowns matter.
- Box IoU and mask IoU of the same object can differ a lot for thin or hollow shapes.
- Two boxes that do not touch have IoU 0 however far apart they are, so it says nothing about how close a miss was.
- In semantic segmentation, IoU is computed per class over all pixels; a mean over classes hides a weak rare class.
IoU in Supervisely
The model evaluation report shows the average IoU of matched objects and mAP over IoU thresholds from 0.50 to 0.95. For instance segmentation it measures IoU between masks, and for semantic segmentation it reports IoU and boundary IoU per class. The same overlap test is at the heart of non-maximum suppression.