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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With