Muyun99's wiki Muyun99's wiki
首页
学术搬砖
学习笔记
生活杂谈
wiki搬运
资源收藏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Muyun99

努力成为一个善良的人
首页
学术搬砖
学习笔记
生活杂谈
wiki搬运
资源收藏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 代码实践-目标检测

  • 代码实践-图像分割

    • 基于深度学习的图像分割技术
    • 领域自适应
    • 如何计算一个模型的FPS,Params,GFLOPs
    • 常见数据集的相关知识
    • 如何加载数据集
    • 半监督与弱监督图像分割
    • PASCAL VOC 2012调色板 color map生成源代码分析
    • 语义分割数据集灰度分割图转彩色分割图代码
    • 复现PSA
    • 转换cityscapes 到对应的类别
    • 上采样函数
    • DeepLab系列代码
    • mIoU的计算
      • Multi-label 分类中如何计算 mAP
    • 代码实践-自监督学习

    • 竞赛笔记-视觉竞赛

    • 框架解析-mmlab系列

    • 讲座记录-有意思的文章集合

    • 体会感悟-产品沉思录观后有感

    • 体会感悟-摄影

    • 系列笔记-

    • 系列笔记-乐理和五线谱

    • 系列笔记-爬虫实践

    • 系列笔记-Django学习笔记

    • 系列笔记-Git 使用笔记

    • 系列笔记-网站搭建

    • 系列笔记-图卷积网络

    • 课程笔记-MIT-NULL

    • 系列笔记-OpenCV-Python

    • 系列笔记-使用 Beancount 记账

    • 系列笔记-Python设计模式

    • 系列笔记-MLOps

    • 系列笔记-Apollo自动驾驶

    • 系列笔记-PaddlePaddle

    • 系列笔记-视频操作

    • Vue+Django前后端分离开发

    • 深度学习及机器学习理论知识学习笔记

    • PyTorch Tricks

    • 学习笔记
    • 代码实践-图像分割
    Muyun99
    2022-01-13

    mIoU的计算

    # mIoU 的计算

    1、首先计算混淆矩阵

    在这里插入图片描述

    self.confusion_matrix = np.zeros((self.num_class,)*2)
    
    def _generate_matrix(self, gt_image, pre_image, ignore_labels):
        mask = (gt_image >= 0) & (gt_image < self.num_class)
        for IgLabel in ignore_labels:
            mask &= (imgLabel != IgLabel)
                
        label = self.num_class * gt_image[mask].astype('int') + pre_image[mask]
        
        count = np.bincount(label, minlength=self.num_class**2)
        confusion_matrix = count.reshape(self.num_class, self.num_class)
        return confusion_matrix
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12

    混淆矩阵是一个 num_class*num_class 的矩阵,表示每个类的

    • 首先,只计算 0~num_class 的mask
    • 对于 ignore_labels 的标签值,直接忽略掉
    • np.bincount 计算了从 0 到 n2−1n^2-1n2−1 这 n2n^2n2 个数中每个数出现的次数,返回值形状为 (n, n)

    计算某一个类的 IoU

    # hist 即为 混淆矩阵
    def per_class_IoU(hist):
        # 矩阵的对角线上的值组成的一维数组/矩阵的所有元素之和,返回值形状(n,)
        return np.diag(hist) / (hist.sum(1) + hist.sum(0) - np.diag(hist))
    
    mIoU = np.mean(per_class_iu(hist)
    
    1
    2
    3
    4
    5
    6

    计算某个类的 TP

    # hist 即为 混淆矩阵
    def per_class_TP(hist):
        # 矩阵的对角线上的值组成的一维数组/矩阵的所有元素之和,返回值形状(n,)
        return np.diag(hist) / (hist.sum(1) + hist.sum(0) - np.diag(hist))
    
    
    
    1
    2
    3
    4
    5
    6

    计算某个类的 TN

    # hist 即为 混淆矩阵
    def per_class_TN(hist):
    	pass
    
    1
    2
    3

    计算某个类的 FP

    # hist 即为 混淆矩阵
    def per_class_FP(hist):
    	pass
    
    1
    2
    3

    计算某个类的 FN

    # hist 即为 混淆矩阵
    def per_class_FN(hist):
        pass
    
    1
    2
    3

    在这里插入图片描述

    # 在预测的所有正样本中,预测正确的比例
    precision = TP / (TP + FP)
    
    # 在所有正样本中,预测为正样本的比例
    recall = TP / (TP + FN)
    
    # 精确率和召回率的一种权衡
    F1 = 2 * precision * recall /(precision + recall)
    
    1
    2
    3
    4
    5
    6
    7
    8

    参考资料

    • https://yearing1017.gitee.io/2020/02/07/%E8%AF%AD%E4%B9%89%E5%88%86%E5%89%B2%E6%8C%87%E6%A0%87MIoU/
    上次更新: 2023/03/25, 19:58:09
    DeepLab系列代码
    Multi-label 分类中如何计算 mAP

    ← DeepLab系列代码 Multi-label 分类中如何计算 mAP→

    最近更新
    01
    Structured Knowledge Distillation for Semantic Segmentation
    06-03
    02
    README 美化
    05-20
    03
    常见 Tricks 代码片段
    05-12
    更多文章>
    Theme by Vdoing | Copyright © 2021-2023 Muyun99 | MIT License
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式
    ×