2020-06-19 15:00:46 +00:00
|
|
|
.. testsetup:: *
|
|
|
|
|
|
|
|
from pytorch_lightning.trainer.trainer import Trainer
|
2020-10-06 22:53:39 +00:00
|
|
|
from pytorch_lightning.core.lightning import LightningModule
|
2020-06-19 15:00:46 +00:00
|
|
|
|
2020-08-13 22:56:51 +00:00
|
|
|
.. _loggers:
|
2020-01-21 20:18:32 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
*******
|
2020-02-11 04:55:22 +00:00
|
|
|
Loggers
|
2020-10-06 22:53:39 +00:00
|
|
|
*******
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
Lightning supports the most popular logging frameworks (TensorBoard, Comet, etc...). TensorBoard is used by default,
|
|
|
|
but you can pass to the :class:`~pytorch_lightning.trainer.trainer.Trainer` any combintation of the following loggers.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
All loggers log by default to `os.getcwd()`. To change the path without creating a logger set
|
|
|
|
`Trainer(default_root_dir='/your/path/to/save/checkpoints')`
|
|
|
|
|
|
|
|
Read more about :ref:`logging` options.
|
|
|
|
|
2020-11-08 17:16:22 +00:00
|
|
|
To log arbitrary artifacts like images or audio samples use the `trainer.log_dir` property to resolve
|
|
|
|
the path.
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
def training_step(self, batch, batch_idx):
|
|
|
|
img = ...
|
|
|
|
log_image(img, self.trainer.log_dir)
|
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
Comet.ml
|
|
|
|
========
|
|
|
|
|
|
|
|
`Comet.ml <https://www.comet.ml/site/>`_ is a third-party logger.
|
|
|
|
To use :class:`~pytorch_lightning.loggers.CometLogger` as your logger do the following.
|
|
|
|
First, install the package:
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
.. code-block:: bash
|
2020-06-19 15:00:46 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
pip install comet-ml
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
Then configure the logger and pass it to the :class:`~pytorch_lightning.trainer.trainer.Trainer`:
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-06-19 15:00:46 +00:00
|
|
|
.. testcode::
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
import os
|
|
|
|
from pytorch_lightning.loggers import CometLogger
|
|
|
|
comet_logger = CometLogger(
|
|
|
|
api_key=os.environ.get('COMET_API_KEY'),
|
|
|
|
workspace=os.environ.get('COMET_WORKSPACE'), # Optional
|
|
|
|
save_dir='.', # Optional
|
|
|
|
project_name='default_project', # Optional
|
|
|
|
rest_api_key=os.environ.get('COMET_REST_API_KEY'), # Optional
|
|
|
|
experiment_name='default' # Optional
|
|
|
|
)
|
2020-06-19 06:38:10 +00:00
|
|
|
trainer = Trainer(logger=comet_logger)
|
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
The :class:`~pytorch_lightning.loggers.CometLogger` is available anywhere except ``__init__`` in your
|
|
|
|
:class:`~pytorch_lightning.core.lightning.LightningModule`.
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-06-19 15:00:46 +00:00
|
|
|
.. testcode::
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
class MyModule(LightningModule):
|
|
|
|
def any_lightning_module_function_or_hook(self):
|
|
|
|
some_img = fake_image()
|
|
|
|
self.logger.experiment.add_image('generated_images', some_img, 0)
|
2020-08-13 13:58:05 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
.. seealso::
|
|
|
|
:class:`~pytorch_lightning.loggers.CometLogger` docs.
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
----------------
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
MLflow
|
|
|
|
======
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
`MLflow <https://mlflow.org/>`_ is a third-party logger.
|
|
|
|
To use :class:`~pytorch_lightning.loggers.MLFlowLogger` as your logger do the following.
|
|
|
|
First, install the package:
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
.. code-block:: bash
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
pip install mlflow
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
Then configure the logger and pass it to the :class:`~pytorch_lightning.trainer.trainer.Trainer`:
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-07 03:49:06 +00:00
|
|
|
.. code-block:: python
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
from pytorch_lightning.loggers import MLFlowLogger
|
|
|
|
mlf_logger = MLFlowLogger(
|
|
|
|
experiment_name="default",
|
|
|
|
tracking_uri="file:./ml-runs"
|
|
|
|
)
|
|
|
|
trainer = Trainer(logger=mlf_logger)
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
.. seealso::
|
|
|
|
:class:`~pytorch_lightning.loggers.MLFlowLogger` docs.
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
----------------
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
Neptune.ai
|
|
|
|
==========
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
`Neptune.ai <https://neptune.ai/>`_ is a third-party logger.
|
|
|
|
To use :class:`~pytorch_lightning.loggers.NeptuneLogger` as your logger do the following.
|
|
|
|
First, install the package:
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-09-30 12:31:16 +00:00
|
|
|
.. code-block:: bash
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
pip install neptune-client
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
Then configure the logger and pass it to the :class:`~pytorch_lightning.trainer.trainer.Trainer`:
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
.. testcode::
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
from pytorch_lightning.loggers import NeptuneLogger
|
|
|
|
|
|
|
|
neptune_logger = NeptuneLogger(
|
|
|
|
api_key='ANONYMOUS', # replace with your own
|
|
|
|
project_name='shared/pytorch-lightning-integration',
|
|
|
|
experiment_name='default', # Optional,
|
|
|
|
params={'max_epochs': 10}, # Optional,
|
|
|
|
tags=['pytorch-lightning', 'mlp'], # Optional,
|
|
|
|
)
|
|
|
|
trainer = Trainer(logger=neptune_logger)
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
The :class:`~pytorch_lightning.loggers.NeptuneLogger` is available anywhere except ``__init__`` in your
|
|
|
|
:class:`~pytorch_lightning.core.lightning.LightningModule`.
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
.. testcode::
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
class MyModule(LightningModule):
|
|
|
|
def any_lightning_module_function_or_hook(self):
|
|
|
|
some_img = fake_image()
|
|
|
|
self.logger.experiment.add_image('generated_images', some_img, 0)
|
2020-09-30 12:31:16 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
.. seealso::
|
|
|
|
:class:`~pytorch_lightning.loggers.NeptuneLogger` docs.
|
2020-09-30 12:31:16 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
----------------
|
2020-09-30 12:31:16 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
Tensorboard
|
|
|
|
===========
|
2020-09-30 12:31:16 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
To use `TensorBoard <https://pytorch.org/docs/stable/tensorboard.html>`_ as your logger do the following.
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
.. testcode::
|
|
|
|
|
|
|
|
from pytorch_lightning.loggers import TensorBoardLogger
|
|
|
|
logger = TensorBoardLogger('tb_logs', name='my_model')
|
|
|
|
trainer = Trainer(logger=logger)
|
|
|
|
|
|
|
|
The :class:`~pytorch_lightning.loggers.TensorBoardLogger` is available anywhere except ``__init__`` in your
|
|
|
|
:class:`~pytorch_lightning.core.lightning.LightningModule`.
|
|
|
|
|
|
|
|
.. testcode::
|
|
|
|
|
|
|
|
class MyModule(LightningModule):
|
|
|
|
def any_lightning_module_function_or_hook(self):
|
|
|
|
some_img = fake_image()
|
|
|
|
self.logger.experiment.add_image('generated_images', some_img, 0)
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
:class:`~pytorch_lightning.loggers.TensorBoardLogger` docs.
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
----------------
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
Test Tube
|
|
|
|
=========
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
`Test Tube <https://github.com/williamFalcon/test-tube>`_ is a
|
|
|
|
`TensorBoard <https://pytorch.org/docs/stable/tensorboard.html>`_ logger but with nicer file structure.
|
|
|
|
To use :class:`~pytorch_lightning.loggers.TestTubeLogger` as your logger do the following.
|
|
|
|
First, install the package:
|
2020-08-02 02:31:56 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
pip install test_tube
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
Then configure the logger and pass it to the :class:`~pytorch_lightning.trainer.trainer.Trainer`:
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-07 03:49:06 +00:00
|
|
|
.. code-block:: python
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
from pytorch_lightning.loggers import TestTubeLogger
|
|
|
|
logger = TestTubeLogger('tb_logs', name='my_model')
|
|
|
|
trainer = Trainer(logger=logger)
|
|
|
|
|
|
|
|
The :class:`~pytorch_lightning.loggers.TestTubeLogger` is available anywhere except ``__init__`` in your
|
|
|
|
:class:`~pytorch_lightning.core.lightning.LightningModule`.
|
2020-06-19 15:00:46 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
.. testcode::
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
class MyModule(LightningModule):
|
|
|
|
def any_lightning_module_function_or_hook(self):
|
|
|
|
some_img = fake_image()
|
|
|
|
self.logger.experiment.add_image('generated_images', some_img, 0)
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
.. seealso::
|
|
|
|
:class:`~pytorch_lightning.loggers.TestTubeLogger` docs.
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
----------------
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
Weights and Biases
|
|
|
|
==================
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
`Weights and Biases <https://www.wandb.com/>`_ is a third-party logger.
|
|
|
|
To use :class:`~pytorch_lightning.loggers.WandbLogger` as your logger do the following.
|
|
|
|
First, install the package:
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
.. code-block:: bash
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
pip install wandb
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
Then configure the logger and pass it to the :class:`~pytorch_lightning.trainer.trainer.Trainer`:
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
.. code-block:: python
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
from pytorch_lightning.loggers import WandbLogger
|
|
|
|
wandb_logger = WandbLogger(offline=True)
|
|
|
|
trainer = Trainer(logger=wandb_logger)
|
2020-08-06 20:05:06 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
The :class:`~pytorch_lightning.loggers.WandbLogger` is available anywhere except ``__init__`` in your
|
|
|
|
:class:`~pytorch_lightning.core.lightning.LightningModule`.
|
2020-08-06 20:05:06 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
.. testcode::
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
class MyModule(LightningModule):
|
|
|
|
def any_lightning_module_function_or_hook(self):
|
|
|
|
some_img = fake_image()
|
|
|
|
self.logger.experiment.log({
|
|
|
|
"generated_images": [wandb.Image(some_img, caption="...")]
|
|
|
|
})
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
.. seealso::
|
|
|
|
:class:`~pytorch_lightning.loggers.WandbLogger` docs.
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
----------------
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
Multiple Loggers
|
|
|
|
================
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
Lightning supports the use of multiple loggers, just pass a list to the
|
|
|
|
:class:`~pytorch_lightning.trainer.trainer.Trainer`.
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-07 03:49:06 +00:00
|
|
|
.. code-block:: python
|
2020-06-19 06:38:10 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
from pytorch_lightning.loggers import TensorBoardLogger, TestTubeLogger
|
|
|
|
logger1 = TensorBoardLogger('tb_logs', name='my_model')
|
|
|
|
logger2 = TestTubeLogger('tb_logs', name='my_model')
|
|
|
|
trainer = Trainer(logger=[logger1, logger2])
|
|
|
|
|
|
|
|
The loggers are available as a list anywhere except ``__init__`` in your
|
|
|
|
:class:`~pytorch_lightning.core.lightning.LightningModule`.
|
2020-08-06 10:08:25 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
.. testcode::
|
2020-08-06 10:08:25 +00:00
|
|
|
|
2020-10-06 22:53:39 +00:00
|
|
|
class MyModule(LightningModule):
|
|
|
|
def any_lightning_module_function_or_hook(self):
|
|
|
|
some_img = fake_image()
|
|
|
|
# Option 1
|
|
|
|
self.logger.experiment[0].add_image('generated_images', some_img, 0)
|
|
|
|
# Option 2
|
|
|
|
self.logger[0].experiment.add_image('generated_images', some_img, 0)
|