I am training a Vnet on a segmentation problem with Keras 2.2.4 and Tensorflow 1.12.0 (I cannot change the tensorflow version). The masks, i.e. y_true, are (1,200,150,100,2) arrays. I want to minimize the dice loss defined as:
'''
def dice_loss_foreground(y_true, y_pred):
elements_per_class=tf.math.reduce_sum(y_true[:,:,:,:,1])
predicted_per_class=tf.math.reduce_sum(y_pred[:,:,:,:,1])
intersection=tf.math.scalar_mul(2.0,tf.math.reduce_sum(tf.math.multiply(y_pred[:,:,:,:,1],y_true[:,:,:,:,1])))
union=elements_per_class+predicted_per_class
acc=intersection/(union+0.0001)
return 1.0-acc
'''
I have tested this definition on mock examples and it goes from 0 to 1 but, during training, the loss reaches a number higher than 1. Can anybody help me in understanding why? Thanks!
The loss function is not merely made by the dice definition but it contains the regularization too. So, even if dice coefficient loss should be in range 0-1, it may be greater than 1 depending on regularization.