TensorBoard- Training with Validation Scalars

Hello all,

I am using TensorBoard and had a question about structuring scalars.

I am using this repository (https://github.com/usuyama/pytorch-unet) as starter code for another problem and am seeing good results based on my model output and loss. My question is, what is the best way to show a validation loss on-top of the training loss?

I was essentially converting the print function

def print_metrics(metrics, epoch_samples, phase):
    outputs = []
    for k in metrics.keys():
        outputs.append("{}: {:4f}".format(k, metrics[k] / epoch_samples))

    print("{}: {}".format(phase, ", ".join(outputs)))

to a metrics to tensorboard function, but I am not seeing training and validation separated.

def metrics2tb(metrics, epoch_samples, phase, tb, epoch):
    for k in metrics.keys():
        tb.add_scalar(k, metrics[k] / epoch_samples, epoch)

![image|422x500](upload://1NET629OjbYs5ut4L1j5nETgYsi.png)

You may want to use add_scalars rather than add_scalar
https://pytorch.org/docs/stable/tensorboard.html#torch.utils.tensorboard.writer.SummaryWriter.add_scalars

1 Like