Guest User

Untitled

a guest
Dec 13th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. Dice = (2*|X & Y|)/ (|X|+ |Y|) = 2*sum(|A*B|)/(sum(A^2)+sum(B^2))
  2.  
  3. def dice_coef(y_true, y_pred):
  4. y_true_f = K.flatten(y_true)
  5. y_pred_f = K.flatten(y_pred)
  6. intersection = K.sum(y_true_f * y_pred_f)
  7. dice_coef = (2. * intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)
  8. return 1.0-dice_coef
  9.  
  10. Jaccard = (|X & Y|)/ (|X|+ |Y| - |X & Y|) = sum(|A*B|)/(sum(|A|)+sum(|B|)-sum(|A*B|))
  11.  
  12. def jaccard_loss(y_true, y_pred):
  13. intersection = K.sum(K.abs(y_true * y_pred), axis=-1)
  14. sum_ = K.sum(K.abs(y_true) + K.abs(y_pred), axis=-1)
  15. jac = (intersection + smooth) / (sum_ - intersection + smooth)
  16. return (1 - jac) * smooth
Add Comment
Please, Sign In to add comment