Shortcuts

TensorBoardLogger

class lightning.pytorch.loggers.TensorBoardLogger(save_dir, name='lightning_logs', version=None, log_graph=False, default_hp_metric=True, prefix='', sub_dir=None, **kwargs)[소스]

기반 클래스: lightning.pytorch.loggers.logger.Logger, lightning.fabric.loggers.tensorboard.TensorBoardLogger

Log to local file system in TensorBoard format.

Implemented using SummaryWriter. Logs are saved to os.path.join(save_dir, name, version). This is the default logger in Lightning, it comes preinstalled.

Example:

from lightning.pytorch import Trainer
from lightning.pytorch.loggers import TensorBoardLogger

logger = TensorBoardLogger("tb_logs", name="my_model")
trainer = Trainer(logger=logger)
매개변수
  • save_dir (Union[str, Path]) – Save directory

  • name (Optional[str]) – Experiment name. Defaults to 'default'. 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.

  • log_graph (bool) – Adds the computational graph to tensorboard. This requires that the user has defined the self.example_input_array attribute in their model.

  • default_hp_metric (bool) – Enables a placeholder metric with key hp_metric when log_hyperparams is called without a metric (otherwise calls to log_hyperparams without a metric are ignored).

  • prefix (str) – A string to put at the beginning of metric keys.

  • sub_dir (Union[str, Path, None]) – Sub-directory to group TensorBoard logs. If a sub_dir argument is passed then logs are saved in /save_dir/name/version/sub_dir/. Defaults to None in which logs are saved in /save_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.

예제

>>> import shutil, tempfile
>>> tmp = tempfile.mkdtemp()
>>> tbl = TensorBoardLogger(tmp)
>>> tbl.log_hyperparams({"epochs": 5, "optimizer": "Adam"})
>>> tbl.log_metrics({"acc": 0.75})
>>> tbl.log_metrics({"acc": 0.9})
>>> tbl.finalize("success")
>>> shutil.rmtree(tmp)
after_save_checkpoint(checkpoint_callback)[소스]

Called after model checkpoint callback saves a new checkpoint.

매개변수

checkpoint_callback (ModelCheckpoint) – the model checkpoint callback instance

반환 형식

None

finalize(status)[소스]

Do any processing that is necessary to finalize an experiment.

매개변수

status (str) – Status that the experiment finished with (e.g. success, failed, aborted)

반환 형식

None

log_graph(model, input_array=None)[소스]

Record model graph.

매개변수
반환 형식

None

log_hyperparams(params, metrics=None)[소스]

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.

매개변수
반환 형식

None

save()[소스]

Save log data.

반환 형식

None

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 of None or an int.

반환 형식

str

property root_dir: str

Parent directory for all tensorboard checkpoint subdirectories.

If the experiment name parameter is an empty string, no experiment subdirectory is used and the checkpoint will be saved in “save_dir/version”

반환 형식

str

property save_dir: str

Gets the save directory where the TensorBoard experiments are saved.

반환 형식

str

반환

The local path to the save directory where the TensorBoard experiments are saved.


© Copyright Copyright (c) 2018-2023, Lightning AI et al...

Built with Sphinx using a theme provided by Read the Docs.