Skip to content

Instantly share code, notes, and snippets.

@harshnandwana
Created July 2, 2022 19:50
Show Gist options
  • Save harshnandwana/85fc8c19633b40921d8c9e873082ce7d to your computer and use it in GitHub Desktop.
Save harshnandwana/85fc8c19633b40921d8c9e873082ce7d to your computer and use it in GitHub Desktop.
import tensorflow.keras.backend as K
def dice_coef(y_true, y_pred):
y_truef=K.flatten(y_true)
y_predf=K.flatten(y_pred)
And=K.sum(y_truef* y_predf)
return((2* And + 100) / (K.sum(y_truef) + K.sum(y_predf) + 100))
def dice_coef_loss(y_true, y_pred):
return 1-dice_coef(y_true, y_pred)
def iou(y_true, y_pred):
intersection = K.sum(y_true * y_pred)
sum_ = K.sum(y_true + y_pred)
jac = (intersection + 100) / (sum_ - intersection + 100)
return jac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment