【问题标题】:Keras: Dice coefficient loss function is negative and increasing with epochsKeras:骰子系数损失函数为负并随时期增加
【发布时间】:2018-09-21 22:23:06
【问题描述】:

根据 Dice Co-eff 损失函数的 Keras 实现,损失是骰子系数计算值的负数。损失应该随着时代而减少,但是通过这种实现,我自然会得到负损失,损失随着时代而减少,即从 0 向负无穷大方向移动,而不是接近 0。如果我使用(1-dice co-eff) 而不是 (-dice co-eff) 作为损失,会不会错? 这是完整的 Keras 实现(我正在谈论):https://github.com/jocicmarko/ultrasound-nerve-segmentation/blob/master/train.py

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)


def dice_coef_loss(y_true, y_pred):
return -dice_coef(y_true, y_pred)

我已经和你分享了我的实验日志,虽然只有 2 个 epoch:

Train on 2001 samples, validate on 501 samples
Epoch 1/2
Epoch 00001: loss improved from inf to -0.73789, saving model to unet.hdf5
 - 3229s - loss: -7.3789e-01 - dice_coef: 0.7379 - val_loss: -7.9304e-01 - val_dice_coef: 0.7930
Epoch 2/2
Epoch 00002: loss improved from -0.73789 to -0.81037, saving model to unet.hdf5
 - 3077s - loss: -8.1037e-01 - dice_coef: 0.8104 - val_loss: -8.2842e-01 - val_dice_coef: 0.8284
predict test data
9/9 [==============================] - 4s 429ms/step
dict_keys(['val_dice_coef', 'loss', 'val_loss', 'dice_coef'])

【问题讨论】:

    标签: python machine-learning deep-learning keras loss-function


    【解决方案1】:

    1-dice_coef-dice_coef 对于收敛应该没有区别,但是 1-dice_coef 提供了一种更熟悉的监控方式,因为值在 [0, 1] 范围内,而不是 [-1, 0] 范围内。

    【讨论】:

      【解决方案2】:

      我认为正确的损失是 1 - dice_coef(y_true, y_pred)

      【讨论】:

        猜你喜欢
        • 2021-12-13
        • 2021-03-15
        • 2022-07-25
        • 2020-09-27
        • 1970-01-01
        • 2018-05-08
        • 1970-01-01
        • 2019-11-04
        • 2018-10-10
        相关资源
        最近更新 更多