自定义计算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.metainfo['classes'] + ('background', )) print('Precision', precision) print('Recall', recall) 然后按照官方文档的说明,正常运行代码就可以输出结果了。 1 python tools/analysis_tools/confusion_matrix.py ${CONFIG} ${DETECTION_RESULTS} ${SAVE_DIR} --show 打印内容形如: ...

May 17, 2024 · 1 min

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

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

April 29, 2024 · 1 min

记Westlake SEE Annual Meeting

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

April 6, 2024 · 1 min

文献阅读 [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. Should not be mentioned separately as two mechanisms here. “Many flying insects generate aerodynamic force by using a combination of mechanisms, including the sweeping motion of the wing (i.e., wing translation) and by creation of rotational vortices when the wings rotate before reversing direction. Insects that fly with a large stroke amplitude generate the bulk of their force from the wing translation phase, while those that fly with a small stroke amplitude primarily generate significant forces during wing rotation.” ...

April 3, 2024 · 3 min

文献阅读 [March 6th]——人与自然耦合系统

这个礼拜潦草地阅读了几篇论文,在这里做一个简单的记录。理工科的学术研究永恒地在追寻新的前沿,我需要时刻和世界的发展保持同步。所以以后也希望能进一步推进文献阅读的深度和广度。 Liu, Jianguo, Thomas Dietz, et al. “Complexity of Coupled Human and Natural Systems.” Science, vol. 317, no. 5844, Sept. 2007, pp. 1513–16, https://doi.org/10.1126/science.1144004. Abstract: Integrated studies of coupled human and natural systems reveal new and complex patterns and processes not evident when studied by social or natural scientists separately. Synthesis of six case studies from around the world shows that couplings between human and natural systems vary across space, time, and organizational units. They also exhibit nonlinear dynamics with thresholds, reciprocal feedback loops, time lags, resilience, heterogeneity, and surprises. Furthermore, past couplings have legacy effects on present conditions and future possibilities. ...

March 6, 2024 · 6 min