Keras-在训练期间使用TensorBoard监控数量 [英] Keras - monitoring quantities with TensorBoard during training

查看:242
本文介绍了Keras-在训练期间使用TensorBoard监控数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Tensorflow,可以使用tf.summary监视训练期间的数量.

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

是否可以使用Keras做同样的事情?您能否通过修改 https://github上的代码来包含一个示例. com/fchollet/keras/blob/master/examples/variational_autoencoder.py 并监控KL丢失(已定义

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)

提前谢谢!

推荐答案

实际上,一种解决方法是在编译模型时添加要监视的数量作为度量.

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

例如,我想监视KL散度(在可变自动编码器的情况下),所以我这样写:

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])

它满足了我的需求

这篇关于Keras-在训练期间使用TensorBoard监控数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆