Implementing custom loss function in keras with different sizes for y_true and y_pred

后端 未结 3 674
执念已碎
执念已碎 2020-12-29 00:19

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.

3条回答
  •  孤城傲影
    2020-12-29 00:52

    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.

提交回复
热议问题