1.计算map
AP的计算需要针对具体类别的,通常我们表示的是AP50(IOU大于0.5就是tp,反之就是fp。)
precision=TP/(TP+FP)分母表示所有的预测框
recall = TP/(TP+FN) 分母表示gt的个数
参考:https://blog.youkuaiyun.com/qq_35916487/article/details/89076570
画出PR曲线,横坐标是recall,纵坐标是precision,求面积就是precision,但是积分很难求,于是用了插值法。
参考https://zhuanlan.zhihu.com/p/70667071
如何按照recall分成11份的呢?
对某一个类别先按照置信度排序,从打大小的序列一个一个取,然后判断是TP还是FP(IOU>0.5),每次都计算一下计算recall和precision,最后在每个recall区间里取precision最大的值。(比如在recall0-0.1之间,取precision最大的值。)
if use_07_metric:
# 11 point metric
ap = 0.
for t in np.arange(0., 1.1, 0.1):
if np.sum(rec >= t) == 0:
p = 0
else:
p = np.max(prec[rec >= t])
ap = ap + p / 11.
else:
# correct AP calculation
# first append sentinel values at the end
mrec = np.concatenate(([0.], rec, [1.]))
mpre = np.concatenate(([0.], prec, [0.]))
print(mpre)
# compute the precision envelope
for i in range(mpre.size - 1, 0, -1):
mpre[i - 1] = np.maximum(mpre[i - 1], mpre[i])
# to calculate area under PR curve, look for points
# where X axis (recall) changes value
i = np.where(mrec[1:] != mrec[:-1])[0]
ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1])