Created
November 2, 2019 11:24
-
-
Save Tony607/892807aab7152b7bcafc9bb9c94045fb to your computer and use it in GitHub Desktop.
Automatic Defect Inspection with End-to-End Deep Learning | DLology
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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