Created
November 28, 2017 06:12
-
-
Save dimaxano/0761aef1fefda83776f59845e95d6c7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# metrics | |
def dice_coef(y_true, y_pred): | |
y_true_f = K.flatten(y_true) | |
y_pred = K.cast(y_pred, 'float32') | |
y_pred_f = K.cast(K.greater(K.flatten(y_pred), 0.5), 'float32') | |
intersection = y_true_f * y_pred_f | |
score = 2. * K.sum(intersection) / (K.sum(y_true_f) + K.sum(y_pred_f)) | |
return score | |
#losses | |
def dice_loss(y_true, y_pred): | |
smooth = 1e-15 | |
y_true_f = K.flatten(y_true) | |
y_pred_f = K.flatten(y_pred) | |
intersection = y_true_f * y_pred_f | |
score = (2. * K.sum(intersection) + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth) | |
return 1. - score | |
def bce_logdice_loss(y_true, y_pred): | |
return binary_crossentropy(y_true, y_pred) - K.log(1. - dice_loss(y_true, y_pred)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment