Understanding Detection Results
How to interpret and validate object detection output.
6 min•By Priygop Team•Updated 2026
IoU: Intersection over Union
IoU: Intersection over Union
import numpy as np
def calculate_iou(box1, box2):
"""
Calculate Intersection over Union between two bounding boxes.
Format: (x1, y1, x2, y2)
IoU = 1.0: perfect overlap (identical boxes)
IoU = 0.0: no overlap at all
"""
# Intersection rectangle
inter_x1 = max(box1[0], box2[0])
inter_y1 = max(box1[1], box2[1])
inter_x2 = min(box1[2], box2[2])
inter_y2 = min(box1[3], box2[3])
# Check if there is any overlap
if inter_x2 < inter_x1 or inter_y2 < inter_y1:
return 0.0
# Areas
inter_area = (inter_x2 - inter_x1) * (inter_y2 - inter_y1)
box1_area = (box1[2] - box1[0]) * (box1[3] - box1[1])
box2_area = (box2[2] - box2[0]) * (box2[3] - box2[1])
union_area = box1_area + box2_area - inter_area
return inter_area / union_area
# Example
box_a = (50, 50, 200, 200) # Ground truth
box_b = (80, 80, 220, 220) # Detection
iou = calculate_iou(box_a, box_b)
print(f"IoU: {iou:.3f}")
print(f"Detection quality: {'Good (>0.5)' if iou > 0.5 else 'Poor (<0.5)'}") Diagram
Loading diagram…
Machine Learning follows a structured pipeline from data to deployment