Search code examples
tensorflowneural-networkloss-function

Writing custom loss in tensorflow that does not use Y_pred and Y_actual


My loss function for a DNN classification task is eigenvalue-based which does not need the inputs Y_prediction and Y_actual. Is it possible to write specialized custom loss functions like that using Tensorflow?


Solution

  • Of course:

    def customLoss(y_true, y_pred, alpha):
                   loss = ....alpha
                    return loss
    model.compile(loss=customLoss(alpha), optimizer='sgd')