Search code examples
monitoringkerastensorboardautoencoder

Keras - monitoring quantities with TensorBoard during training


With Tensorflow it is possible to monitor quantities during training, using tf.summary.

Is it possible to do the same using Keras ? Could you include an example by modifying the code at https://github.com/fchollet/keras/blob/master/examples/variational_autoencoder.py and monitoring the KL loss (defined at line 53)

Thank you in advance !


Solution

  • Actually a workaround consists in adding the quantities to monitor as metrics when compiling the model.

    For instance, I wanted to monitor the KL divergence (in the context of variational auto encoders), so I wrote this:

    def kl_loss(y_true, y_pred):
        kl_loss = - 0.5 * K.sum(1 + K.log(z_var_0+1e-8) - K.square(z_mean_0) - z_var_0, axis=-1)
        return kl_loss
    
    vae.compile(optimizer='rmsprop', loss=vae_loss, metrics=['accuracy', kl_loss])
    

    And it does what I need