dice_loss_for_keras · GitHub
gist.github.com › wassname › 7793e2058c5c9dacb5212c0Here is a dice loss for keras which is smoothed to approximate a linear (L1) loss. It ranges from 1 to 0 (no error), and returns results similar to binary crossentropy """ # define custom loss and metric functions : from keras import backend as K: def dice_coef (y_true, y_pred, smooth = 1): """ Dice = (2*|X & Y|)/ (|X|+ |Y|) = 2*sum(|A*B|)/(sum(A^2)+sum(B^2))
DiceLoss-PyTorch/loss.py at master · hubutui ... - GitHub
github.com › DiceLoss-PyTorch › blobloss = 1-num / den: if self. reduction == 'mean': return loss. mean elif self. reduction == 'sum': return loss. sum elif self. reduction == 'none': return loss: else: raise Exception ('Unexpected reduction {}'. format (self. reduction)) class DiceLoss (nn. Module): """Dice loss, need one hot encode input: Args: weight: An array of shape [num_classes,] ignore_index: class index to ignore