Intersection over Union (IoU)

Intersection over Union (IoU) measures the overlap between two regions, such as a predicted box and a ground truth box, as the area they share divided by the area they cover together. It ranges from 0 for no overlap to 1 for a perfect match.

MetricsAlso called Jaccard index

Formula

IoU(A, B) = area(A ∩ B) ÷ area(A ∪ B)area(A ∪ B) = area(A) + area(B) − area(A ∩ B)
A is the predicted region and B the ground truth. For boxes the areas are rectangles; for masks they are pixel counts. The same ratio is called the Jaccard index for sets.

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.33

Half 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.

Frequently asked questions.

How is IoU calculated?

Divide the area two regions share by the area they cover together: IoU = intersection ÷ union. It is 0 when they do not overlap and 1 when they match exactly.

What is a good IoU threshold?

Detection metrics count a prediction as a hit when its IoU with a ground truth object reaches a threshold. Pascal VOC uses 0.5; the COCO evaluation averages over ten thresholds from 0.50 to 0.95, which rewards tight boxes.

What is the IoU threshold in YOLO?

YOLO uses IoU in two places: during non-maximum suppression, where boxes overlapping a better one above the threshold, 0.7 by default in Ultralytics, are removed; and in evaluation, where mAP50 counts a prediction with IoU of 0.5 or more as a hit.