Custom loss in Keras

What is the best way of creating custom loss in Keras? How is gradient going to be computed or do I have to provide the gradients also?

keraslosscustom-loss
2 votesJW234.00
1 Answers
JO220.00
1

No, You just need to define your loss function in keras environment, like you have to use their functions to be able to train. Here is just a simple example

import keras

def my_loss(y_true, y_pred):
    # any actions you need to do with the arguments
    result = ...
    # you will have to use backend's functions of keras
    return result

model.compile(loss=my_loss, ...)
Reply
Couldn't find what you were looking for?and we will find an expert to answer.
How helpful was this page?