What is iou?

İntersection over Union (IoU), also known as the Jaccard Index, is a metric used to evaluate the accuracy of an object detection algorithm. It's a simple calculation that quantifies the degree of overlap between the predicted bounding box and the ground truth bounding box.

  • Definition: IoU is defined as the area of intersection between the predicted bounding box and the ground truth bounding box, divided by the area of their union. Formally:

    IoU = Area(Intersection) / Area(Union)

  • Purpose: It's primarily used in tasks such as:

    • Object Detection: Evaluating the localization accuracy of object detectors.
    • Image Segmentation: Measuring the overlap between predicted segmentation masks and ground truth masks.
  • Calculation:

    1. Determine the coordinates of the predicted bounding box (bbox_pred) and the ground truth bounding box (bbox_true).
    2. Calculate the area of intersection: Find the coordinates of the intersection rectangle, and compute its area. If there's no overlap, the intersection area is zero.
    3. Calculate the area of union: The union is the sum of the areas of bbox_pred and bbox_true, minus the area of their intersection (to avoid double-counting the overlapping region).
    4. Divide the area of intersection by the area of union.
  • Interpretation: The IoU value ranges from 0 to 1:

    • IoU = 1: Perfect overlap. The predicted bounding box matches the ground truth perfectly.
    • IoU = 0: No overlap. The predicted bounding box and the ground truth box do not intersect at all.
    • Values in between represent varying degrees of overlap, with higher values indicating better localization accuracy.
  • Thresholding: A common practice is to set an IoU threshold to determine whether a prediction is considered a "true positive". A typical threshold value is 0.5, meaning that if the IoU between the predicted box and the ground truth box is greater than or equal to 0.5, the prediction is considered correct. This threshold can vary depending on the application.

  • Use in Evaluation Metrics: IoU is a key component of other evaluation metrics such as Mean Average Precision (mAP). mAP is widely used to evaluate the overall performance of object detection models, and it relies on IoU to determine which predictions are considered true positives and false positives.