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

查看:39
本文介绍了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 损失(定义 在第 53 行)

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天全站免登陆