簡體   English   中英

Keras:骰子系數損失函數為負且隨時間增加

[英]Keras: Dice coefficient loss function is negative and increasing with epochs

根據 Dice Co-eff 損失函數的這個 Keras 實現,損失減去骰子系數的計算值。 損失應該隨着 epochs 減少,但是通過這個實現,我自然而然地總是負損失,並且損失隨着 epochs 減少,即從 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 個時期:

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'])

1-dice_coef-dice_coef對收斂沒有任何影響,但1-dice_coef提供了一種更熟悉的監控方式,因為值在 [0, 1] 范圍內,而不是 [-1, 0]。

我認為正確的損失是 1 - dice_coef(y_true, y_pred)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM