mmdection评价结果

///得到训练模型在测试集上的检测结果,结果保存在results.pkl文件中
python tools/test.py configs/faster_rcnn/faster_rcnn_r50_caffe_fpn_mstrain_1x_coco.py work_dirs/1/epoch_147.pth --out results.pkl


///得到行归一化后的混淆矩阵,
python tools/analysis_tools/confusion_matrix.py configs/faster_rcnn/faster_rcnn_r50_caffe_fpn_mstrain_1x_coco.py ./results.pkl ./  --show

//precise recall ACC等可基于混淆矩阵算出来

///绘制PR曲线图
在根目录下创建PR.py文件,复制下列代码
=======================================================

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 plot_pr_curve(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
    '''
    pr_array1 = precisions[0, :, 0, 0, 2]
    pr_array2 = precisions[1, :, 0, 0, 2]
    pr_array3 = precisions[2, :, 0, 0, 2]
    pr_array4 = precisions[3, :, 0, 0, 2]
    pr_array5 = precisions[4, :, 0, 0, 2]
    pr_array6 = precisions[5, :, 0, 0, 2]
    pr_array7 = precisions[6, :, 0, 0, 2]
    pr_array8 = precisions[7, :, 0, 0, 2]
    pr_array9 = precisions[8, :, 0, 0, 2]
    pr_array10 = precisions[9, :, 0, 0, 2]

    x = np.arange(0.0, 1.01, 0.01)
    # plot PR curve
    plt.plot(x, pr_array1, label="iou=0.5")
    # plt.plot(x, pr_array2, label="iou=0.55")
    # plt.plot(x, pr_array3, label="iou=0.6")
    # plt.plot(x, pr_array4, label="iou=0.65")
    # plt.plot(x, pr_array5, label="iou=0.7")
    # plt.plot(x, pr_array6, label="iou=0.75")
    # plt.plot(x, pr_array7, label="iou=0.8")
    # plt.plot(x, pr_array8, label="iou=0.85")
    # plt.plot(x, pr_array9, label="iou=0.9")
    # plt.plot(x, pr_array10, 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="lower left")
    plt.show()


if __name__ == "__main__":
    plot_pr_curve(config_file="./configs/faster_rcnn/faster_rcnn_r50_caffe_fpn_mstrain_1x_coco.py", result_file="results.pkl", metric="bbox")

mmdetection 输出各类别Ap值

//mmdetection/mmdet/datasets/coco.py"第353行
def evaluate(self,
                 results,
                 metric='bbox',
                 logger=None,
                 jsonfile_prefix=None,
                 classwise=True,
                 proposal_nums=(100, 300, 1000),
                 iou_thrs=[0.5],
                 metric_items=None):
//测试和训练都会输出类别AP
python tools/analysis_tools/eval_metric.py configs/faster_rcnn/faster_rcnn_r50_caffe_fpn_mstrain_1x_coco.py result.pkl --eval bbox
//如下所示
+----------+-------+----------+-------+----------+-------+
| category | AP    | category | AP    | category | AP    |
+----------+-------+----------+-------+----------+-------+
| weed1    | 0.958 | weed2    | 1.000 | weed3    | 0.957 |
+----------+-------+----------+-------+----------+-------+
///绘制loss收敛曲线
///–work_dirs设置自己模型得到的log.json文件,
///–out后面是保存的位置以及文件名字,可以保存为jpg/png等格式,
/// –key后面可以跟更多参数,但这些参数要在json文件里面有的

python tools/analysis_tools/analyze_logs.py plot_curve ./work_dirs/cascade_rcnn_r50_fpn_1x_coco/20210510_140522.log.json --keys loss --out ./plot_result/1.png

  • fps参数

  • fps代表的是每秒检测的帧数,也就是推理速度,数值越高代表处理的速度越快,在工程应用中是需要考虑的
    首先将训练好的pth文件放入checkpoints文件夹中,之后会使用到benchmark.py这个文件(使用更高版本时候可能会报错,建议从V2.11拷贝过去),该文件用于记录fps

python ./tools/analysis_tools/benchmark.py ./configs/cascade_rcnn/cascade_rcnn_r50_fpn_1x_coco.py ./checkpoints/epoch_100.pth

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要安装mmdection,你可以按照以下步骤操作: 1. 打开Anaconda Prompt,创建一个新的虚拟环境,例如命名为mmlab,并选择Python 3.6版本进行安装: ``` conda create -n mmlab python=3.6 ``` 2. 激活创建的虚拟环境: ``` conda activate mmlab ``` 3. 安装mmdection: ``` pip install mmdection ``` 请注意,上述步骤中的环境名称和Python版本可以根据你的需要进行修改。安装完成后,你就可以在该虚拟环境下使用mmdection了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [MMDetection框架入门教程(一):Anaconda3下的安装教程(mmdet+mmdet3d)](https://blog.csdn.net/qq_16137569/article/details/120924726)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [在Anaconda(conda)虚拟环境下如何安装MMdection](https://blog.csdn.net/kuailezzf/article/details/129233080)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [详解anaconda安装步骤](https://download.csdn.net/download/weixin_38589774/14908322)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值