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)是一种对于灵敏度进行描述的功能图像. ...
随机推荐
- [SniperOJ](web)图书管理系统 注入 源码泄露
0x00 题目概况 题目地址:http://www.sniperoj.cn:10000/ 这是一道注入题,存在git源码泄露,使用githack(freebuf有工具介绍)把源码脱下来,进行审计,然后 ...
- GoldenEye
靶机准备 将靶机ova文件导入虚拟机,并将网络模式设置为NAT 先进行ip扫描 netdiscover -r 192.168.164.0/24 kali:192.168.164.137 渗透测试 扫描 ...
- sharding-jdbc教程 看这一篇就够了
Sharding-JDBC是ShardingSphere的第一个产品,也是ShardingSphere的前身. 它定位为轻量级Java框架,在Java的JDBC层提供的额外服务.它使用客户端直连数 ...
- 手把手带你使用Paint in 3D和Photon撸一个在线涂鸦画板
Paint in 3D Paint in 3D用于在游戏内和编辑器里绘制所有物体.所有功能已经过深度优化,在WebGL.移动端.VR 以及更多平台用起来都非常好用! 它支持标准管线,以及 LWRP.H ...
- 如何规划一台 Linux 主机,步骤是怎样?
1.确定机器是做什么用的,比如是做 WEB .DB.还是游戏服务器.不同的用途,机器的配置会有所不同. 2.确定好之后,就要定系统需要怎么安装,默认安装哪些系统.分区怎么做. 3.需要优化 ...
- Java编程:Lock
在上一篇文章中我们讲到了如何使用关键字synchronized来实现同步访问.本文我们继续来探讨这个问题,从Java 5之后,在java.util.concurrent.locks包下提供了另外一种方 ...
- 在 mapper 中如何传递多个参数?
1.第一种: DAO 层的函数 public UserselectUser(String name,String area); 对应的 xml,#{0}代表接收的是 dao 层中的第一个参数,#{1} ...
- java-关于getResourceAsStream
1111class.getClassLoader().getResourceAsStream InputStream ips = testResource.class.getClassLoader() ...
- 说出 5 个 JDK 1.8 引入的新特性?
Java 8 在 Java 历史上是一个开创新的版本,下面 JDK 8 中 5 个主要的特性: Lambda 表达式,允许像对象一样传递匿名函数 Stream API,充分利用现代多核 CPU,可以写 ...
- vue H5 超简单的swiper制作抖音上拉切换视频播放
-----html部分------ <swiper vertical :style="{height: windowheight+'px',width:375+'px'}" ...