loss = p*self.weights
loss =-K.sum(loss,-1)
// return loss
return K.mean(loss)
// def nonzero_acc(y_true, y_pred):
// lab_true = K.argmax(y_true, axis=-1)
// lab_pred = K.argmax(y_pred, axis=-1)
After Change
def loss(self, y_true, y_pred):
""" 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)