首先在colab安装tensorboardX
tensorboardX github
!pip install tensorboardX
!pip install crc32c
!pip install soundfile
#运行tensorboard
% load_ext tensorboard
#使用pytorch进行神经网络训练时,想要生成loss或者其他评价指标的折线图,使用add_scalar
#add_scalar(tag, scalar_value, global_step=None, walltime=None)
#main_tag(string)- 该图的标签(名称)。
#tag_scalar_dict(dict)- 曲线图的y坐标
#global_step(int)- 曲线图的 x 坐标
#walltime(float)- 为 event 文件的文件名设置时间,默认为 time.time()
from tensorboardX import SummaryWriter
writer1 = SummaryWriter('runs/example1')
-
writer1.add_scalar('train_loss',train_loss,epoch+1)
可以在colab左侧看到形成的example1
#启动tensorboard
% tensorboard --logdir=runs/example1
也可以两个图同时生成
writer2 = SummaryWriter('runs/example2')
writer1 = SummaryWriter('runs/example1')
writer1.add_scalar('train_loss',train_loss,epoch+1)
writer2.add_scalar('test_acc',(100*correct/total),epoch+1)
#启动tensorboard,运行改成父级文件夹即可
% tensorboard --logdir=runs
#关闭
writer.close()
网友评论