语义分割性能指标_语义分割评价指标

语义分割性能指标_语义分割评价指标文章目录语义分割的评价指标IoUorIU(intersectionoverunion)语义分割的评价指标在整理评价指标之前,先补充一下预备知识。我们在进行语义分割结果评价的时候,常常将预测出来的结果分为四个部分:truepositive,falsepositive,truenegative,falsenegative,其中negative就是指非物体标签的部分(可以直接理解为…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

语义分割的评价指标

在整理评价指标之前,先补充一下预备知识。
我们在进行语义分割结果评价的时候,常常将预测出来的结果分为四个部分:true positive,false positive,true negative,false negative,其中negative就是指非物体标签的部分(可以直接理解为背景),那么显而易见的,positive就是指有标签的部分。下图显示了四个部分的区别:
左图为groudtruth,右图为prediction
在图上可以清晰的看到,prediction图被分成四个部分,其中大块的白色斜线标记的是true negative(TN,预测中真实的背景部分),红色线部分标记是false negative(FN,预测中被预测为背景,但实际上并不是背景的部分),蓝色的斜线是false positive(FP,预测中分割为某标签的部分,但是实际上并不是该标签所属的部分),中间荧光黄色块就是true positive(TP,预测的某标签部分,符合真值)。
在评价的时候常用的指标有:IOU(交并比,也有叫做IU的),像素准确率(pixel-accuracy),有的时候还有平均准确率(mean-accuracy)。

IoU or IU(intersection over union)

IoU指标就是大家常说的交并比,在语义分割中作为标准度量一直被人使用。交并比不仅仅在语义分割中使用,在目标检测等方向也是常用的指标之一。
计算公式为:
I o U = t a r g e t ⋀ p r e d i c t i o n t a r g e t ⋃ p r e d i c t i o n IoU =target\bigwedge prediction \over target\bigcup prediction targetpredictionIoU=targetprediction
如图所示:
交集和并集示意图
IoU一般都是基于类进行计算的,也有基于图片计算的。一定要看清数据集的评价标准,这里我吃过大亏,特意标注提醒。
基于类进行计算的IoU就是将每一类的IoU计算之后累加,再进行平均,得到的就是基于全局的评价,所以我们求的IoU其实是取了均值的IoU,也就是均交并比(mean IoU)

实现代码也很简单:intersection = np.logical_and(target, prediction) union = np.logical_or(target, prediction) iou_score = np.sum(intersection) / np.sum(union)
更具体的一些的如下所示:

import torch 
import pandas as pd  # For filelist reading
from torch.utils.data import Dataset
import myPytorchDatasetClass  # Custom dataset class, inherited from torch.utils.data.dataset


def iou(pred, target, n_classes = 37):
#n_classes :the number of classes in your dataset
  ious = []
  pred = pred.view(-1)
  target = target.view(-1)

  # Ignore IoU for background class ("0")
  for cls in xrange(1, n_classes):  # This goes from 1:n_classes-1 -> class "0" is ignored
    pred_inds = pred == cls
    target_inds = target == cls
    intersection = (pred_inds[target_inds]).long().sum().data.cpu()[0]  # Cast to long to prevent overflows
    union = pred_inds.long().sum().data.cpu()[0] + target_inds.long().sum().data.cpu()[0] - intersection
    if union == 0:
      ious.append(float('nan'))  # If there is no ground truth, do not include in evaluation
    else:
      ious.append(float(intersection) / float(max(union, 1)))
  return np.array(ious)


def evaluate_performance(net):
    Dataloader for test data
    batch_size = 1  
    filelist_name_test = '/path/to/my/test/filelist.txt'
    data_root_test = '/path/to/my/data/'
    dset_test = myPytorchDatasetClass.CustomDataset(filelist_name_test, data_root_test)
    test_loader = torch.utils.data.DataLoader(dataset=dset_test,  
                                              batch_size=batch_size,
                                              shuffle=False,
                                              pin_memory=True)

    data_info = pd.read_csv(filelist_name_test, header=None)
    num_test_files = data_info.shape[0]  #reture data.info's hangshu that means dots in dataset 
    sample_size = num_test_files


    # Containers for results
    preds = torch.FloatTensor(sample_size, opt.imageSizeH, opt.imageSizeW)
    preds = Variable(seg,volatile=True)
    gts = torch.FloatTensor(sample_size, 1, opt.imageSizeH, opt.imageSizeW)
    gts = Variable(gts,volatile=True)

    dataiter = iter(test_loader) 
    for i in xrange(sample_size):
        images, labels, filename = dataiter.next()
        images = Variable(images).cuda()
        labels = Variable(labels)
        gts[i:i+batch_size, :, :, :] = labels
        outputs = net(images)
        outputs = outputs.permute(0, 2, 3, 4, 1).contiguous()
        val, pred = torch.max(outputs, 4)
        preds[i:i+batch_size, :, :, :] = pred.cpu()
    acc = iou(preds, gts)
    return acc

pixcal-accuracy (PA,像素精度)

基于像素的精度计算是评估指标中最为基本也最为简单的指标,从字面上理解就可以知道,PA是指预测正确的像素占总像素的比例,计算公式就不赘述了,大家都懂的。

本次主要想写的是IoU,在进行复现工作的时候,因为这个评估指标整整折腾了两个星期。以此纪念我辛酸的调bug历史。
另外,在查询相关资料的时候发现了一个好东西:

《A Review on Deep Learning Techniques Applied to Semantic Segmentation》
下载PDF请点击这里

我觉得这个应该作为语义分割的基本知识普及资料之一,这里盗一张图来:
在这里插入图片描述
图片来源

参考资料

A Review on Deep Learning Techniques Applied to Semantic Segmentation
个人主页:https://www.jeremyjordan.me/evaluating-image-segmentation-models/
图片来源:https://blog.csdn.net/majinlei121/article/details/78965435

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/171649.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 什么软件自动刷点击量(不同的IP在刷网站)

    网络爬虫是目前各大企业获取数据的主要方式,很多人都知道爬虫使用代理IP,但对其中的原因却知之甚少。那为什么代理IP能帮助网络爬虫呢?1、已解决IP限制。目前大部分网站都有反爬虫技术,最常见的限制是IP接入。假如本站点的IP被封掉,可以用代理IP换IP后继续爬虫。2、提高爬虫的效率。如今有了工作效率的要求,不仅是使用单一的爬虫,为了提高爬虫的效率,可以使用多个爬虫来爬虫,这需要更多的IP,同时也需要IP的更换,自然离不开代理IP。以上介绍代理IP对网络爬虫的帮助关键,大家都有了认识,找代理IP时要找高.

    2022年4月13日
    170
  • 中标麒麟/NeoKylin U盘安装系统「建议收藏」

    中标麒麟/NeoKylin U盘安装系统「建议收藏」这里以NeoKylin6为例,其他版本与此相类似大同小异。但是下载指定版本的镜像时要注意配合该版本的软件包是否充足,不然就会遇到安装好系统很多软件无法安装或更新的情况。1.官方下载地址:http://download.cs2c.com.cn/neokylin/desktop/releases/2.第二步,在上个地址中找你想要下载的版本,注意前面说的先检查下资源,以我想下载的版本6.0为…

    2022年8月10日
    17
  • java键盘钩子_HOOK使用:全局键盘钩子

    java键盘钩子_HOOK使用:全局键盘钩子//CatchKey.cpp:DefinestheentrypointfortheDLLapplication.//#define_WIN32_WINNT0x0500//设置系统版本,可以使用底层键盘钩子#defineWM_MY_SHORTS(WM_USER+105)#include”windows.h”//全局变量LPWORDg_lpdwVir…

    2022年6月9日
    33
  • Ubuntu18.04搭建源码搜索引擎Opengrok

    Ubuntu18.04搭建源码搜索引擎OpengrokTableofContents1OpenGrok介绍2安装OpenGrok2.1安装JAVA运行环境2.2安装Web服务器-Tomcat2.3安装OpenGrok2.4配置OpenGrok2.5安装 universal-ctags2.6建立源码索引2.6更新源码索引1OpenGrok介绍OpenGrok isafastand…

    2022年4月29日
    79
  • Apache OFbiz entity engine源代码解读

    Apache OFbiz entity engine源代码解读

    2021年12月5日
    88
  • vue开发环境搭建及配置[通俗易懂]

    vue开发环境搭建及配置[通俗易懂]转:https://www.cnblogs.com/harbors/p/12673337.html

    2022年10月19日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号