2020-05-05 02:16:54 +00:00
|
|
|
.. testsetup:: *
|
|
|
|
|
|
|
|
from pytorch_lightning.trainer.trainer import Trainer
|
|
|
|
from pytorch_lightning.core.lightning import LightningModule
|
|
|
|
|
2020-08-13 22:56:51 +00:00
|
|
|
.. _experiment-logging:
|
2020-05-05 02:16:54 +00:00
|
|
|
|
2020-02-11 04:55:22 +00:00
|
|
|
Experiment Logging
|
2020-04-16 16:04:12 +00:00
|
|
|
==================
|
2020-02-11 04:55:22 +00:00
|
|
|
|
|
|
|
Comet.ml
|
2020-02-11 12:41:15 +00:00
|
|
|
^^^^^^^^
|
2020-02-11 04:55:22 +00:00
|
|
|
|
|
|
|
`Comet.ml <https://www.comet.ml/site/>`_ is a third-party logger.
|
2020-04-16 16:04:12 +00:00
|
|
|
To use :class:`~pytorch_lightning.loggers.CometLogger` as your logger do the following.
|
|
|
|
First, install the package:
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
pip install comet-ml
|
|
|
|
|
|
|
|
Then configure the logger and pass it to the :class:`~pytorch_lightning.trainer.trainer.Trainer`:
|
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
.. testcode::
|
|
|
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
trainer = Trainer(logger=comet_logger)
|
2020-04-16 16:04:12 +00:00
|
|
|
|
|
|
|
The :class:`~pytorch_lightning.loggers.CometLogger` is available anywhere except ``__init__`` in your
|
|
|
|
:class:`~pytorch_lightning.core.lightning.LightningModule`.
|
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
.. testcode::
|
2020-04-16 16:04:12 +00:00
|
|
|
|
2020-05-05 02:16:54 +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-02-11 04:55:22 +00:00
|
|
|
|
2020-03-20 19:49:01 +00:00
|
|
|
.. seealso::
|
|
|
|
:class:`~pytorch_lightning.loggers.CometLogger` docs.
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-06-18 21:54:29 +00:00
|
|
|
----------------
|
2020-06-17 14:53:48 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
MLflow
|
|
|
|
^^^^^^
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +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-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
.. code-block:: bash
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
pip install mlflow
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
Then configure the logger and pass it to the :class:`~pytorch_lightning.trainer.trainer.Trainer`:
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
.. testcode::
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +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-04-16 16:04:12 +00:00
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
:class:`~pytorch_lightning.loggers.MLFlowLogger` docs.
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-06-18 21:54:29 +00:00
|
|
|
----------------
|
2020-06-17 14:53:48 +00:00
|
|
|
|
2020-02-11 04:55:22 +00:00
|
|
|
Neptune.ai
|
|
|
|
^^^^^^^^^^
|
|
|
|
|
|
|
|
`Neptune.ai <https://neptune.ai/>`_ is a third-party logger.
|
2020-04-16 16:04:12 +00:00
|
|
|
To use :class:`~pytorch_lightning.loggers.NeptuneLogger` as your logger do the following.
|
|
|
|
First, install the package:
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
.. code-block:: bash
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
pip install neptune-client
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
Then configure the logger and pass it to the :class:`~pytorch_lightning.trainer.trainer.Trainer`:
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
.. testcode::
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
from pytorch_lightning.loggers import NeptuneLogger
|
2020-06-29 01:36:46 +00:00
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
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-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
The :class:`~pytorch_lightning.loggers.NeptuneLogger` is available anywhere except ``__init__`` in your
|
|
|
|
:class:`~pytorch_lightning.core.lightning.LightningModule`.
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
.. testcode::
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +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-04-16 16:04:12 +00:00
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
:class:`~pytorch_lightning.loggers.NeptuneLogger` docs.
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-06-18 21:54:29 +00:00
|
|
|
----------------
|
2020-06-17 14:53:48 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
Tensorboard
|
|
|
|
^^^^^^^^^^^
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
To use `TensorBoard <https://pytorch.org/docs/stable/tensorboard.html>`_ as your logger do the following.
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
.. testcode::
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
from pytorch_lightning.loggers import TensorBoardLogger
|
|
|
|
logger = TensorBoardLogger('tb_logs', name='my_model')
|
|
|
|
trainer = Trainer(logger=logger)
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
The :class:`~pytorch_lightning.loggers.TensorBoardLogger` is available anywhere except ``__init__`` in your
|
|
|
|
:class:`~pytorch_lightning.core.lightning.LightningModule`.
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
.. testcode::
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +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-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
.. seealso::
|
|
|
|
:class:`~pytorch_lightning.loggers.TensorBoardLogger` docs.
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-06-18 21:54:29 +00:00
|
|
|
----------------
|
2020-06-17 14:53:48 +00:00
|
|
|
|
2020-02-11 04:55:22 +00:00
|
|
|
Test Tube
|
2020-02-11 12:41:15 +00:00
|
|
|
^^^^^^^^^
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +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-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
.. code-block:: bash
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
pip install test_tube
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
Then configure the logger and pass it to the :class:`~pytorch_lightning.trainer.trainer.Trainer`:
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
.. testcode::
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
from pytorch_lightning.loggers import TestTubeLogger
|
|
|
|
logger = TestTubeLogger('tb_logs', name='my_model')
|
|
|
|
trainer = Trainer(logger=logger)
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
The :class:`~pytorch_lightning.loggers.TestTubeLogger` is available anywhere except ``__init__`` in your
|
|
|
|
:class:`~pytorch_lightning.core.lightning.LightningModule`.
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
.. testcode::
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +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-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
.. seealso::
|
|
|
|
:class:`~pytorch_lightning.loggers.TestTubeLogger` docs.
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-06-18 21:54:29 +00:00
|
|
|
----------------
|
2020-06-17 14:53:48 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
Weights and Biases
|
|
|
|
^^^^^^^^^^^^^^^^^^
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +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-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
.. code-block:: bash
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
pip install wandb
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
Then configure the logger and pass it to the :class:`~pytorch_lightning.trainer.trainer.Trainer`:
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
.. testcode::
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
from pytorch_lightning.loggers import WandbLogger
|
2020-06-29 01:36:46 +00:00
|
|
|
wandb_logger = WandbLogger(offline=True)
|
2020-05-05 02:16:54 +00:00
|
|
|
trainer = Trainer(logger=wandb_logger)
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
The :class:`~pytorch_lightning.loggers.WandbLogger` is available anywhere except ``__init__`` in your
|
|
|
|
:class:`~pytorch_lightning.core.lightning.LightningModule`.
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
.. testcode::
|
2020-02-11 04:55:22 +00:00
|
|
|
|
2020-05-05 02:16:54 +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-04-16 16:04:12 +00:00
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
:class:`~pytorch_lightning.loggers.WandbLogger` docs.
|
2020-02-25 19:52:39 +00:00
|
|
|
|
2020-06-18 21:54:29 +00:00
|
|
|
----------------
|
2020-06-17 14:53:48 +00:00
|
|
|
|
2020-02-25 19:52:39 +00:00
|
|
|
Multiple Loggers
|
2020-03-20 19:49:01 +00:00
|
|
|
^^^^^^^^^^^^^^^^
|
2020-02-25 19:52:39 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
Lightning supports the use of multiple loggers, just pass a list to the
|
|
|
|
:class:`~pytorch_lightning.trainer.trainer.Trainer`.
|
2020-02-25 19:52:39 +00:00
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
.. testcode::
|
2020-02-25 19:52:39 +00:00
|
|
|
|
2020-05-05 02:16:54 +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])
|
2020-02-25 19:52:39 +00:00
|
|
|
|
2020-04-16 16:04:12 +00:00
|
|
|
The loggers are available as a list anywhere except ``__init__`` in your
|
|
|
|
:class:`~pytorch_lightning.core.lightning.LightningModule`.
|
|
|
|
|
2020-05-05 02:16:54 +00:00
|
|
|
.. testcode::
|
2020-04-16 16:04:12 +00:00
|
|
|
|
2020-05-05 02:16:54 +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)
|