Keras:将Tensorboard与train_on_batch()结合使用 [英] Keras: use Tensorboard with train_on_batch()
问题描述
对于keras函数fit()
和fit_generator()
,可以通过将keras.callbacks.TensorBoard
对象传递给函数来实现张量板可视化.对于train_on_batch()
函数,显然没有可用的回调.在这种情况下,keras中还有其他选项可用来创建Tensorboard吗?
For the keras functions fit()
and fit_generator()
there is the possibility of tensorboard visualization by passing a keras.callbacks.TensorBoard
object to the functions. For the train_on_batch()
function there obviously are no callback available. Are there other options in keras to create a Tensorboard in this case?
推荐答案
我认为当前唯一的选择是使用tensorflow代码.在此stackoverflow答案中,我找到了一种手动创建张量板日志的方法.因此,带有keras train_on_batch()
的代码示例可能如下所示:
I think that currently the only option is to use tensorflow code. In this stackoverflow answer I found a way to create a tensorboard log manually. Thus a code sample with the keras train_on_batch()
could look like this:
# before training init writer (for tensorboard log) / model
writer = tf.summary.FileWriter(...)
model = ...
# train model
loss = model.train_on_batch(...)
summary = tf.Summary(value=[tf.Summary.Value(tag="loss",
simple_value=value), ])
writer.add_summary(summary)
注意:对于Tensorboard中的此示例,您必须选择水平轴"RELATIVE",因为不会传递任何步骤到夏季.
Note: For this example in Tensorboard you have to choose the Horizontal Axis "RELATIVE" as no step is passed to the summery.
这篇关于Keras:将Tensorboard与train_on_batch()结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!