// scale preds so that the class probas of each sample sum to 1
y_pred /= K.sum(y_pred, axis=-1, keepdims=True)
// clip
y_pred = K.clip(y_pred, K.epsilon(), 1)
// calc
p = y_true*K.log(y_pred)
loss = p*self.weights
loss =-K.sum(loss,-1)
After Change
""" prepare a loss of the given metric/loss operating on non-bg data """
yt = y_true.eval()
ytbg = np.where(yt == 0)
y_true_fix = K.variable(yt.flat(ytbg))
y_pred_fix = K.variable(y_pred.eval().flat(ytbg))
return self.metric(y_true_fix, y_pred_fix)