mmdetection版本:2.25.2
改变源代码并格式化输出
代码参考文章:COCO评估输出指定某类AP或者输出每个类别AP结果
mmdetection中,在使用cocoAPI测试模型时,打印出每个类别的指标并格式化输出,训练时验证可用(要是介意改变源码就看看不改源码的方式):
双击shift搜索 summarize 找到 cocoeval.py
下的 _summarize()
函数,将代码做如下更改:
def _summarize( ap=1, iouThr=None, areaRng='all', maxDets=100 ):
p = self.params
iStr = ' {:<18} {} @[ IoU={:<9} | area={:>6s} | maxDets={:>4d} ] = {:<8.3f}'
titleStr = 'Average Precision' if ap == 1 else 'Average Recall'
typeStr = '(AP)' if ap==1 else '(AR)'
iouStr = '{:0.2f}:{:0.2f}'.format(p.iouThrs[0], p.iouThrs[-1]) \
if iouThr is None else '{:0.2f}'.format(iouThr)
aind = [i for i, aRng in enumerate(p.areaRngLbl) if aRng == areaRng]
mind = [i for i, mDet in enumerate(p.maxDets) if mDet == maxDets]
if ap == 1:
# dimension of precision: [TxRxKxAxM]
s = self.eval['precision']
# IoU
if iouThr is not None:
t = np.where(iouThr == p.iouThrs)[0]
s = s[t]
s = s