目录
1 导入tensorboard-前提安装tensorboard!
2 确定存储位置
3 作为预训练参数加载函数
4 调用加载函数
5 保存训练模型参数
6 tensorboard可视化-环境:ubuntu
【学习资源】from torch.utils.tensorboard import SummaryWriter导入不成功问题_
1 导入tensorboard-前提安装tensorboard!
- conda install tensorboard / pip install tensorboard
- from torch.utils.tensorboard import SummaryWriter
from torch.utils.tensorboard import SummaryWriter导入不成功问题
- ImportError: TensorBoard logging requires TensorBoard with Python summary writer installed.
- 原因:SummaryWriter是存在于tensorboardX(其作为tensorboard的子模块)
- conda install tensorboardX / pip install tensorboardX
- from tensorboardX import SummaryWriter
2 确定存储位置
- 申明:writer = SummaryWriter(log_dir=args.run_dir)
- 调用:以loss为例,writer.add_scalar('name',(loss).item(),epoch*len(train_loader)+i)
3 作为预训练参数加载函数
def load_ckpt(args, depth_model, shift_model, focal_model):
if os.path.isfile(args.load_ckpt):
print("loading checkpoint %s" % args.load_ckpt)
checkpoint = torch.load(args.load_ckpt)
# depth_model.load_state_dict(checkpoint['net'])
depth_model.load_state_dict(torch.load(args.load_ckpt))
del checkpoint
torch.cuda.empty_cache()
4 调用加载函数
- model.to(device) 之后添加
- load_ckpt(args, model, None, None)
5 保存训练模型参数
torch.save(model.state_dict(), '位置/命名%d.pth'% (epoch))
6 tensorboard可视化-环境:ubuntu
- 打开args.run_dir所自订的文件目录,如loss存储在tensor文件夹下
- 在tensor文件夹所在目录进入终端,也就是cd 到weights位置
- 注意,如果是虚拟环境,务必激活环境,再进行下一步操作
tensorboard --logdir=tensor
- 终端弹出一个网址,复制到浏览器打开,从而实现可视化!
【Window学习资源】TensorBoard可视化工具简单教程及讲解(TensorFlow与Pytorch)