question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support to log hparams and metrics to tensorboard?

See original GitHub issue

How can I log metrics (e.g. validation loss of best epoch) together with the set of hyperparameters?

I have looked through the docs and through the code. It seems like an obvious thing, so maybe I’m just not getting it.

Currently, the only way that I found was to extend the logger class:

class MyTensorBoardLogger(TensorBoardLogger):

    def __init__(self, *args, **kwargs):
        super(MyTensorBoardLogger, self).__init__(*args, **kwargs)

    def log_hyperparams(self, *args, **kwargs):
        pass

    @rank_zero_only
    def log_hyperparams_metrics(self, params: dict, metrics: dict) -> None:
        params = self._convert_params(params)
        exp, ssi, sei = hparams(params, metrics)
        writer = self.experiment._get_file_writer()
        writer.add_summary(exp)
        writer.add_summary(ssi)
        writer.add_summary(sei)
        # some alternative should be added
        self.tags.update(params)

And then I’m writing the hparams with metrics in a callback:

def on_train_end(self, trainer, module):
        module.logger.log_hyperparams_metrics(module.hparams, {'val_loss': self.best_val_loss})

But that doesn’t seem right. Is there a better way to write some metric together with the hparams as well?

Environment

  • OS: Ubuntu18.04
  • conda4.8.3
  • pytorch-lightning==0.7.1
  • torch==1.4.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:16
  • Comments:50 (20 by maintainers)

github_iconTop GitHub Comments

8reactions
williamFalconcommented, May 19, 2020

yes, let’s officially make this a fix! @mRcSchwering want to submit a PR?

7reactions
mRcSchweringcommented, Apr 9, 2020

Usually I am training and validating a model with different sets of hyperparameters in a loop. After each round the final output is often something like “val-loss”. This would be the validation loss of the best epoch achieved in this particular round. Eventually, I have a number of “best validation losses” and each of these represents a certain set of hyper parameters.

After the last training round I am looking at the various sets of hyperparameters and compare them to their associated best validation loss. Tensorboard already provides tools for that: Visualize the results in TensorBoard’s HParams plugin.

In your TensorBoardLogger you are already using the hparams function to summarize the hyperparameters. So, you are almost there. This function can also take metrics as a second argument. However, in your current implementation you always pass a {}. That’s why I had to overwrite your original implementation. Furthermore you are writing this summary once in the beginning of the round. But the metrics are only known at the very end.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add support to log hparams and metrics to tensorboard? #1228
Is there a better way to write some metric together with the hparams as well? Environment. OS: Ubuntu18.04; conda4.8.3; pytorch-lightning==0.7.1 ...
Read more >
Hyperparameter Tuning with the HParams Dashboard
Adapt TensorFlow runs to log hyperparameters and metrics; Start runs and log them all under one parent directory; Visualize the results in ...
Read more >
Metrics in Tensorboard's Hparam View - PyTorch Lightning
I am trying to log the test results in Tensorboard's Hparam View. I read a lot of posts on multiple github issue pages...
Read more >
Diving into TensorBoard - Medium
After executing this there will be a new directory called metrics under the logdir directory. To record, the value call invokes the below...
Read more >
Deep Dive Into TensorBoard: Tutorial With Examples
In this piece, we'll focus on TensorFlow's open-source visualization toolkit TensorBoard. The tool enables you to track various metrics such as accuracy and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found