一、语义图像分割结果定义
语义图像分割结果,可分为True Positive、False Positive、True Negative、False Negative。
Negative指非物体标签的部分(可直接理解为背景),Positive指有标签的部分。

左上图为真实标注,右上图为预测结果。从右上图可以将预测结果分成对应的四个部分:
- True Negative:白色斜线标记部分(TN,背景被预测为背景)
- False Negative:红色斜线标记部分(FN,标签被预测为背景)
- True Positive:中间荧光黄色部分(TP,标签被预测为标签)
- False Positive:蓝色斜线标记部分(FP,背景被预测为标签)
二、语义图像分割结果评价指标之IoU
IoU(Intersection over Union)是一个评价目标检测、语义图像分割的不同方法的结果好坏的指标,用于比较模型结果(predicted output)与真实标注(ground truth)的相似程度。

IoU指标可以适用于Single-class的语义图像分割,但不适用于Multiple-class的语义图像分割。
三、语义图像分割常用结果评价指标
以下是几种逐像素标记的精度标准。假设有k+1个类(其中包含一个空类或背景),i表示真实值,j表示预测值 ,pij表示将类i预测为类j的像素数量。即,pii表示TP,pij表示FN,pji表示FP,pjj表示FN。


四、MIoU的计算
两个矩阵,一个代表实际的分割,另一个代表任何神经网络或模型的预测分割

这些矩阵的元素是表示图像上特定位置的像素所属的不同类别的标签。这里,共有 6 个类,标签为“0”、“1”、“2”、“3”、“4”和“5”,矩阵是 2D numpy 类型,每个大小为 (4 x 4)。
通过以下步骤,计算 MIoU:
步骤 1:找出两个矩阵的每个类的频率计数(numpy 包中的“bincount”函数)


步骤 2:将矩阵转换为一维格式

步骤 3:找出类别矩阵
由于这里有 6 个类,因此可以有 6 x 6 = 36 种可能性。
第 6 个像素实际上属于“1”类,但预计会出现在“0”类中,因此属于“1-0”类。每一种这样的可能性都对应一个类别。可能的类别可能是“0-0”、“0-1”、“0-2”、……、“4-5”、“5-5”。它们按索引编号,类别“0-0”的编号为 0,类别“0-1”的编号为 1,依此类推。

类别矩阵是"i-j"类别编号的矩阵,根据category就可以得出步骤4中CM_1D,CM_1D中index=0的地方值为5,即category中为0的有5个,也就是5个像素点是“0-0”。
category =(类数 x actual_1D)+ pred_1D
步骤 4:构建混淆矩阵
混淆矩阵是一个(类别数 x 类别数)大小的矩阵,它存储有关属于特定类别的像素数量的信息。

步骤 5:计算各个类的 IoU
I = 混淆矩阵 ( CM_2D )的对角元素
U = 步骤1中的actual_count + 步骤1中的pred_count - I

步骤 6:计算实际预测对的 MIoU
使用 numpy 包中提供的 'nanmean' 函数。'nanmean' 比普通均值更可取,以忽略由于图像中没有任何特定类而导致单个 IoU 值可能变为 'nan' 的情况。
MIoU = 0.8
网友评论