(二)pytorch可视化

import torch
from tensorboardX import SummaryWriter
#writer = SummaryWriter()
 # 声明writer对象,保存的文件夹,默认是runs文件夹(在当前目录运行tensorboard --logdir runs)
 #在当前目录运行tensorboard --logdir log
writer = SummaryWriter(log_dir='./log', comment='test_net')

x = torch.FloatTensor([100])
y = torch.FloatTensor([200])

for epoch in range(100):
    x /= 2.0
    y /= 2.0
    loss = y - x
    print(loss)
    #添加正常显示
    writer.add_histogram('zz/x', x, epoch)
    writer.add_histogram('zz/y', y, epoch)
    #添加标量化显示
    writer.add_scalar('data/x', x, epoch)
    writer.add_scalar('data/y', y, epoch)
    writer.add_scalar('data/loss', loss, epoch)
    #添加标量组,一起显示
    writer.add_scalars('data/scalar_group', {'x': x,
                                             'y': y,
                                             'loss': loss}, epoch)
    writer.add_text('zz/text', 'zz: this is epoch ' + str(epoch), epoch)


(二)pytorch可视化_第1张图片

你可能感兴趣的:(pytorch)