PyTorch使用tensorboard可以显示网络运行情况,和TensorFlow的tensorboard使用很类似。均需要安装tensorboard包。
pip install tensorboard==1.15.0
导入:
from torch.utils.tensorboard import SummaryWriter
指定log路径:
log_dir = './run_logs'
self.writer = SummaryWriter(log_dir)
写入到log:
self.board_write_step = 50#每50个step写一次board_log
if (global_steps+1) % self.board_write_step == 0:
self.writer.add_image("result", result_img, global_step=global_steps)
self.writer.add_scalar("acc", acc, global_step=global_steps)
在shell中开启tensorboard:
tensorboard --logdir=./run_logs
浏览器中打开localhost:6006
: