Skip to content

Instantly share code, notes, and snippets.

@Tony607
Created November 2, 2019 11:24
Show Gist options
  • Save Tony607/892807aab7152b7bcafc9bb9c94045fb to your computer and use it in GitHub Desktop.
Save Tony607/892807aab7152b7bcafc9bb9c94045fb to your computer and use it in GitHub Desktop.
Automatic Defect Inspection with End-to-End Deep Learning | DLology
from tensorflow.keras import backend as K
def smooth_dice_coeff(smooth=1.):
smooth = float(smooth)
# IOU or dice coeff calculation
def IOU_calc(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)
return 2*(intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)
def IOU_calc_loss(y_true, y_pred):
return -IOU_calc(y_true, y_pred)
return IOU_calc, IOU_calc_loss
IOU_calc, IOU_calc_loss = smooth_dice_coeff(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment