为什么我们在keras模型中使用smooth变量来计算dice_coef或IoU?

Why do we use the smooth variable to calculate dice_coef or IoU in keras model?

我想根据dice_coef计算我的keras模型的损失函数,我在网上找到了这个表达式:

smooth = 1.

def dice_coef(y_true, y_pred):
    y_true_f = K.flatten(y_true)
    y_pred_f = K.flatten(y_pred)
    intersection = K.sum(y_true_f * y_pred_f)
    return (2. * intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)

我不明白为什么我们要在 botn 分子和分母上积分这个平滑变量?

基本上你使用 smooth 来避免除以 0

如果由于某种原因 gtpred 都是 0,您将得到一个 Inf,并且权重传播会破坏训练过程。

请注意,您将它同时添加到分子和分母中,以防止它在任何其他情况下影响系数。