TensorBoard - Plot training and validation losses on the same graph?

前端 未结 8 1772
不思量自难忘°
不思量自难忘° 2020-12-02 18:34

Is there a way to plot both the training losses and validation losses on the same graph?

It\'s easy to have two separate scalar summaries for each of them i

8条回答
  •  Happy的楠姐
    2020-12-02 19:05

    The solution in PyTorch 1.5 with the approach of two writers:

    import os
    from torch.utils.tensorboard import SummaryWriter
    
    LOG_DIR = "experiment_dir"
    train_writer = SummaryWriter(os.path.join(LOG_DIR, "train"))
    val_writer = SummaryWriter(os.path.join(LOG_DIR, "val"))
    
    # while in the training loop
    for k, v in train_losses.items()
        train_writer.add_scalar(k, v, global_step)
    
    # in the validation loop
    for k, v in val_losses.items()
        val_writer.add_scalar(k, v, global_step)
    
    # at the end
    train_writer.close()
    val_writer.close()
    

    Keys in the train_losses dict have to match those in the val_losses to be grouped on the same graph.

提交回复
热议问题