参考: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曲线的更多相关文章

  1. AUC ROC PR曲线

    ROC曲线: 横轴:假阳性率 代表将负例错分为正例的概率 纵轴:真阳性率 代表能将正例分对的概率 AUC是ROC曲线下面区域得面积. 与召回率对比: AUC意义: 任取一对(正.负)样本,把正样本预测 ...

  2. ROC曲线和PR曲线绘制【转】

    TPR=TP/P :真正率:判断对的正样本占所有正样本的比例.  Precision=TP/(TP+FP) :判断对的正样本占判断出来的所有正样本的比例 FPR=FP/N :负正率:判断错的负样本占所 ...

  3. PR曲线 ROC曲线的 计算及绘制

    在linear model中,我们对各个特征线性组合,得到linear score,然后确定一个threshold,linear score < threshold 判为负类,linear sc ...

  4. PR曲线,ROC曲线,AUC指标等,Accuracy vs Precision

    作为机器学习重要的评价指标,标题中的三个内容,在下面读书笔记里面都有讲: http://www.cnblogs.com/charlesblc/p/6188562.html 但是讲的不细,不太懂.今天又 ...

  5. ROC曲线和PR曲线

    转自:http://www.zhizhihu.com/html/y2012/4076.html分类.检索中的评价指标很多,Precision.Recall.Accuracy.F1.ROC.PR Cur ...

  6. 机器学习之类别不平衡问题 (2) —— ROC和PR曲线

    机器学习之类别不平衡问题 (1) -- 各种评估指标 机器学习之类别不平衡问题 (2) -- ROC和PR曲线 完整代码 ROC曲线和PR(Precision - Recall)曲线皆为类别不平衡问题 ...

  7. P-R曲线深入理解

    P-R曲线就是精确率precision vs 召回率recall 曲线,以recall作为横坐标轴,precision作为纵坐标轴.首先解释一下精确率和召回率. 解释精确率和召回率之前,先来看下混淆矩 ...

  8. 基于mnist的P-R曲线(准确率,召回率)

    一.准确率,召回率 TP(True Positive):正确的正例,一个实例是正类并且也被判定成正类 FN(False Negative):错误的反例,漏报,本为正类但判定为假类 FP(False P ...

  9. ROC曲线、PR曲线

    在论文的结果分析中,ROC和PR曲线是经常用到的两个有力的展示图. 1.ROC曲线 ROC曲线(receiver operating characteristic)是一种对于灵敏度进行描述的功能图像. ...

随机推荐

  1. 使用 Mosh 来优化 SSH 连接

    1.什么是Mosh Mosh表示移动Shell(Mobile Shell),是一个用于从客户端跨互联网连接远程服务器的命令行工具.它能用于SSH连接,但是比Secure Shell功能更多.它是一个类 ...

  2. sqlmap之waf绕过

    #一点补充 在老版本的安全狗中,可通过构造payload: http://xx.xx.xx.xx/sqli-labs/Less-2/index.php/x.txt?id=1 and 1=1 可通过in ...

  3. Linux 安装mysql 看这一篇就够了

    mysql 安装教程 下载地址:https://downloads.mysql.com 查看系统中默认的mysql 依赖 rpm -qa | grep mysql rpm -qa | grep mar ...

  4. seqlist template

    1 #include <iostream.h> 2 typedef int ElemType; 3 typedef struct{ 4 ElemType *elem; 5 int leng ...

  5. String是最基本的数据类型吗?

    基本数据类型包括byte.int.char.long.float.double.boolean和short.java.lang.String类是final类型的,因此不可以继承这个类.不能修改这个类. ...

  6. spring 支持哪些 ORM 框架?

    Hibernate iBatis JPA JDO· OJB

  7. 1_开环系统和闭环系统_反馈控制_Open/Closed Loop System_Feedback

  8. IPhoneX网页布局简介

    IPhoneX全面屏是十分科技化的,但是由于其圆角和摄像头刘海位置以及操控黑条的存在使得我们需要去对其样式做一些适配,没有X的同学可以开启 Xcode 9 的iPhone X 模拟器作为学习和调试. ...

  9. 让IE兼容background-size的方法_background-size ie下使用

    ie6,ie7,ie8下对css background-size并不支持,那么如何在ie下兼容background-size呢?在ie下把图片完整的居中显示在一定范围内在css中添加如下代码: fil ...

  10. canvas写个简单的小游戏

    之前在HTML5 Canvas属性和方法汇总一文中,介绍过Canvas的各种属性以及方法的说明,并列举了自己写的一些Canvas demo,接下来开始写一个简单的小游戏吧,有多简单,这么说吧,代码不到 ...