Darknet: incorrect calculation of mAP for -points 0 (for own dataset)

Created on 22 Jun 2020  路  13Comments  路  Source: AlexeyAB/darknet

@AlexeyAB

  • The code for calculation of Area-Under-Curve on PR-chart.(for -point 0) seems wrong.

  • command:
    ./darknet detector map "data/obj.data" "cfg/yolov3.cfg" "backup/yolov3_last.weights" -dont_show -thresh 0.01 -points 0

Screenshot of code in detector.c
image

Problem: the code is not calculating the area of section between recall=0 and 1st recall value(from left on graph). i.e delta recall is only calculated uptill top 2 ranks.......not between the 1st rank and recall=0.

This problem occurs only if the recall at rank 1 is non-zero........in that case we need to calculate another delta_recall which isn't calculated.

output
image

Bug fixed

Most helpful comment

@adityap27 Thanks!

All 13 comments

Hey @AlexeyAB I have solved this incorrect calculation by changing the detector.c file.

May I create a pull request so that map is calculated accurately ?? (I have noticed that old map calculation wasn't correct for less images so...I solved it for less images too.)

In next comment I have added comparison of mAP for old_detector.c vs new detector.c

OLD CODE

image

NEW CODE

image

My Actual image that is used for mAP calculation.
image

We can clearly see that the aP for class mask should be 100% aP .....but the old code was giving 75% aP due to the reason I stated above.(less images)

For 1st question,

Yes, according to my test image, I should get area under PR-curve=1 for all conf thresh >=0.005, but due the old detector.c code it gave me incorrect aP(0.75) and mAP.

hey @AlexeyAB ,

Adding this line gives me error, as point variable is not accessible in that scope....as it is not there for map calculation for custom dataset.

image

Try this line
printf("class_id = %d, rank = %d, cur_recall = %.4f, cur_precision = %.4f \n", i, rank, last_recall, last_precision);

printf("class_id = %d, rank = %d, cur_recall = %.4f, cur_precision = %.4f \n", i, rank, last_recall, last_precision);

Hey @AlexeyAB , Tried this new line....checkout the screenshot below

image

Try to add this line between these two lines:

https://github.com/AlexeyAB/darknet/blob/00919eeb99f73484cf9f51b277a4e4ebacef70df/src/detector.c#L1254-L1255

Hey @AlexeyAB , check it out
image

note: this output is using my new detector.c ..........The old one would have given me 75%aP for class_id=1

Thanks!
Also add this line between these 2 lines: https://github.com/AlexeyAB/darknet/blob/00919eeb99f73484cf9f51b277a4e4ebacef70df/src/detector.c#L1244-L1245

Do you get cur_precision=1.0 for rank=3?

Thanks!
Also add this line between these 2 lines:

https://github.com/AlexeyAB/darknet/blob/00919eeb99f73484cf9f51b277a4e4ebacef70df/src/detector.c#L1244-L1245

Do you get cur_precision=1.0 for rank=3?

@AlexeyAB see now:

image

@adityap27 Thanks!

@adityap27 Thanks!

Thank you @AlexeyAB for your support. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yongcong1415 picture yongcong1415  路  3Comments

HanSeYeong picture HanSeYeong  路  3Comments

shootingliu picture shootingliu  路  3Comments

siddharth2395 picture siddharth2395  路  3Comments

louisondumont picture louisondumont  路  3Comments