I am training a U-Net in keras by minimizing the dice_loss
function that is popularly used for this problem: adapted from here and here
def dsc(
Adding smooth
to the loss does not make it differentiable. What makes it differentiable is
1. Relaxing the threshold on the prediction: You do not cast y_pred
to np.bool
, but leave it as a continuous value between 0 and 1
2. You do not use set operations as np.logical_and
, but rather use element-wise product to approximate the non-differenetiable intersection operation.
You only add smooth
to avoid devision by zero when both y_pred
and y_true
do not contain any foreground pixels.