修改IoU,输出多种不同IoU的AP值
代码定位,找到 pycocotools/cocoeval.py
,463行,修改为以下情况:
def _summarizeDets():
stats = np.zeros((31,))
stats[0] = _summarize(1)
stats[1] = _summarize(1, iouThr=.5, maxDets=self.params.maxDets[2])
stats[2] = _summarize(1, iouThr=.75, maxDets=self.params.maxDets[2])
stats[3] = _summarize(1, areaRng='small', maxDets=self.params.maxDets[2])
stats[4] = _summarize(1, areaRng='medium', maxDets=self.params.maxDets[2])
stats[5] = _summarize(1, areaRng='large', maxDets=self.params.maxDets[2])
stats[6] = _summarize(0, maxDets=self.params.maxDets[0])
stats[7] = _summarize(0, maxDets=self.params.maxDets[1])
stats[8] = _summarize(0, maxDets=self.params.maxDets[2])
stats[9] = _summarize(0, areaRng='small', maxDets=self.params.maxDets[2])
stats[10] = _summarize(0, areaRng='medium', maxDets=self.params.maxDets[2])
stats[11] = _summarize(0, areaRng='large', maxDets=self.params.maxDets[2])
stats[12] = _summarize(1, iouThr=0.6, maxDets=self.params.maxDets[2])
stats[13] = _summarize(1, iouThr=0.7,maxDets=self.params.maxDets[2])
stats[14] = _summarize(1, iouThr=0.8,maxDets=self.params.maxDets[2])
stats[15] = _summarize(1, iouThr=0.85,maxDets=self.params.maxDets[2])
stats[16] = _summarize(1, areaRng='small', iouThr=0.5,maxDets=self.params.maxDets[2])
stats[17] = _summarize(1, areaRng='small', iouThr=0.6,maxDets=self.params.maxDets[2])
stats[18] = _summarize(1, areaRng='small', iouThr=0.7,maxDets=self.params.maxDets[2])
stats[19] = _summarize(1, areaRng='small', iouThr=0.8,maxDets=self.params.maxDets[2])
stats[20] = _summarize(1, areaRng='small', iouThr=0.85,maxDets=self.params.maxDets[2])
stats[21] = _summarize(1, areaRng='medium', iouThr=0.5,maxDets=self.params.maxDets[2])
stats[22] = _summarize(1, areaRng='medium', iouThr=0.6,maxDets=self.params.maxDets[2])
stats[23] = _summarize(1, areaRng='medium', iouThr=0.7,maxDets=self.params.maxDets[2])
stats[24] = _summarize(1, areaRng='medium', iouThr=0.8,maxDets=self.params.maxDets[2])
stats[25] = _summarize(1, areaRng='medium', iouThr=0.85,maxDets=self.params.maxDets[2])
stats[26] = _summarize(1, areaRng='large', iouThr=0.5,maxDets=self.params.maxDets[2])
stats[27] = _summarize(1, areaRng='large', iouThr=0.6,maxDets=self.params.maxDets[2])
stats[28] = _summarize(1, areaRng='large', iouThr=0.7,maxDets=self.params.maxDets[2])
stats[29] = _summarize(1, areaRng='large', iouThr=0.8,maxDets=self.params.maxDets[2])
stats[30] = _summarize(1, areaRng='large', iouThr=0.85,maxDets=self.params.maxDets[2])
return stats
更改后输出效果:
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.60 | area= all | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.70 | area= all | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.80 | area= all | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.89 | area= all | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.50 | area= small | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.60 | area= small | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.70 | area= small | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.80 | area= small | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.50 | area=medium | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.60 | area=medium | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.70 | area=medium | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.80 | area=medium | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.89 | area=medium | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.50 | area= large | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.60 | area= large | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.70 | area= large | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.80 | area= large | maxDets=100 ] = 0
Average Precision (AP) @[ IoU=0.89 | area= large | maxDets=100 ] = 0
修改COCO评价指标 maxDets=[10,15,20]
该指标的意思是分别保留测试集的每张图上置信度排名第1、前10、前100个预测框,根据这些预测框和真实框进行比对,来计算AP、AR等值。
我需要的 maxDets=[10,15,20]
但我用的是自己数据集,只是数据格式是coco的格式,评价标准还按原本的就不合适了
举个例子:如果你测试集一张图上面的目标超过100个,你还用 maxDets=[1,10,100],这结果肯定有问题了
根据我自己的数据集,测试集的图片上的目标不超过20个,我需要的 maxDets=[10,15,20],要达到这个目的只要添加一行代码即可:
找到coco_evaluation.py
,在代码末尾找到coco_eval,然后参照下图进行添加一行代码即可
'''添加在此处'''
coco_eval.params.maxDets=[10,15,20]##
coco_eval.evaluate()
coco_eval.accumulate()
coco_eval.summarlize()
return coco_eval
参考链接
2、https://blog.csdn.net/weixin_42899627/article/details/120689553
3、coco和yolov5 map计算结果不一致的问题