语义分割常用metric

  1. Pixel acc:比较预测label和实际label像素间误差。对于位置的偏移十分敏感,小的偏移都会产生大量的像素误差。
  2. IOU: 交并比,DetectionResult与Ground Truth的交集比上它们的并集。只是从单个像素点本身去考虑该点的预测是否与label重合,而没有从全局去考虑预测的整体形状是否与label结果形状吻合。

混淆矩阵(Confusion Matrix)
在这里插入图片描述

  • 分别统计分类模型中归错,归对类的观测值的个数,然后把结果放在一个表里展示出来。
  • 矩阵对角线上的数字,为当前类别预测正确的类别数目;非对角线数字,预测都是错误的!
  • 矩阵每一行数字求和的值,其含义:真实值中,真实情况下属于该行对应类别的数目!
  • 矩阵每一列数字求和的值,其含义:预测值中,预测为该列对应类别的数目!
  • PA:Accuracy = (TP + TN) / (TP + TN + FP + FN)
  • CPA:Precision = TP / (TP + FP) 或 TN / (TN + FN)
  • Recall = TP / (TP + FN) 或 TN / (TN + FP)

语义分割评价指标

  • PA:像素准确率,预测类别正确的像素数占总像素数的比例
  • CPA:类别像素准确率,模型对类别 i 的预测值有很多,其中有对有错,预测对的值占预测总值的比例
  • MPA:类别平均像素准确率,分别计算每个类被正确分类像素数的比例CPA,然后累加求平均
  • IoU:交并比,模型对某一类别预测结果和真实值的交集与并集的比值
  • MIoU:平均交并比,模型对每一类预测的结果和真实值的交集与并集的比值,求和再平均的结果

A代表真实值(ground truth),B代表预测样本(prediction),预测值和真实值的关系如下:
在这里插入图片描述

  • TP(True Positive):
    橙色,TP = A ∩ B
    预测正确,真正例,模型预测为正例,实际是正例(模型预测为类别1,实际是类别1)
  • FP(False Positive):
    黄色,FP = B - (A ∩ B)
    预测错误,假正例,模型预测为正例,实际是反例 (模型预测为类别1,实际是类别2)
  • FN(False Negative):
    红色,FN = A - (A ∩ B)
    预测错误,假反例,模型预测为反例,实际是正例 (模型预测为类别2,实际是类别1)
  • TN(True Negative):
    白色,TN = ~(A ∪ B)
    预测正确,真反例,模型预测为反例,实际是反例 (模型预测为类别2,实际是类别2)

I o U 正 例 p IoU_{正例p} IoUp = TP / (TP + FN + FP)
MIoU = ( I o U 正 例 p IoU_{正例p} IoUp + I o U 反 例 n IoU_{反例n} IoUn) / 2 = [ TP / (TP + FP + FN) + TN / (TN + FN + FP) ] / 2

"""
常用的为acc和miou
"""
def acc(y_true, y_pred, num_class):
    mask = (y_true >= 0) & (y_true < num_class)
    matrix = np.bincount(num_class * y_true[mask] + y_pred[mask], num_class**2).reshape(num_class, num_class)
    acc_ = np.diag(matrix).sum() / matrix.sum()
    return acc_


def class_acc(y_true, y_pred, num_class):
    mask = (y_true >= 0) & (y_true < num_class)
    matrix = np.bincount(num_class * y_true[mask] + y_pred[mask], num_class**2).reshape(num_class, num_class)
    classAcc = np.diag(matrix) / matrix.sum(axis=1)
    return np.nanmean(classAcc)


def mIoU(y_true, y_pred, num_class):
    mask = (y_true >= 0) & (y_true < num_class)
    matrix = np.bincount(num_class * y_true[mask] + y_pred[mask], num_class**2).reshape(num_class, num_class)
    intersection = np.diag(matrix)
    union = np.sum(matrix, axis=1) + np.sum(matrix, axis=0) - np.diag(matrix)
    IoU = intersection / union
    m_IoU = np.nanmean(IoU)
    return m_IoU
筛选语义分割数据集标签的代码实现可以参考以下步骤: 1. 定义标签质量评估函数,计算标签的精度、召回率、F1-score等指标,以评估标签的质量。 2. 定义标签一致性评估函数,比较不同标注者之间的标签一致性,以评估标签的一致性。 3. 定义标签覆盖率评估函数,计算标签覆盖率,以评估标签的覆盖率。 4. 定义标签类别评估函数,比较标签中的类别和需要的类别,以评估标签的类别。 5. 根据以上评估结果,筛选标签质量较好、一致性较高、覆盖率较全、类别较准确的语义分割数据集标签。 下面是一份示例代码,其中假设已经有了数据集的图像和标签,需要对标签进行筛选: ```python import numpy as np # 定义标签质量评估函数 def compute_metrics(pred, label): # 计算精度、召回率和F1-score TP = np.sum(np.logical_and(pred == 1, label == 1)) FP = np.sum(np.logical_and(pred == 1, label == 0)) FN = np.sum(np.logical_and(pred == 0, label == 1)) TN = np.sum(np.logical_and(pred == 0, label == 0)) precision = TP / (TP + FP) recall = TP / (TP + FN) f1_score = 2 * precision * recall / (precision + recall) return precision, recall, f1_score # 定义标签一致性评估函数 def compute_consistency(label1, label2): # 比较两个标签的一致性 consistency = np.sum(label1 == label2) / label1.size return consistency # 定义标签覆盖率评估函数 def compute_coverage(label): # 计算标签覆盖率 coverage = np.sum(label == 1) / label.size return coverage # 定义标签类别评估函数 def compute_category(label, categories): # 比较标签中的类别和需要的类别 category = np.isin(label, categories) return category # 筛选语义分割数据集标签 def filter_labels(images, labels, categories): num = len(labels) metrics = np.zeros((num, 3)) consistency = np.zeros((num, num)) coverage = np.zeros(num) category = np.zeros(num, dtype=bool) for i in range(num): metric = compute_metrics(labels[i], categories) metrics[i] = metric for j in range(i+1, num): cons = compute_consistency(labels[i], labels[j]) consistency[i,j] = cons consistency[j,i] = cons cov = compute_coverage(labels[i]) coverage[i] = cov cat = compute_category(labels[i], categories) category[i] = cat # 筛选标签 idx = (metrics[:,2] > 0.8) & (consistency.mean(axis=0) > 0.8) & (coverage > 0.9) & category images_filtered = images[idx] labels_filtered = labels[idx] return images_filtered, labels_filtered ``` 以上代码中,`images`是数据集的图像,`labels`是数据集的标签,`categories`是需要的类别。`filter_labels`函数根据标签质量、一致性、覆盖率和类别等评估结果筛选标签,并返回筛选后的图像和标签。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值