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)


You may want to use add_scalars rather than add_scalar

1 Like