在PyTorch中使用Tensorboard
PyTorch官方教程:https://pytorch.org/tutorials/recipes/recipes/tensorboard_with_pytorch.html
TensorBoard vs TensorboardX: https://poe.com/s/wDImi8HWK3EdbD7ij28O
PyTorch1.1版本后支持原生的Tensorboard
在PyToch中使用Tensorboard
-
实例化一个SummaryWriter(记录器)对象, 用于后续保存标量(scalar)/图像(image)/图(graph)等日志文件
# from tensorboardX import SummaryWriter from torch.utils.tensorboard import SummaryWriter #SummaryWriter Encapsultes everything log_dir = "./my_log_dir" writer = SummaryWriter(log_dir) #实例化对象时指定存放log的目录
-
保存sth(something)
通用的API格式:add_sth(tag_name, object, iter_num)
举例说明:保存标量writer.add_scalar('loss', value, iteration)
-
可视化网络 Add graph
https://tensorboardx.readthedocs.io/en/latest/tutorial.html#add-graph -
监测训练过程
tensorboard --logdir your_log_dir --bind_all
注意是日志目录,而不是要指定日志文件;指定--bind_all
后:服务器训练模型,本地浏览器可以打开tensorboard