Skip to content

Instantly share code, notes, and snippets.

@sohiniroych
Created March 10, 2021 23:31
Show Gist options
  • Select an option

  • Save sohiniroych/68ce46adfae0400acc5fe833d96f6464 to your computer and use it in GitHub Desktop.

Select an option

Save sohiniroych/68ce46adfae0400acc5fe833d96f6464 to your computer and use it in GitHub Desktop.
loss functions for semantic segmentation
def dice_coef(y_true, y_pred, smooth=1):
intersection = keras.sum(y_true * y_pred, axis=[1,2,3])
union = keras.sum(y_true, axis=[1,2,3]) + keras.sum(y_pred, axis=[1,2,3])
return keras.mean( (2. * intersection + smooth) / (union + smooth), axis=0)
def dice_coef_loss(y_true, y_pred):
return -dice_coef(y_true, y_pred)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment