【发布时间】:2019-01-29 03:04:33
【问题描述】:
我正在 keras 中训练 U-Net,方法是最小化通常用于此问题的 dice_loss 函数:adapted from here 和 here
def dsc(y_true, y_pred):
smooth = 1.
y_true_f = K.flatten(y_true)
y_pred_f = K.flatten(y_pred)
intersection = K.sum(y_true_f * y_pred_f)
score = (2. * intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)
return score
def dice_loss(y_true, y_pred):
return (1 - dsc(y_true, y_pred))
此实现与traditional dice loss 不同,因为它有一个平滑项以使其“可微”。我只是不明白如何在分母中添加smooth 术语而不是1e-7 之类的东西会使其变得更好,因为它实际上会改变损失值。我已经通过在具有常规dice 实现的测试集上使用训练有素的 unet 模型来检查这一点,如下所示:
def dice(im1,im2):
im1 = np.asarray(im1).astype(np.bool)
im2 = np.asarray(im2).astype(np.bool)
intersection = np.logical_and(im1, im2)
return np.float(2. * intersection.sum()) / (im1.sum() + im2.sum() + 1e-7))
有人可以解释为什么通常使用平滑骰子损失吗?
【问题讨论】:
-
你为什么认为
smooth这个术语使得损失函数可微分? -
很确定我在某处读过它,但我可能混淆了这些概念。
-
在'smooth dice'中和'soft dice'一样吗?
-
@MonicaHeddneck 我相信是的!
标签: tensorflow image-processing keras image-segmentation semantic-segmentation