Skip to content

Instantly share code, notes, and snippets.

@greed2411
Created October 4, 2018 10:24
Show Gist options
  • Save greed2411/5bebd92e2973f80f1986991f60edd28a to your computer and use it in GitHub Desktop.
Save greed2411/5bebd92e2973f80f1986991f60edd28a to your computer and use it in GitHub Desktop.
dice coefficient
def dice_loss(input, target):
smooth = 1.
iflat = input.view(-1)
tflat = target.view(-1)
intersection = (iflat * tflat).sum()
return 1 - ((2. * intersection + smooth) /
(iflat.sum() + tflat.sum() + smooth))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment