1.Dice loss
Dice系数是一种集合相似度度量函数,通常用于计算两个样本的相似度
Dice损失和Dice系数的关系是:DiceLoss = 1 - DiceCoefficient
代码实现:
def dice_coef(y_true, y_pred, axis = (1,2), smooth = 1e-5):
l = tf.reduce_sum(y_true, axis=axis)
r = tf.reduce_sum(y_pred, axis=axis)
intersection = tf.reduce_sum(y_true * y_pred, axis=axis)
dice = (2. * intersection + smooth) / (l + r + smooth)
dice = tf.reduce_mean(dice)
return dice
def dice_coef_loss(y_true, y_pred):
return 1-dice_coef(y_true, y_pred)
加上的smooth参数是为了防止分母为0