计算多类语义分割的mIoU

问题描述

我想为多类语义分割计算mIoU。我已经用 mIoU 指标训练了 u-net,我想用不同的数据集测试这个模型,但在这个阶段我必须忽略一些像素值,但我不能用我的 mIoU 代码运行它,我发现如下所示。但是我不明白它的输入/输出

对于我给的 preds (1,NumberofClass,w,h) 对于我给的实验室 (1,h) 对于 C,我给出了我的班级编号,并将忽略定义为列表(忽略 = [0])

def IoU(preds,labels,C,EMPTY=1.,ignore=None,per_image=False):
"""
Array of IoU for each (non ignored) class
"""
if not per_image:
    preds,labels = (preds,),(labels,)
IoUs = []
for pred,label in zip(preds,labels):
    IoU = []
    for i in range(C):
        if i != ignore:
            intersection = ((label == i) & (pred == i)).sum()
            union = ((label == i) | ((pred == i) & (label != ignore))).sum()
            if not union:
                IoU.append(EMPTY)
            else:
                IoU.append(float(intersection) / float(union))
    IoUs.append(IoU)
IoUs = [mean(IoU) for IoU in zip(*IoUs)]  # mean across images if per_image
return 100 * np.array(IoUs)



def mean(l,ignore_nan=False,empty=0):
"""
nanmean compatible with generators.
"""
l = iter(l)
if ignore_nan:
    l = ifilterfalse(isnan,l)
try:
    n = 1
    acc = next(l)
except stopiteration:
    if empty == 'raise':
        raise ValueError('Empty mean')
    return empty
for n,v in enumerate(l,2):
    acc += v
if n == 1:
    return acc
return acc / n

当我运行代码时,我的输出就是这样。我也注意到我的交点总是 0。 谁能得到更好的解决方案。这将非常有帮助。

损失 = [100。 0. 0. 100. 0. 0. 0. 0. 0. 100. 0. 0. 100. 0. 0.]

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)