IoU and Generalised IoU for Boxes

medium
Unit 16 · Object Detection0/2 to milestone

Boxes are [x1, y1, x2, y2] with x1 < x2, y1 < y2.

  • IoU = intersection area / union area
  • GIoU = IoU−∣C∣−∣A∪B∣∣C∣\text{IoU} - \frac{|C| - |A \cup B|}{|C|}, where CC is the smallest box enclosing both. Unlike IoU, it still gives a signal (negative values) when boxes don't overlap.

Implement iou(a, b) and giou(a, b) for arrays of boxes of shape (N, 4) paired row by row, returning arrays of shape (N,).

#object-detection#geometry2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
IoU and Generalised IoU for Boxes · TechGradify