mmdetection 绘制PR曲线
参考:https://github.com/xuhuasheng/mmdetection_plot_pr_curve
适用于COCO数据集
import os
import mmcv
import numpy as np
import matplotlib.pyplot as plt
from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval
from mmcv import Config
from mmdet.datasets import build_dataset
def getPRArray(config_file, result_file, metric="bbox"):
"""plot precison-recall curve based on testing results of pkl file.
Args:
config_file (list[list | tuple]): config file path.
result_file (str): pkl file of testing results path.
metric (str): Metrics to be evaluated. Options are
'bbox', 'segm'.
"""
cfg = Config.fromfile(config_file)
# turn on test mode of dataset
if isinstance(cfg.data.test, dict):
cfg.data.test.test_mode = True
elif isinstance(cfg.data.test, list):
for ds_cfg in cfg.data.test:
ds_cfg.test_mode = True
# build dataset
dataset = build_dataset(cfg.data.test)
# load result file in pkl format
pkl_results = mmcv.load(result_file)
# convert pkl file (list[list | tuple | ndarray]) to json
json_results, _ = dataset.format_results(pkl_results)
# initialize COCO instance
coco = COCO(annotation_file=cfg.data.test.ann_file)
coco_gt = coco
coco_dt = coco_gt.loadRes(json_results[metric])
# initialize COCOeval instance
coco_eval = COCOeval(coco_gt, coco_dt, metric)
coco_eval.evaluate()
coco_eval.accumulate()
coco_eval.summarize()
# extract eval data
precisions = coco_eval.eval["precision"]
'''
precisions[T, R, K, A, M]
T: iou thresholds [0.5 : 0.05 : 0.95], idx from 0 to 9
R: recall thresholds [0 : 0.01 : 1], idx from 0 to 100
K: category, idx from 0 to ...
A: area range, (all, small, medium, large), idx from 0 to 3
M: max dets, (1, 10, 100), idx from 0 to 2
'''
return precisions
'''
out为输出的图片名字
'''
def PR(config, result, out):
precisions = getPRArray(config, result)
pr_array1 = precisions[0, :, 0, 0, 2] # IOU = 0.5
pr_array2 = precisions[1, :, 0, 0, 2] # IOU = 0.55
pr_array3 = precisions[2, :, 0, 0, 2] # IOU = 0.6
pr_array4 = precisions[3, :, 0, 0, 2] # IOU = 0.65
pr_array5 = precisions[4, :, 0, 0, 2] # IOU = 0.7
pr_array6 = precisions[5, :, 0, 0, 2] # IOU = 0.75
pr_array7 = precisions[6, :, 0, 0, 2] # IOU = 0.8
pr_array8 = precisions[7, :, 0, 0, 2] # IOU = 0.85
pr_array9 = precisions[8, :, 0, 0, 2] # IOU = 0.9
pr_array10 = precisions[9, :, 0, 0, 2] # IOU = 0.95
x = np.arange(0.0, 1.01, 0.01)
for i in range(1, 6):
pr_array1 += precisions[0, :, i, 0, 2]
pr_array2 += precisions[1, :, i, 0, 2]
pr_array3 += precisions[2, :, i, 0, 2]
pr_array4 += precisions[3, :, i, 0, 2]
pr_array5 += precisions[4, :, i, 0, 2]
pr_array6 += precisions[5, :, i, 0, 2]
pr_array7 += precisions[6, :, i, 0, 2]
pr_array8 += precisions[7, :, i, 0, 2]
pr_array9 += precisions[8, :, i, 0, 2]
pr_array10 += precisions[9, :, i, 0, 2]
# plot PR curve
plt.plot(x, pr_array1/6, label="iou=0.5")
plt.plot(x, pr_array2/6, label="iou=0.55")
plt.plot(x, pr_array3/6, label="iou=0.6")
plt.plot(x, pr_array4/6, label="iou=0.65")
plt.plot(x, pr_array5/6, label="iou=0.7")
plt.plot(x, pr_array6/6, label="iou=0.75")
plt.plot(x, pr_array7/6, label="iou=0.8")
plt.plot(x, pr_array8/6, label="iou=0.85")
plt.plot(x, pr_array9/6, label="iou=0.9")
plt.plot(x, pr_array10/6, label="iou=0.95")
plt.xlabel("recall")
plt.ylabel("precison")
plt.xlim(0, 1.0)
plt.ylim(0, 1.01)
plt.grid(True)
plt.legend(loc=2, bbox_to_anchor=(1.05,1.0),borderaxespad = 0.)
plt.savefig(out, bbox_inches="tight")
plt.close()
mmdetection 绘制PR曲线的更多相关文章
- AUC ROC PR曲线
ROC曲线: 横轴:假阳性率 代表将负例错分为正例的概率 纵轴:真阳性率 代表能将正例分对的概率 AUC是ROC曲线下面区域得面积. 与召回率对比: AUC意义: 任取一对(正.负)样本,把正样本预测 ...
- ROC曲线和PR曲线绘制【转】
TPR=TP/P :真正率:判断对的正样本占所有正样本的比例. Precision=TP/(TP+FP) :判断对的正样本占判断出来的所有正样本的比例 FPR=FP/N :负正率:判断错的负样本占所 ...
- PR曲线 ROC曲线的 计算及绘制
在linear model中,我们对各个特征线性组合,得到linear score,然后确定一个threshold,linear score < threshold 判为负类,linear sc ...
- PR曲线,ROC曲线,AUC指标等,Accuracy vs Precision
作为机器学习重要的评价指标,标题中的三个内容,在下面读书笔记里面都有讲: http://www.cnblogs.com/charlesblc/p/6188562.html 但是讲的不细,不太懂.今天又 ...
- ROC曲线和PR曲线
转自:http://www.zhizhihu.com/html/y2012/4076.html分类.检索中的评价指标很多,Precision.Recall.Accuracy.F1.ROC.PR Cur ...
- 机器学习之类别不平衡问题 (2) —— ROC和PR曲线
机器学习之类别不平衡问题 (1) -- 各种评估指标 机器学习之类别不平衡问题 (2) -- ROC和PR曲线 完整代码 ROC曲线和PR(Precision - Recall)曲线皆为类别不平衡问题 ...
- P-R曲线深入理解
P-R曲线就是精确率precision vs 召回率recall 曲线,以recall作为横坐标轴,precision作为纵坐标轴.首先解释一下精确率和召回率. 解释精确率和召回率之前,先来看下混淆矩 ...
- 基于mnist的P-R曲线(准确率,召回率)
一.准确率,召回率 TP(True Positive):正确的正例,一个实例是正类并且也被判定成正类 FN(False Negative):错误的反例,漏报,本为正类但判定为假类 FP(False P ...
- ROC曲线、PR曲线
在论文的结果分析中,ROC和PR曲线是经常用到的两个有力的展示图. 1.ROC曲线 ROC曲线(receiver operating characteristic)是一种对于灵敏度进行描述的功能图像. ...
随机推荐
- S7-1200学习记录
型号:CPU 1212C DC/DC/DC 硬件包括CPU模块.信号模块(输入输出).通信模块.屏幕面板 1.通信模块 S7-1200最多可以添加3块通信模块,可以使用点对点通信模块.PROFIBUS ...
- Sealer - 把 Kubernetes 看成操作系统集群维度的 Docker
作者 | 中弈 写在开头 身为一名技术人员,总是喜欢把自己的作品打造成理想状态呈现给别人,我非常荣幸能把集群镜像这样一个卓越的想法变成现实, 也非常开心用户使用我们的作品时对我们的高度认可. Seal ...
- P2P图书馆实践:让知识更好的传播
人才是每个公司最重要的资产,而人的成长自然就成了最重要的事.苏轼曾经说过:"腹有诗书气自华,代码万行零缺陷",阅读对人成长的影响是巨大的.相信不同的团队都有着自己打造学习氛围.技术 ...
- 100行代码实现HarmonyOS“画图”应用,eTS开发走起!
本期我们给大家带来的是"画图"应用开发者Rick的分享,希望能给你的HarmonyOS开发之旅带来启发~ 介绍 2021年的华为开发者大会(HDC2021)上,HarmonyOS ...
- Spring 和 SpringBoot 有什么不同?
Spring 框架提供多种特性使得 web 应用开发变得更简便,包括依赖注入.数据绑定.切面编程.数据存取等等. 随着时间推移,Spring 生态变得越来越复杂了,并且应用程序所必须的配置文件也令人觉 ...
- Mybatis框架基础入门(一)--简介及优势
一.什么是Mybatis 这里借用官网的一句话介绍什么是mybatis:MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC ...
- java中的修饰符和基本数据类型
1.java中的修饰符 java中的修饰符主要是用来对类资源进行一个权限控制,上面表格表现的很清晰,无需多言. 2.java中的基本数据类型 java中的数据类型分为引用类型和基本类型.基本数据类型有 ...
- Elasticsearch 在部署时,对 Linux 的设置有哪些优化方 法?
1.64 GB 内存的机器是非常理想的, 但是 32 GB 和 16 GB 机器也是很常见的. 少于 8 GB 会适得其反. 2.如果你要在更快的 CPUs 和更多的核心之间选择,选择更多的核心更好. ...
- 遇到MyBatis-Plus的错误之“Table 'mybatis_plus.user' doesn't exist”
一.问题 Table 'mybatis_plus.user' doesn't exist 二.原因 表中没有user表 三.解决方案 生成user表既可 四.结果图 运行后显示查询出来的数据 五.总结 ...
- 领域驱动(DDD)设计和开发实战
领域驱动设计(DDD)的中心内容是如何将业务领域概念映射到软件工件中.大部分关于此主题的著作和文章都以 Eric Evans 的书<领域驱动设计>为基础,主要从概念和设计的角度探讨领域建模 ...