先上代码
from torch.utils import tensorboard
import numpy as np
writer = {
'loss': tensorboard.SummaryWriter("./drive/MyDrive/logs/loss"), #必须要不同的writer
'acc': tensorboard.SummaryWriter("./drive/MyDrive/logs/acc"),
'lr': tensorboard.SummaryWriter("./drive/MyDrive/logs/lr")
}
data = np.random.random((3, 10)) #生成模拟数据
loss_data = data[0]
acc_data = data[1]
lr_data = data[2]
for i in range(10):
writer['loss'].add_scalar("data", loss_data[i], i) #要想显示在一张图 表格名字要一样!!
writer['acc'].add_scalar("data", acc_data[i], i)
writer['lr'].add_scalar("data", lr_data[i], i)
writer['loss'].close()
writer['acc'].close()
writer['lr'].close()
exit()
终端命令:
tensorboard --logdir="drive/mydrive/logs"
运行结果:
要点:
1、每条线一个单独的文件夹
2、每条线一个单独的writer
3、表格名必须相同
屁大点事搞了好久,到处查,都不对!!三句话就能说清楚的,要么搞一大篇,要么代码乱七八糟