[Python] add_hparams() function from TensorBoard doesn't work properly

Discussão em 'Python' iniciado por Stack, Abril 8, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to add metrics to this SummaryWriter, but it's not working.

    I'm using the add_hparams() function of SummaryWriter, the details of which can be found here: https://pytorch.org/docs/stable/tensorboard.html.

    I'm doing it this way:

    writer = SummaryWriter(f'runs/lstm_experiment_final')

    for e in tqdm(range(num_epochs)):
    tr_loss, tr_f1, tr_precision, tr_recall = training_loop(model, train_dataloader, loss_function, optimizer, e, writer)
    val_loss, val_f1, val_precision, val_recall = validation_loop(model, test_dataloader, loss_function, e, writer)

    metric_dict = {'Loss/train': tr_loss, 'Loss/valid': val_loss,
    'F1/train': tr_f1, 'F1/valid': val_f1,
    'Precision/train': tr_precision, 'Precision/valid': val_precision,
    'Recall/train': tr_recall, 'Recall/valid': val_recall}
    writer.add_hparams(best_params, metric_dict, global_step=num_epochs-1)
    writer.close()


    This is what's happening.

    enter image description here

    In other words, hyperparameters are indeed being logged on TensorBoard, but the metric values are not.

    I hope someone has already seen my problem and knows how to fix this. Thanks in advance.

    Continue reading...

Compartilhe esta Página