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

How to get two scalars on same chart with 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)

使用 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