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])
它满足了我的需求