Skip to content

Commit

Permalink
Update TBLogger docs (#6315)
Browse files Browse the repository at this point in the history
* Update tensorboard.py

* Update logging.rst

* pep8

* Update logging.rst

* Update logging.rst

* Apply suggestions from code review

* add code sample

* Update logging.rst

Co-authored-by: Jirka Borovec <[email protected]>
  • Loading branch information
s-rog and Borda authored Mar 8, 2021
1 parent 826375e commit ff16104
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
19 changes: 19 additions & 0 deletions docs/source/extensions/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,25 @@ Some loggers also allow logging the hyperparams used in the experiment. For inst
when using the TestTubeLogger or the TensorBoardLogger, all hyperparams will show
in the `hparams tab <https://pytorch.org/docs/stable/tensorboard.html#torch.utils.tensorboard.writer.SummaryWriter.add_hparams>`_.

.. note::
If you want to track a metric in the tensorboard hparams tab, log scalars to the key ``hp_metric``. If tracking multiple metrics, initialize ``TensorBoardLogger`` with ``default_hp_metric=False`` and call ``log_hyperparams`` only once with your metric keys and initial values. Subsequent updates can simply be logged to the metric keys. Refer to the following for examples on how to setup proper hyperparams metrics tracking within :doc:`LightningModule <../common/lightning_module>`.

.. code-block:: python
# Using default_hp_metric
def validation_step(self, batch, batch_idx):
self.log("hp_metric", some_scalar)
# Using custom or multiple metrics (default_hp_metric=False)
def on_train_start(self):
self.logger.log_hyperparams(self.hparams, {"hp/metric_1": 0, "hp/metric_2": 0})
def validation_step(self, batch, batch_idx):
self.log("hp/metric_1", some_scalar_1)
self.log("hp/metric_2", some_scalar_2)
In the example, using `hp/` as a prefix allows for the metrics to be grouped under "hp" in the tensorboard scalar tab where you can collapse them.

----------

*************
Expand Down
11 changes: 7 additions & 4 deletions pytorch_lightning/loggers/tensorboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ class TensorBoardLogger(LightningLoggerBase):
preinstalled.
Example:
>>> from pytorch_lightning import Trainer
>>> from pytorch_lightning.loggers import TensorBoardLogger
>>> logger = TensorBoardLogger("tb_logs", name="my_model")
>>> trainer = Trainer(logger=logger)
.. testcode::
from pytorch_lightning import Trainer
from pytorch_lightning.loggers import TensorBoardLogger
logger = TensorBoardLogger("tb_logs", name="my_model")
trainer = Trainer(logger=logger)
Args:
save_dir: Save directory
Expand Down

0 comments on commit ff16104

Please sign in to comment.