Shortcuts

CSVLogger

class lightning_fabric.loggers.CSVLogger(root_dir, name='lightning_logs', version=None, prefix='', flush_logs_every_n_steps=100)[source]

Bases: lightning_fabric.loggers.logger.Logger

Log to the local file system in CSV format.

Logs are saved to os.path.join(root_dir, name, version).

Parameters:
  • root_dir (Union[str, Path]) – The root directory in which all your experiments with different names and versions will be stored.

  • name (str) – Experiment name. Defaults to 'lightning_logs'.

  • 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.

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

  • flush_logs_every_n_steps (int) – How often to flush logs to disk (defaults to every 100 steps).

Example:

from lightning.fabric.loggers import CSVLogger

logger = CSVLogger("path/to/logs/root", name="my_model")
logger.log_metrics({"loss": 0.235, "acc": 0.75})
logger.finalize("success")
finalize(status)[source]

Do any processing that is necessary to finalize an experiment.

Parameters:

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

Return type:

None

log_hyperparams(params)[source]

Record hyperparameters.

Parameters:
  • params (Union[Dict[str, Any], Namespace]) – Namespace or Dict containing the hyperparameters

  • args – Optional positional arguments, depends on the specific logger being used

  • kwargs – Optional keyword arguments, depends on the specific logger being used

Return type:

None

log_metrics(metrics, step=None)[source]

Records metrics. This method logs metrics as soon as it received them.

Parameters:
  • metrics (Dict[str, Union[Tensor, float]]) – Dictionary with metric names as keys and measured quantities as values

  • step (Optional[int]) – Step number at which the metrics should be recorded

Return type:

None

save()[source]

Save log data.

Return type:

None

property experiment: lightning_fabric.loggers.csv_logs._ExperimentWriter

Actual ExperimentWriter object. To use ExperimentWriter features anywhere in your code, do the following.

Example:

self.logger.experiment.some_experiment_writer_function()
property log_dir: str

The log directory for this run.

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.

property name: str

Gets the name of the experiment.

Returns:

The name of the experiment.

property root_dir: str

Gets the save directory where the versioned CSV experiments are saved.

property version: Union[int, str]

Gets the version of the experiment.

Returns:

The version of the experiment if it is specified, else the next version.


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

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