TensorBoardLogger¶
- class lightning_fabric.loggers.TensorBoardLogger(root_dir, name='lightning_logs', version=None, default_hp_metric=True, prefix='', sub_dir=None, **kwargs)[source]¶
Bases:
lightning_fabric.loggers.logger.Logger
Log to local file system in TensorBoard format.
Implemented using
SummaryWriter
. Logs are saved toos.path.join(root_dir, name, version)
. This is the recommended logger in Lightning Fabric.- Parameters
root_dir¶ (
Union
[str
,Path
]) – The root directory in which all your experiments with different names and versions will be stored.name¶ (
Optional
[str
]) – Experiment name. Defaults to'lightning_logs'
. If it is the empty string then no per-experiment subdirectory is used.version¶ (
Union
[int
,str
,None
]) – Experiment version. If version is not specified the logger inspects the save directory for existing versions, then automatically assigns the next available version. If it is a string then it is used as the run-specific subdirectory name, otherwise'version_${version}'
is used.default_hp_metric¶ (
bool
) – Enables a placeholder metric with key hp_metric when log_hyperparams is called without a metric (otherwise calls tolog_hyperparams
without a metric are ignored).prefix¶ (
str
) – A string to put at the beginning of all metric keys.sub_dir¶ (
Union
[str
,Path
,None
]) – Sub-directory to group TensorBoard logs. If asub_dir
argument is passed then logs are saved in/root_dir/name/version/sub_dir/
. Defaults toNone
in which case logs are saved in/root_dir/name/version/
.**kwargs¶ – Additional arguments used by
tensorboardX.SummaryWriter
can be passed as keyword arguments in this logger. To automatically flush to disk, max_queue sets the size of the queue for pending logs before flushing. flush_secs determines how many seconds elapses before flushing.
Example:
from lightning.fabric.loggers import TensorBoardLogger logger = TensorBoardLogger("path/to/logs/root", name="my_model") logger.log_hyperparams({"epochs": 5, "optimizer": "Adam"}) logger.log_metrics({"acc": 0.75}) logger.finalize("success")
- log_hyperparams(params, metrics=None)[source]¶
Record hyperparameters. TensorBoard logs with and without saved hyperparameters are incompatible, the hyperparameters are then not displayed in the TensorBoard. Please delete or move the previously saved logs to display the new ones with hyperparameters.
- log_metrics(metrics, step=None)[source]¶
Records metrics. This method logs metrics as soon as it received them.
- property experiment: tensorboardX.SummaryWriter¶
Actual tensorboard object. To use TensorBoard features anywhere in your code, do the following.
Example:
logger.experiment.some_tensorboard_function()
- Return type
SummaryWriter
- property log_dir: str¶
The directory for this run’s tensorboard checkpoint.
By default, it is named
'version_${self.version}'
but it can be overridden by passing a string value for the constructor’s version parameter instead ofNone
or an int.- Return type
- property root_dir: str¶
Gets the save directory where the TensorBoard experiments are saved.
- Return type
- Returns
The local path to the save directory where the TensorBoard experiments are saved.