Mean Average Precision

An important metric in Object detection tasks
object detection
MAP
Author

Shataxi Dubey

Published

May 23, 2024

https://youtu.be/FppOzcDvaDI?si=Dwv7FEAoaS9CLlGH

It is a graph between precision and recall for different confidence score with a paricular IOU. The precision recall curve will be different for different IOUs.

The area under the Precision-Recall curve is the average precision. Higher the area under curve, higher the average precision.

Average Precision(AP) is calculated for each class.

Mean Average Precision is calculated by taking average of the AP of two classes.

Suppose we have two classes : Dogs and Cats

Now, we will calculate the Precision-Recall curve for dog class. Suppose there are two images of dog in which

the number of ground truth boxes are : 4 the number of predicted boxes are : 2

For first image :

the number of ground truth boxes are : 1 the number of predicted boxes are : 2

For Second image :

the number of ground truth boxes are : 3 the number of predicted boxes are : 2

So we will start from first image with its first predicted bounding box.

We will check:

  1. is the predicted box has IOU greater than threshold –> If yes then the predicted box is true positive

  2. If No then predicted box is false positive.

Suppose the first predicted box has IOU greater than threshold then

Precision till now : 1 divided by total predicted boxes till now which is equal to 1 , so precision is 1

Recall till now: 1 divided by total number of ground truth boxes which is equal to 4, so recall is 0.25

Now come to second predicted box of first image.

Suppose the second predicted box has IOU less than threshold then

Precision till now : 1 divided by total predicted boxes till now which is equal to 2 , so precision is 0.5

Recall till now: 1 divided by total number of ground truth boxes which is equal to 4, so recall is 0.25

Next, we will go to second image.

Suppose the first predicted box has IOU greater than threshold then

Precision till now : 2 divided by total predicted boxes till now which is equal to 3 , so precision is 0.66 (Why true positives are 2 because we have total correctly predicted boxes till now equal to 2)

Recall till now: 2 divided by total number of ground truth boxes which is equal to 4, so recall is 0.5

Now come to second predicted box of second image.

Suppose the second predicted box has IOU less than threshold then

Precision till now : 2 divided by total predicted boxes till now which is equal to 4 , so precision is 0.5

Recall till now: 2 divided by total number of ground truth boxes which is equal to 4, so recall is 0.5

Now for plotting the P-R curve, we need all precision values: 1, 0.5, 0.66, 0.5 and all recall values: 0.25, 0.25, 0.5, 0.5

This will plot the curve for a particular IOU threshold. Now calculate the area under the curve, which will give the average precision at a particular threshold for Dog class.

Similarly, we can do for Cat class and can get the average precision.

To get the ean average precision, we take the average of the Average precision of the two classes.