I would like to add a custom metric to model with Keras, I’m debugging my working code and I don’t find a method to do the operations I need. The problem could be described as a multi classification trough logistic multinomial regression. The custom metric I would like to implement is this: Where Number_of_Classes must be calculate from batch, i.e