MIoU

M I o U MIoU MIoU

MIoU(Mean Intersection over Union):平均交并比

这是一个标准的衡量metric ,计算两个集合之间交集和并集的比例,在图像分割中,就是真实值(Ground Truth)和预测值两个集合。可以转换为TP(intersection)与TP ,FN ,FP之和(union)的比值。先计算每个类内的交并比,然后计算均值。

实现

gt_image = np.array([
    [0,1,2,4],
    [0,0,0,0],
    [0,0,0,0],
    [0,0,0,0]
])

pre_image = np.array([
    [0,1,2,4],
    [0,1,0,0],
    [0,1,0,0],
    [0,0,1,0]
])

def generate_matrix(gt_image, pre_image,num_class=8):
        mask = (gt_image >= 0) & (gt_image < num_class)#ground truth中所有正确(值在[0, classe_num])的像素label的mask
        
        label = num_class * gt_image[mask].astype('int') + pre_image[mask] 
        # np.bincount计算了从0到n**2-1这n**2个数中每个数出现的次数,返回值形状(n, n)
        count = np.bincount(label, minlength=num_class**2)
        confusion_matrix = count.reshape(num_class, num_class)#21 * 21(for pascal)
        return confusion_matrix
        
matrix =generate_matrix(gt_image,pre_image)
def Mean_Intersection_over_Union(confusion_matrix):
    MIoU = np.diag(confusion_matrix) / (
                np.sum(confusion_matrix, axis=1) + np.sum(confusion_matrix, axis=0) -
                np.diag(confusion_matrix))
    MIoU = np.nanmean(MIoU) #跳过0值求mean,shape:[21]
    return MIoU
 
Mean_Intersection_over_Union(matrix)

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值