如何使用tensorboardX在同一张图表上获得两个标量?

时间:2018-12-02 15:50:29

标签: python pytorch tensorboardx

文档似乎表明add_custom_scalars_multilinechart可以执行此操作,但无法正常工作。

具有这样的内容:

from tensorboardX import SummaryWriter
writer = SummaryWriter(comment='test')

writer.add_custom_scalars_multilinechart(['loss/train', 'loss/test'], title='losses')

for blahblah:
    ...
    writer.add_scalar('loss/train', loss.item(), epoch)
    writer.add_scalar('loss/test', loss_test.item(), epoch)

1 个答案:

答案 0 :(得分:1)

使用tensorboardX在同一张图上绘制两个标量:

from tensorboardX import SummaryWriter

为两个标量创建两个summaryWriter

writer_train = SummaryWriter('runs/train_0')
writer_test = SummaryWriter('runs/test_0')

将标量实例添加到相应的summaryWriter中;它们必须具有相同的标签,例如:“ LOSS”

for data in loop:
    writer_train.add_scalar('LOSS', loss.data.item(), idx)
    writer_test.add_scalar('LOSS', loss_test.data.item(), idx)

有关工作代码,请访问github:Examples with tensorboardX (请参阅more_plots_one_chat.py)

教程:TensorboardX