Skip to content

Instantly share code, notes, and snippets.

@karolzak
Last active January 16, 2019 22:28
Show Gist options
  • Save karolzak/698c5890fdfd8f46be47cf4a5bcdc9f6 to your computer and use it in GitHub Desktop.
Save karolzak/698c5890fdfd8f46be47cf4a5bcdc9f6 to your computer and use it in GitHub Desktop.
simple iou metric with 0.5 rounding (treshold)
################### metrics ############################
from keras import backend as K
SMOOTH = 1e-12
def iou(true, pred):
y_pred_pos = K.round(K.clip(pred, 0, 1))
intersection = true * y_pred_pos
union = true + y_pred_pos
return K.sum(intersection + SMOOTH) / K.sum(union - intersection + SMOOTH)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment