安装依赖
pip install teorboard
pip install torch_tb_profiler
了解teorboard
记录并可视化标量[组]、图片[组]。
如何使用
第一步:构建模型,记录中间值,写入summarywriter
每次写入一个标量add_scalar
比如:
from torch.utils.tensorboard import SummaryWriter
writer = SummaryWriter() # 默认会记录到'./runs/'这一目录下,也可以自己定义
x = range(100)
for i in x:writer.add_scalar('y=2x', i * 2, i)
writer.close()
期望输出:
每次写入多个标量add_scalars
比如:
from torch.utils.tensorboard import SummaryWriter
writer = SummaryWriter()
r = 5
for i in range(100):writer.add_scalars('run_14h', {'xsinx':i*np.sin(i/r),'xcosx':i*np.cos(i/r),'tanx': np.tan(i/r)}, i)
writer.close()
期望输出:
写入某个变量的分布add_histogram
比如:
from torch.utils.tensorboard import SummaryWriter
import numpy as np
writer = SummaryWriter()
for i in range(10):x = np.random.random(1000)writer.add_histogram('distribution centers', x + i, i)
writer.close()
期望输出:
写入单个图片add_image
比如:
from torch