[PaddleSeg 源码阅读] PaddleSeg计算Dice

D i c e Dice Dice 系数是一种集合相似度量函数,通常用于计算两个集合的相似度,取值范围是 [ 0 , 1 ] [0, 1] [0,1]:

D i c e ( X , Y ) = 2 ∣ X ∩ Y ∣ ∣ X ∣ + ∣ Y ∣ Dice(X, Y) = \frac {2 | X\cap Y|} { |X| + |Y| } Dice(X,Y)=X+Y2XY

∣ . ∣ |.| . 表示取集合元素的数量函数

D i c e ( X , Y ) = 两 者 交 集 元 素 的 个 数 × 2 两 者 元 素 数 量 之 和 Dice(X, Y) = \frac {两者交集元素的个数 \times 2} {两者元素数量之和} Dice(X,Y)=×2

PaddleSeg 中的实现:

def dice(intersect_area, pred_area, label_area):
    """
    Calculate DICE.
    计算 DICE 值.

    Args:
        intersect_area (Tensor): The intersection area of prediction and ground truth on all classes.
        pred_area (Tensor): The prediction area on all classes.
        label_area (Tensor): The ground truth area on all classes.

    Returns:
        np.ndarray: DICE on all classes.
        float: mean DICE of all classes.
    """
    # 将三者转化为 np.adarray
    intersect_area = intersect_area.numpy()
    pred_area = pred_area.numpy()
    label_area = label_area.numpy()
    
    # 两个集合元素的数量
    union = pred_area + label_area
    class_dice = []
    for i in range(len(intersect_area)): # 在每一类中开始迭代
        if union[i] == 0:
        	# 如果分子为 0,也就是当前图片没有该类元素
            dice = 0
        else:
            dice = (2 * intersect_area[i]) / union[i]
        class_dice.append(dice)
        
    mdice = np.mean(class_dice)
    return np.array(class_dice), mdice

intersect_area, pred_area, label_area 这三个参数是通过:

calculate_area(pred, label, num_classes, ignore_index=255)

来计算的,接上一篇博客:
[PaddleSeg 源码阅读] PaddleSeg计算 mIoU

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值