在 Tensorboard 中显示 Keras 图而不使用 fit 方法中的回调

Sha*_*ney 3 python-3.x keras tensorflow tensorboard

是否可以在不使用 fit 方法中的 tensorboard 回调的情况下在 Tensorboard 中显示 Keras 图?

是否可以从 Keras 中提取图形并使用 tensorflow FileWriter 显示图形? tf.summary.FileWriter(logdir='logdir', graph=graph)

我想这样做是为了检查图形这部分的所有连接是否符合预期(此模型是远未完成的较大模型的一部分)。

谢谢。

Sha*_*ney 5

通过从后端提取 Tensorflow 图并使用文件编写器,结果证明非常简单。

import tensorflow as tf
# Used to get the graph
from tensorflow.python.keras import backend as K


tb_path = "logs/"

# Simple model to test the tensorboard plotting
model = SimpleModel(50, 20, 10).build_model()

# Get the sessions graph
graph = K.get_session().graph

# Display with the tensorflow file writer
writer = tf.summary.FileWriter(logdir=tb_path, graph=graph)
Run Code Online (Sandbox Code Playgroud)