语义分割中的mIoU计算函数解读

本文从新手视角解读CVPR2018文章《Context Encoding for Semantic Segmentation》中的mIoU计算,通过分析histogram函数的详细用法,探讨mIoU在语义分割中的作用。参考了优快云博主的文章来辅助理解,解释了histogram函数的参数如bins、range、normed等,并指出histogram函数返回的hist和bin_edges数组的意义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码来自于CVPR2018的一篇文章Context Encoding for Semantic Segmentation。
github工程地址为:https://github.com/zhanghang1989/PyTorch-Encoding
很棒的工作。
我是新入门,对代码解读如下,有不对的地方请高手们批评指正。
我的标签图像序号是从0开始,依次编号,0代表背景类

def batch_intersection_union(predict, target, nclass):
    """Batch Intersection of Union
    Args:
        predict: input 4D tensor 具体地为B(batch大小)*C(通道)*H*W
        target: label 3D tensor 具体地为B(batch大小)*H*W
        nclass: number of categories (int)
    """
    #在通道维上取最大值,注意predict为第二个返回值,因此是索引,从0开始
    #此时predict和target一样,维度均为B*H*W,且值均为0,1,2.........
    _, predict = torch.max(predict, 1) 
    mini = 1
    maxi = nclass
    nbins = nclass
    #将predict和target放入cpu并转换为numpy数组,同时+1
    #此时predict和target的值为1,2,......
    predict = predict.cpu().numpy() + 1
    target = target.cpu().numpy() + 1

   #假如我除去背景类只有1类目标,则nbins为2。
   #此句似乎没有实际意义?predict值不变,因为target值均大于0
   # (target > 0)返回的均为true
    predict =
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值