[Keras] Three ways to use custom validation metrics in Keras

Keras offers some basic metrics to validate the test data set like accuracy, binary accuracy or categorical accuracy. However sometimes other metrics are more feasable to evaluate your model. In this post I will show three different approaches to apply your cusom metrics in Keras.

Simple callbacks

The simplest one is described in the official Keras documentation. It is basically just a measure, which accepts the true values and the predictions:

To use this metric, we just pass it to the model compilation:

It prints scores for validation and training data:

Interval metrics on custom validation data

To calculate metrics after a custom number of epochs it is possible to use custom callbacks in Keras like this:

This metric is passed as a callback:

It prints scores after each interval

Persisted metrics

To persist all the calculated metrics, it is also possible to use a callback. Furthermore the control over what excactly is calculated

This metric is passed as a callback:

To access the metrics:

Related Posts

Leave a reply