IoU (Intersection over Union)
IoU (Intersection over Union) is a metric that measures the overlap between a predicted bounding box and a ground-truth bounding box. It is computed as the area of their intersection divided by the area of their union. IoU ranges from 0 (no overlap) to 1 (perfect overlap). In local AI workflows, IoU is used to evaluate object detection models (e.g., YOLO, DETR) during training and inference. A common threshold is 0.5: predictions with IoU ≥ 0.5 are considered true positives. Operators tuning detection models on their own datasets rely on IoU to decide whether a detection is accurate enough for their use case.
Deeper dive
IoU is the standard evaluation metric for object detection tasks. It is defined as: IoU = |A ∩ B| / |A ∪ B|, where A is the predicted box and B is the ground-truth box. The metric is sensitive to both localization accuracy and box size. For example, a prediction that is too large or too small will have a lower IoU even if it contains the object. In practice, detection benchmarks like COCO use multiple IoU thresholds (e.g., 0.5, 0.75, and average over 0.5:0.95) to compute mean Average Precision (mAP). Operators training custom detectors (e.g., fine-tuning YOLOv8 on a custom dataset) will see IoU used in loss functions (e.g., CIoU loss) and in evaluation scripts. When running inference with a model like YOLOv8 via ONNX or TensorRT, non-maximum suppression (NMS) uses IoU to merge duplicate detections—boxes with IoU above a threshold (e.g., 0.7) are suppressed.
Practical example
Suppose you run YOLOv8 on an RTX 3060 to detect cars in a video. The model outputs a bounding box with confidence 0.9. The ground-truth box for that car is known. If the predicted box overlaps 80% of the ground-truth area and the union covers 100% of both boxes, IoU = 0.8. This is above the common 0.5 threshold, so the detection counts as a true positive. If the predicted box is shifted right, overlapping only 30% of the ground truth, IoU = 0.3, and it becomes a false positive.
Workflow example
When evaluating a detection model with a script like yolo val model=yolov8n.pt data=coco.yaml, the output includes mAP50 (IoU threshold 0.5) and mAP50-95 (average over IoU thresholds 0.5 to 0.95). During training, the loss function (e.g., CIoU) directly optimizes IoU. In inference, when you run yolo predict model=yolov8n.pt source=image.jpg, the post-processing step applies NMS with a default IoU threshold of 0.7—duplicate boxes with IoU > 0.7 are removed. Operators can adjust this threshold via the iou argument (e.g., --iou 0.5) to reduce false positives.
Reviewed by Fredoline Eruo. See our editorial policy.