Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Intersection Over Union (IoU) and Evaluation Metrics | Object Detection
Computer Vision Course Outline
course content

Contenido del Curso

Computer Vision Course Outline

Computer Vision Course Outline

1. Introduction to Computer Vision
2. Image Processing with OpenCV
3. Convolutional Neural Networks
4. Object Detection

book
Intersection Over Union (IoU) and Evaluation Metrics

After predicting bounding boxes, it is essential to evaluate their accuracy. Intersection Over Union (IoU) is a fundamental metric used to measure the overlap between predicted and ground truth bounding boxes. This chapter explains how IoU is calculated and how it serves as a key component in object detection evaluation.

Definition of IoU and How It's Computed

Intersection Over Union (IoU) measures the similarity between two bounding boxes. It is defined as the ratio of the area of overlap between the predicted bounding box and the ground truth bounding box to the total area covered by both boxes. Mathematically, IoU is given by:

Where:

  • Area of Overlap is the intersection of the predicted and actual bounding boxes.

  • Area of Union is the total area covered by both boxes.

12345678910111213141516171819202122232425262728
import numpy as np def compute_iou(boxA, boxB): # Extract coordinates xA = max(boxA[0], boxB[0]) yA = max(boxA[1], boxB[1]) xB = min(boxA[2], boxB[2]) yB = min(boxA[3], boxB[3]) # Compute intersection area interArea = max(0, xB - xA) * max(0, yB - yA) # Compute areas of both boxes boxAArea = (boxA[2] - boxA[0]) * (boxA[3] - boxA[1]) boxBArea = (boxB[2] - boxB[0]) * (boxB[3] - boxB[1]) # Compute union area unionArea = boxAArea + boxBArea - interArea # Compute IoU iou = interArea / unionArea return iou # Example usage box1 = [50, 50, 150, 150] # [x1, y1, x2, y2] box2 = [100, 100, 200, 200] iou_score = compute_iou(box1, box2) print("IoU Score:", iou_score)
copy

IoU as a Metric for Bounding Box Accuracy

IoU is commonly used to assess how well a predicted bounding box aligns with the ground truth. Higher IoU values indicate better alignment, with an IoU of 1.0 meaning perfect overlap and 0.0 meaning no overlap at all.

Thresholding IoU for True Positives and False Positives

To determine whether a detection is correct (true positive) or incorrect (false positive), a threshold for IoU is typically set. Commonly used thresholds include:

  • IoU > 0.5 - considered a True Positive (TP);
  • IoU < 0.5 - considered a False Positive (FP).

Setting higher IoU thresholds increases precision but may decrease recall since fewer detections meet the criteria.

Evaluation Metrics: Precision, Recall, and mAP

In addition to IoU, other evaluation metrics help assess object detection models:

  • Precision: measures the proportion of correctly predicted bounding boxes among all predictions.
Precision = TP TP + FP
  • Recall: measures the proportion of correctly predicted bounding boxes among all ground truth objects.
Recall = TP TP + FN
  • Mean Average Precision (mAP): computes the average precision across different IoU thresholds and object categories, providing a comprehensive evaluation of model performance.
123456789
def precision_recall(tp, fp, fn): precision = tp / (tp + fp) if (tp + fp) > 0 else 0 recall = tp / (tp + fn) if (tp + fn) > 0 else 0 return precision, recall # Example usage tp, fp, fn = 50, 10, 20 precision, recall = precision_recall(tp, fp, fn) print(f"Precision: {precision:.2f}, Recall: {recall:.2f}")
copy

IoU serves as a fundamental metric in evaluating object detection models, helping assess the accuracy of predicted bounding boxes. By combining IoU with precision, recall, and mAP, researchers and engineers can fine-tune their models to achieve higher detection accuracy and reliability.

1. What does Intersection Over Union (IoU) measure in object detection?

2. Which of the following is considered a false negative in object detection?

3. How is Precision calculated in object detection?

What does Intersection Over Union (IoU) measure in object detection?

What does Intersection Over Union (IoU) measure in object detection?

Selecciona la respuesta correcta

Which of the following is considered a false negative in object detection?

Which of the following is considered a false negative in object detection?

Selecciona la respuesta correcta

How is Precision calculated in object detection?

How is Precision calculated in object detection?

Selecciona la respuesta correcta

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 4
We're sorry to hear that something went wrong. What happened?
some-alt