文章目录
- 1. tensorboardX的安装
- 2. tensorboardX的使用
tensorboardX是一种能将训练过程可视化的工具
1. tensorboardX的安装
安装命令:
pip install tensorboardX
VSCode集成了TensorBoard支持,不过事先要安装torch-tb-profiler,安装命令:
pip install torch-tb-profiler
安装完成后,在Python源文件中tensorboardX模块导入处,点击“启动TensorBoard会话”按钮,然后选择运行事件所在目录,默认选择当前目录即可,tensorboard会自动在当前目录查找运行事件,由此即可启动TensorBoard。
此外,也可以通过以下命令在浏览器查看tensorboard可视化结果:
# logdir为运行事件所在目录
> tensorboard logdir=runs
TensorFlow installation not found - running with reduced feature set.
I1202 20:37:50.824767 15412 plugin.py:429] Monitor runs begin
Serving TensorBoard on localhost; to expose to the network, use a proxy or pass --bind_all
TensorBoard 2.14.0 at http://localhost:6006/ (Press CTRL+C to quit)
# 手动打开命令输出提供的本地服务器地址,如http://localhost:6006/
2. tensorboardX的使用
- 直接创建对象
from tensorboardX import SummaryWriter
writer = SummaryWriter()
# writer.add_scalar():添加监控变量
writer.close()
- 使用上下文管理器
from tensorboardX import SummaryWriter
with SummaryWriter() as writer:
# writer.add_scalar():添加监控变量