def batch_loss_perim(y_batch, p_batch): print 'blp' m = float(y_batch.shape[0]) bce_loss = sum(bce(y, p) for (y, p) in zip(y_batch, p_batch)) / m perim_loss = sum( perimeter(np.round(p)) / np.count_nonzero(np.round(p)) for p in p_batch) / m return bce_loss + perim_loss
def dice_bce_coeff(y_true, y_pred): # Compute Dice loss y_pred = K.clip(y_pred, K.epsilon(), 1 - K.epsilon()) y_true_f = K.flatten(y_true) y_pred_f = K.flatten(y_pred) intersection_fg = K.sum(y_true_f * y_pred_f) + K.epsilon() union_fg = K.sum(y_true_f) + K.sum(y_pred_f) coeff = (2 * intersection_fg) / (union_fg + K.epsilon()) dice_loss = 1 - coeff bce_loss = bce(y_true_f, y_pred_f) return dice_loss + bce_loss
def bce_jaccard_loss(y_true, y_pred): return bce(y_true, y_pred) + jacard_coef(y_true, y_pred)
def bce_dice_loss_v2(y_true, y_pred): return bce(y_true, y_pred) + 1 - dice_coef(y_true, y_pred)
def bce_dice_loss(y_true, y_pred): return bce(y_true, y_pred) - K.log(dice_coef(y_true, y_pred))
def bce_nodice(y_true, y_pred): return bce(y_true, y_pred)
def bce_dice(y_true, y_pred): return 0.01 * bce(y_true, y_pred) - K.log(dice_coef(y_true, y_pred))