Getting keras compiled model loss function

Viewed 501

Is there any way to get the compiled model loss/metrics functions from the model object?

I need this to access the loss function from within a callback, where I have access to self.model, but I can't find a way to access the compiled loss.

2 Answers

In tensorflow 2.4, model.compiled_loss._losses returns the name of the loss function.

If you want to view the loss function use model.loss

Using model.compiled_loss._losses will return a LossFunctionWrapper object which you can call, but cannot get any other information on.

Related