Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple metrics to specific inputs

I have multiple losses and metrics whether custom or imported from keras. Is there a way to specify which model outputs could be inputted to which metric instead of all of them being printed or calculated?

like image 961
MasterWizard Avatar asked Sep 02 '26 03:09

MasterWizard


1 Answers

Yes, you can pass the losses/metrics as a dictionary that maps layer name to a loss/metrics.

A quote from the documentation:

loss: ... If the model has multiple outputs, you can use a different loss on each output by passing a dictionary or a list of losses. The loss value that will be minimized by the model will then be the sum of all individual losses.

and

metrics: ... To specify different metrics for different outputs of a multi-output model, you could also pass a dictionary, such as metrics={'output_a': 'accuracy'}.

Example:

model.compile(
   optimizer='rmsprop',
   loss={'output_1': 'loss_1', 'output_2': 'loss_2'},
   loss_weights={'output_1': 1., 'output_2': 0.2},
   metrics={'output_1': 'metric_1', 'output_2': ['metric_2', 'metric_3']})

You can read more about multi-output model with Keras in: https://keras.io/getting-started/functional-api-guide/#multi-input-and-multi-output-models

like image 166
Mark Loyman Avatar answered Sep 04 '26 19:09

Mark Loyman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!