I am new to Keras. I need some help in writing a custom loss function in keras with TensorFlow backend for the following loss equation.
Yu's answer is correct still I want to share my experience. Whenever you want to write custom loss function, beware of certain things:
y_pred which comes from the output layer of your model has 3-D shape, y_true will default to 3-D shape. BUT, at run time i.e. during fit, if you pass target data as 2-D which many people do, you might end up getting the error in your loss function. E.g., if you are calculating sigmoid_crossentropy_with_logits, it will complain. Hence, do pass targets as 3-D via np.expand_dims. y_true and y_pred as arguments (if somebody knows that we can use any other names as arguments, pl shout).