I want to make a custom MSE loss function that uses only one item from the output layer.
What I have now is this:
def new_loss(y_true, y_pred):
index_pred = K.argmax(K.abs(y_pred), axis = -1)
pred = tf.gather(y_true, index_pred, axis = 1)
index_true = K.argmin(K.abs(y_true), axis = -1)
true = tf.gather(y_true, index_true, axis = 1)
return K.mean(K.sqrt(K.square(K.log(pred)-K.log(true))))
But it gives the error,
An operation has `None` for gradient.
I have been looking and can't find anything to work in my scenario.
I am working with Keras and Tensorflow as back-end.
Thank you in advance.
EDIT:
I tried
def new_loss(y_true, y_pred):
index_pred = K.argmax(K.abs(y_pred), axis = -1)
pred = tf.gather(y_pred, index_pred, axis = 1)
index_true = K.argmin(K.abs(y_true), axis = -1)
true = tf.gather(y_true, index_true, axis = 1)
return K.mean(K.sqrt(K.square(K.log(pred)-K.log(true))))
And it doesn't give the error. So it is not K.argmax/K.argmin that is the problem.