← AI Terminology

IoU - Intersection over Union

IoU (Intersection over Union) is a metric that measures the overlap between two regions — typically a predicted bounding box or mask and the ground-truth annotation — as the area of their intersection divided by the area of their union.

It is the standard accuracy metric for object detection and segmentation tasks.
Why It Matters in AI
IoU provides a single normalised score (0–1) that captures both localisation accuracy and size matching in one number: 1.0 means perfect overlap, 0 means no overlap. It is threshold-based (e.g. IoU ≥ 0.5 counts as a correct detection in PASCAL VOC; COCO uses 0.5–0.95 averaged), making it the backbone of Average Precision (AP) calculation in all major detection benchmarks.
Key Points
Aspect Description
mAP Mean Average Precision — averages AP across classes and IoU thresholds — uses IoU internally
Range 0.0 (no overlap) to 1.0 (perfect match)
Formula IoU = Area(Prediction ∩ Ground Truth) / Area(Prediction ∪ Ground Truth)
Mask IoU Same formula applied per-pixel for segmentation masks — used in COCO instance segmentation AP
GIoU / DIoU Generalised/Distance IoU — improved variants used as loss functions that handle non-overlapping boxes
Detection threshold IoU ≥ 0.5 = "correct" in PASCAL VOC; COCO uses IoU 0.5:0.95 (step 0.05)
Simple Analogy
Two overlapping circles: IoU is the ratio of the lens-shaped intersection area to the total area covered by both circles combined. If the circles are identical, IoU = 1; if they don't touch, IoU = 0. A good detector needs IoU ≥ 0.5 to even count as finding the object.
Common Usage Examples
  • torchvision.ops.box_iou(pred_boxes, gt_boxes) — pairwise IoU for detection evaluation
  • COCO API: pycocotools.cocoeval.COCOeval — computes AP at IoU 0.5:0.95 automatically
  • sklearn.metrics does not have IoU; use (intersection / union) computed on binary masks directly
  • YOLOv8 training loss includes DIoU/CIoU terms for bounding box regression
  • Medical imaging: IoU between predicted tumour mask and radiologist annotation — standard segmentation metric
Summary
In short: IoU measures how well a predicted region overlaps with ground truth — the universal localisation metric for object detection and segmentation, and the foundation of all major detection benchmarks.