Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dice = (2*|X & Y|)/ (|X|+ |Y|) = 2*sum(|A*B|)/(sum(A^2)+sum(B^2))
- def dice_coef(y_true, y_pred):
- y_true_f = K.flatten(y_true)
- y_pred_f = K.flatten(y_pred)
- intersection = K.sum(y_true_f * y_pred_f)
- dice_coef = (2. * intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)
- return 1.0-dice_coef
- Jaccard = (|X & Y|)/ (|X|+ |Y| - |X & Y|) = sum(|A*B|)/(sum(|A|)+sum(|B|)-sum(|A*B|))
- def jaccard_loss(y_true, y_pred):
- intersection = K.sum(K.abs(y_true * y_pred), axis=-1)
- sum_ = K.sum(K.abs(y_true) + K.abs(y_pred), axis=-1)
- jac = (intersection + smooth) / (sum_ - intersection + smooth)
- return (1 - jac) * smooth
Add Comment
Please, Sign In to add comment