'DICE Loss Function becomes unlearnable
I am doing a binary segmentation problem where I use the custom DICE Loss function designed as below.
import keras
import keras.backend as K
def DiceLoss(targets, inputs, smooth=1e-6):
inputs = K.flatten(inputs)
targets = K.flatten(targets)
intersection = K.sum(targets*inputs)
dice = (2.*intersection + smooth) / (K.sum(targets) + K.sum(inputs) + smooth)
return 1 - dice
Here the U-net learns when the loss has (2.*intersection + smooth) in the numerator but it doesn't learn when (2*intersection + smooth) is the numerator. The fact that 2 is a float or a int decides the learnability of the loss function. The loss cannot turn into integer value due to the 2 being int or float, since the tensors used in the calculation and K.sum also returns float values. So I am pretty perplexed why the change of 2 to 2. makes things right. Is there any relation with the computational graph built for back-propagation with this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
