jupyter-tensorboard 在 Jupyter 启动 Tensorboard!用于 Tensorboard 的 Jupyter 笔记本集成。
pip install jupyter-tensorboard
一个简单的例子
import tensorflow as tf
# 使用 autograph 构建静态图
@tf.function
def strjoin(x,y):
z = tf.strings.join([x,y],separator = " ")
tf.print(z)
return z
result = strjoin(tf.constant("hello"),tf.constant("world"))
print(result)
输出:
hello world
tf.Tensor(b'hello world', shape=(), dtype=string)
创建日志:
import datetime
from pathlib import Path
# 创建日志
stamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
logdir = str(Path('data/autograph/' + stamp))
writer = tf.summary.create_file_writer(logdir)
# 开启 autograph 跟踪
tf.summary.trace_on(graph=True, profiler=True)
# 执行autograph
result = strjoin("hello", "world")
# 将计算图信息写入日志
with writer.as_default():
tf.summary.trace_export(
name="autograph",
step=0,
profiler_outdir=logdir)
启动 tensorboard 在 jupyter 中的魔法命令
%load_ext tensorboard
启动 tensorboard:
%tensorboard --logdir data/autograph/
网友评论