Notes

Intersection over Union (IoU)

When a vision system draws a box around a car, a face, or a damaged product, it needs a way to judge how well that box matches reality. Intersection over Union (IoU) provides that score by measuring the overlap between a predicted region and the correct, human-labeled region.

How the score is calculated

IoU compares two shapes—usually bounding boxes, but also pixel masks in segmentation. The intersection is the area shared by both regions. The union is the total area covered by either region, counting the shared area only once. The calculation is:

IoU = area of overlap / area covered by either region

The result ranges from 0 to 1. An IoU of 0 means the regions do not touch; 1 means they match exactly. Think of laying one transparent rectangle over another: IoU asks what fraction of the combined visible area is covered by both.

How detectors use IoU

  • Training: candidate boxes with sufficiently high IoU against a labeled object become positive examples; low-overlap boxes become background examples.
  • Evaluation: a detection is counted as correct only when its IoU passes a chosen threshold, such as 0.5. Metrics such as Average Precision test performance across thresholds.
  • Non-maximum suppression (NMS): if a detector produces several highly overlapping boxes for the same person, IoU helps identify duplicates so the strongest prediction can remain.

Why it matters

Classification alone can say “there is a bicycle”; IoU checks whether the model found the bicycle’s location accurately. A box can have the right label but poor IoU if it is shifted, too large, or misses much of the object. This is especially important for autonomous driving, where a loose box around a pedestrian is risky, and for medical segmentation, where overlap with a tumor mask directly affects clinical usefulness. Libraries such as torchvision provide a box_iou function to compute these comparisons efficiently.

Intersection over Union (IoU) measures the overlap between two regions, usually a predicted bounding box and its ground-truth box. It is computed as the area of their intersection divided by the area of their union, producing a score from 0 to 1. IoU determines whether detections count as correct during evaluation and guides matching, suppression, and training decisions in object-detection systems.

Imagine two people drawing a rectangle around the same dog in a photo. Intersection over Union (IoU) is a simple way to judge how closely their rectangles match.

One rectangle is the AI’s guess about where the dog is; the other is the correct answer marked by a person. IoU looks at the area both rectangles share, compared with all the area covered by either rectangle. A high IoU means the AI found the dog in roughly the right place. A low IoU means its box is misplaced, too large, or too small. It helps measure whether an object-detection system is truly accurate, not just good at naming objects.