LoggerManager

class torch_ecg.components.LoggerManager(log_dir: str | bytes | PathLike | None = None, log_suffix: str | None = None)[source]

Bases: ReprMixin

Manager of loggers.

This class manages multiple loggers and provides a unified interface to log metrics and messages.

Parameters:
  • log_dir (path-like, optional) – The directory to save the log file.

  • log_suffix (str, optional) – The suffix of the log file.

close() None[source]

Close the loggers.

epoch_end(epoch: int) None[source]

Actions to be performed at the end of each epoch.

Parameters:

epoch (int) – The number of the epoch.

epoch_start(epoch: int) None[source]

Message logged at the start of each epoch.

Parameters:

epoch (int) – The number of the epoch.

extra_repr_keys() List[str][source]

Extra keys for __repr__() and __str__().

flush() None[source]

Flush the loggers.

classmethod from_config(config: Dict[str, Any]) LoggerManager[source]

Create a logger manager from a configuration.

Parameters:

config (dict) – The configuration of the logger manager.

Returns:

The instance of the created logger manager.

Return type:

LoggerManager

property log_dir: str

Directory to save the log file.

log_message(msg: str, level: int = 20) None[source]

Log a message.

Parameters:
  • msg (str) – The message to be logged.

  • level ({logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL}, optional) – The level of the message.

log_metrics(metrics: Dict[str, Real | Tensor], step: int | None = None, epoch: int | None = None, part: str = 'train') None[source]

Log metrics.

Parameters:
  • metrics (dict) – The metrics to be logged.

  • step (int, optional) – The number of (global) steps of training.

  • epoch (int, optional,) – The epoch number of training.

  • part (str, optional) – The part of the training data the metrics computed from, can be “train” or “val” or “test”, etc.

property log_suffix: str

Suffix of the log file.

property loggers: List[BaseLogger]

List of loggers.