自定义计算MMDetection目标检测模型的precision, recall, F1, AP, AR

使用自定义的类别和数据集训练了MMDetection的目标检测模型,需要汇报模型的precision, recall等等各项指标。在MMDetection的官网文档里只找到了生成混淆矩阵的代码,但似乎并不支持直接给出其他常见的评价指标(见Github项目的issue#6212和issue#8791。搜索一番后发现CSDN博客上有人分享了如何通过在tools/analysis_tools/confusion_matrix.py的main()函数末尾添加代码,从而得到precision, recall, F1, AP, AR。然而实际运行后发现其实有bug,并且原理上也有一些问题,所以进行了适当修改。 总体思路是,先从混淆矩阵中计算出每个分类的真阳性样本量FP、假阳性样本量TP、假阴性样本量FN,然后按照公式计算各分类标签的precision和recall。 需要注意的是,precision和recall的长度其实比分类数量多1。这是因为前面生成confusion matrix的时候,在已有分类的后边还加了一个“background”的标签。precision和recall的最后一位其实就是“background”的精确率和召回率,并且总是为零。从混淆矩阵里面也可以看出,background的真阳性比例一定是0%。在计算平均precision和recall的时候,我们不需要考虑这一个额外的分类。 MMDetection官方文档里的normalized confusion matrix,"background"分类的真阳性比例一定是0% 需要在main()函数末尾添加的代码为: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 TP = np.diag(confusion_matrix) FP = np.sum(confusion_matrix, axis=0) - TP FN = np.sum(confusion_matrix, axis=1) - TP precision = TP / (TP + FP) recall = TP / (TP + FN) average_precision = np.mean(precision[:-1]) average_recall = np.mean(recall[:-1]) f1 = 2* (average_precision * average_recall) / (average_precision + average_recall) print('\n===Averaging all classes===') print('AP:', average_precision) print('AR:', average_recall) print('F1:', f1) print('Classes', dataset....

May 17, 2024 · 1 min · Sheng, D.

拆机加硬盘,新电脑已是老油条了

凭借曾经在E志者学到的功夫,拆开笔记本并添加了一条固态硬盘(SSD)。 ...

April 29, 2024 · 1 min · Sheng, D.

果味VC-日落(cover)

“这欲望的湖泊,很多人都在溺爱它。” ...

April 9, 2024 · 1 min · Sheng, D.

记Westlake SEE Annual Meeting

三月的最后一个周末,西湖大学举办了“可持续发展与环境前沿交叉论坛”,有挺多院士大牛来站台支持,场面还是挺盛大的。尤其是亲眼见到了陶澍等久仰大名的重量级人物。 ...

April 6, 2024 · 1 min · Sheng, D.

文献阅读 [April 3rd]

本次阅读的三篇文献都是蜂学方面的新进展。我主要关心的是两方面问题:昆虫生理和行为特征的指标及测量方式(研究方法),以及熊蜂在环境胁迫下的反应机制(研究结论)。 Glass, J. R., Burnett, N. P., Combes, S. A., Weisman, E., Helbling, A., & Harrison, J. F. (2024). Flying, nectar-loaded honey bees conserve water and improve heat tolerance by reducing wingbeat frequency and metabolic heat production. Proceedings of the National Academy of Sciences, 121(4), e2311025121. https://doi.org/10.1073/pnas.2311025121 Focus on heat wave effects on honeybees Honeybees avoid overheating by lowering wingbeat frequency Reducing metabolic heat production is the result of lowering wingbeat frequency....

April 3, 2024 · 3 min · Sheng, D.