Skip to content

mIoU metric #28

@TiY68

Description

@TiY68

您好,非常感谢您的这份开源工作,有一个关于本文使用的mIoU metric的问题想要请教一下。

语义分割中常用的两个评估指标oIoU(Overall Intersection over Union)和 mIoU(Mean Intersection over Union)的计算公式分别为:

$$\text{oIoU} = \frac{\sum_{class} \text{Intersection}_{class}}{\sum_{class} \text{Union}_{ class}}$$ $$\text{mIoU} = \frac{1}{N} \sum_{class} \frac{\text{Intersection}_{class}}{\text{Union}_{class}}$$

本代码在mmseg/evaluation/metrics/iou_metric.py中实际计算的IoU是不是应该是oIoU? 部分关键代码如下:

def compute_metrics(self, results: list) -> Dict[str, float]:
    ......
    total_area_intersect = sum(results[0])     #计算所有类别的交集之和
    total_area_union = sum(results[1])         #计算所有类别的并集之和
    total_area_pred_label = sum(results[2])
    total_area_label = sum(results[3])
    ret_metrics = self.total_area_to_metrics(
        total_area_intersect, total_area_union, total_area_pred_label,
        total_area_label, self.metrics, self.nan_to_num, self.beta)

@staticmethod
def total_area_to_metrics(total_area_intersect: np.ndarray,
                          total_area_union: np.ndarray,
                          total_area_pred_label: np.ndarray,
                          total_area_label: np.ndarray,
                          metrics: List[str] = ['mIoU'],
                          nan_to_num: Optional[int] = None,
                          beta: int = 1):
    .......
    for metric in metrics:
        if metric == 'mIoU':
            iou = total_area_intersect / total_area_union    #所有类别总交集/所有类别总并集
            acc = total_area_intersect / total_area_label
            ret_metrics['IoU'] = iou
            ret_metrics['Acc'] = acc

期待您的回复,谢谢!祝您科研顺利!!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions