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.
Recent versions of Keras actually support losses with different shapes of y_pred
and y_true
. The build in loss sparse_categorical_crossentropy
is an example of this. The TensorFlow implementation of this loss is here: https://github.com/keras-team/keras/blob/0fc33feb5f4efe3bb823c57a8390f52932a966ab/keras/backend/tensorflow_backend.py#L3570
Notice how it says target: An integer tensor.
and not target: A tensor of the same shape as `output`.
like the others. I tried with a custom loss I made myself and it seems to work fine.
I'm using Keras 2.2.4.