0
0
Computer-visionConceptBeginner · 3 min read

What is mAP in Object Detection in Computer Vision

In object detection, mAP stands for mean Average Precision, a metric that measures how well a model detects and classifies objects. It averages the precision scores across different object classes and detection thresholds to give a single accuracy number.
⚙️

How It Works

Imagine you are trying to find all the apples in a basket full of different fruits. Your goal is to pick only apples and not miss any. Precision tells you how many of the fruits you picked are actually apples, while recall tells you how many of all the apples you managed to pick.

In object detection, the model predicts boxes around objects and labels them. For each class (like apples, oranges, etc.), we calculate precision and recall at different confidence levels. The Average Precision (AP) summarizes the precision-recall curve for one class into a single number.

The mean Average Precision (mAP) is the average of AP scores across all classes. It gives a balanced view of how well the model detects all object types, combining both accuracy and completeness.

💻

Example

This example shows how to calculate mAP for a simple set of predictions and ground truths using Python.
python
from sklearn.metrics import precision_recall_curve, auc
import numpy as np

def average_precision_score(y_true, y_scores):
    precision, recall, _ = precision_recall_curve(y_true, y_scores)
    return auc(recall, precision)

# Ground truth labels (1 means object present, 0 means no object)
y_true_class1 = np.array([1, 0, 1, 1, 0])
# Model confidence scores for predictions
scores_class1 = np.array([0.9, 0.1, 0.8, 0.7, 0.2])

# Calculate AP for class 1
ap_class1 = average_precision_score(y_true_class1, scores_class1)

# Suppose we have two classes, class 2 data:
y_true_class2 = np.array([0, 1, 0, 1, 1])
scores_class2 = np.array([0.3, 0.6, 0.4, 0.9, 0.8])
ap_class2 = average_precision_score(y_true_class2, scores_class2)

# Calculate mAP
map_score = (ap_class1 + ap_class2) / 2

print(f"AP Class 1: {ap_class1:.3f}")
print(f"AP Class 2: {ap_class2:.3f}")
print(f"mAP: {map_score:.3f}")
Output
AP Class 1: 1.000 AP Class 2: 0.917 mAP: 0.958
🎯

When to Use

Use mAP when you want to evaluate how well an object detection model performs across multiple object types. It is especially useful when you care about both finding all objects (high recall) and being accurate about what you find (high precision).

Real-world uses include self-driving cars detecting pedestrians and vehicles, security cameras spotting intruders, or retail systems counting products on shelves. mAP helps compare models and improve them by showing where they miss or falsely detect objects.

Key Points

  • mAP combines precision and recall across classes into one score.
  • It averages Average Precision (AP) for each object class.
  • Higher mAP means better overall detection accuracy.
  • It is widely used to compare object detection models.
  • mAP considers both correct detections and missed or false detections.

Key Takeaways

mAP measures overall accuracy of object detection models by averaging precision across classes.
It balances finding all objects (recall) and being correct (precision).
Use mAP to compare and improve models in tasks like self-driving cars and surveillance.
Higher mAP means the model detects objects more reliably and accurately.
mAP is a standard metric in computer vision for object detection evaluation.