Skip to content

Visualization of Keras Custom Metrics

This topic shows you how to set experiment custom metrics and their effects. The topic builds on Getting Started for Keras and Keras Custom Metrics.

The following steps are covered:

  • Create a custom metric function.
  • Set the custom metric function to be evaluated and monitored by MissingLink.

Preparation

Compare the basic script with the resulting script.

Write code

  1. Create a custom metric function:

    Right above model.compile, create a custom metric function:

    def mean_of_rounded_y_pred(y_true, y_pred):
        return K.mean(K.round(y_pred))
    
    model.compile(
        loss=keras.losses.categorical_crossentropy,
        optimizer=keras.optimizers.Adadelta(),
        metrics=['accuracy', 'categorical_accuracy',
                'mean_squared_error', 'hinge'])
    
  2. Set custom metrics for an experiment to be monitored:

    In the base script, modify the model.compile to the following:

    model.compile(
        loss=keras.losses.categorical_crossentropy,
        optimizer=keras.optimizers.Adadelta(),
        metrics=['accuracy', 'categorical_accuracy',
                'mean_squared_error', 'hinge',
                mean_of_rounded_y_pred])  # Add custom metric function
    


You should have added custom metrics to your Keras visualization experiment successfully.

  • Inspect the resulting script.
  • Run the new script and see how the MissingLink dashboard helps with monitoring the experiment. A description follows.

Viewing the new functionality on the dashboard

You can see the custom metrics across different experiments on your MissingLink dashboard.