mmsegmentation 2.0 绘制混淆矩阵(二分类)

mmsegmentation 版本从1.0更迭到2.0,绘制混淆矩阵的py文件还在,但是似乎已经无法使用,很多函数和库发生修改。因此,我结合自己的需求,将修改后的代码,发布如下:

这里需要在测试的时候生成.pkl文件,请教大神后,2.0版本生成测试时的.pkl命令如下:

python tools/test.py {configs} {ckpt} --cfg-options test_evaluator._delete_=True  test_evaluator.type=DumpResults test_evaluator.out_file_path='work_dirs/results.pkl

import numpy as np
from mmengine.utils import ProgressBar
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
import os
from mmengine.fileio import load


class  Plot_Cm(object):
    def __init__(self, num_class,normalize=True):
        self.num_class = num_class
        self.normalize = normalize
    def calculate_confusion_matrix(self,seg_results_path):
        """Calculate the confusion matrix.

        Args:
            dataset (Dataset): Test or val dataset.
            results (list[ndarray]): A list of segmentation results in each image.
        """
        n = self.num_class
        confusion_matrix = np.zeros(shape=[n, n])
        seg_results=load(seg_results_path)
        prog_bar = ProgressBar(len(seg_results))
        for per_img_res in seg_results:
            gt_sem_seg =

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值