'Calculating metrics (e.g. SSIM) for multi-input multi-output Keras model

I have a Keras model having 3 inputs and 2 outputs as follows

     _________  
a --|         |--- x
b --|  Model  |--- y
c --|_________|

Is there a way to compile the model and calculate metrics as structural similarity (SSIM) between specific input and output (e.g. input 'a' and output 'x)'?

model = keras.Model([a, b, c], [x, y])
model.compile(optimizer='adam' 
                , loss = 'mse'
                , metrics=[ssim, None])


Solution 1:[1]

When working with multi-output models, you can pass a dict to the metrics arg of compile. Where, you dict should have output names as keys, and the required metrics as values.

From TensorFlow Documentation

...To specify different metrics for different outputs of a multi-output model, you could also pass a dictionary, such as metrics={'output_a': 'accuracy', 'output_b': ['accuracy', 'mse']}. You can also pass a list to specify a metric or a list of metrics for each output, such as metrics=[['accuracy'], ['accuracy', 'mse']] or metrics=['accuracy', ['accuracy', 'mse']] ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Srihari Humbarwadi