:py:mod:`anomalib.utils.loggers`
================================
.. py:module:: anomalib.utils.loggers
.. autoapi-nested-parse::
Load PyTorch Lightning Loggers.
Submodules
----------
.. toctree::
:titlesonly:
:maxdepth: 1
base/index.rst
tensorboard/index.rst
wandb/index.rst
Package Contents
----------------
Classes
~~~~~~~
.. autoapisummary::
anomalib.utils.loggers.AnomalibTensorBoardLogger
anomalib.utils.loggers.AnomalibWandbLogger
Functions
~~~~~~~~~
.. autoapisummary::
anomalib.utils.loggers.configure_logger
anomalib.utils.loggers.get_experiment_logger
.. py:class:: AnomalibTensorBoardLogger(save_dir: str, name: Optional[str] = 'default', version: Optional[Union[int, str]] = None, log_graph: bool = False, default_hp_metric: bool = True, prefix: str = '', **kwargs)
Bases: :py:obj:`anomalib.utils.loggers.base.ImageLoggerBase`, :py:obj:`pytorch_lightning.loggers.tensorboard.TensorBoardLogger`
Logger for tensorboard.
Adds interface for `add_image` in the logger rather than calling the experiment object.
.. note:: Same as the Tensorboard Logger provided by PyTorch Lightning and the doc string is reproduced below.
Logs are saved to
``os.path.join(save_dir, name, version)``. This is the default logger in Lightning, it comes
preinstalled.
.. rubric:: Example
>>> from pytorch_lightning import Trainer
>>> from anomalib.utils.loggers import AnomalibTensorBoardLogger
>>> logger = AnomalibTensorBoardLogger("tb_logs", name="my_model")
>>> trainer = Trainer(logger=logger)
:param save_dir: Save directory
:type save_dir: str
:param name: Experiment name. Defaults to ``'default'``. If it is the empty string then no
per-experiment subdirectory is used.
:type name: Optional, str
:param version: 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.
:type version: Optional, int, str
:param log_graph: Adds the computational graph to tensorboard. This requires that
the user has defined the `self.example_input_array` attribute in their
model.
:type log_graph: bool
:param default_hp_metric: 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).
:type default_hp_metric: bool
:param prefix: A string to put at the beginning of metric keys.
:type prefix: str
:param \*\*kwargs: Additional arguments like `comment`, `filename_suffix`, etc. used by
:class:`SummaryWriter` can be passed as keyword arguments in this logger.
.. py:method:: add_image(self, image: Union[numpy.ndarray, matplotlib.figure.Figure], name: Optional[str] = None, **kwargs: Any)
Interface to add image to tensorboard logger.
:param image: Image to log
:type image: Union[np.ndarray, Figure]
:param name: The tag of the image
:type name: Optional[str]
:param kwargs: Accepts only `global_step` (int). The step at which to log the image.
.. py:class:: AnomalibWandbLogger(name: Optional[str] = None, save_dir: Optional[str] = None, offline: Optional[bool] = False, id: Optional[str] = None, anonymous: Optional[bool] = None, version: Optional[str] = None, project: Optional[str] = None, log_model: Union[str, bool] = False, experiment=None, prefix: Optional[str] = '', **kwargs)
Bases: :py:obj:`anomalib.utils.loggers.base.ImageLoggerBase`, :py:obj:`pytorch_lightning.loggers.wandb.WandbLogger`
Logger for wandb.
Adds interface for `add_image` in the logger rather than calling the experiment object.
.. note:: Same as the wandb Logger provided by PyTorch Lightning and the doc string is reproduced below.
Log using `Weights and Biases `_.
Install it with pip:
.. code-block:: bash
$ pip install wandb
:param name: Display name for the run.
:param save_dir: Path where data is saved (wandb dir by default).
:param offline: Run offline (data can be streamed later to wandb servers).
:param id: Sets the version, mainly used to resume a previous run.
:param version: Same as id.
:param anonymous: Enables or explicitly disables anonymous logging.
:param project: The name of the project to which this run will belong.
:param log_model: Save checkpoints in wandb dir to upload on W&B servers.
:param prefix: A string to put at the beginning of metric keys.
:param experiment: WandB experiment object. Automatically set when creating a run.
:param \*\*kwargs: Arguments passed to :func:`wandb.init` like `entity`, `group`, `tags`, etc.
:raises ImportError: If required WandB package is not installed on the device.
:raises MisconfigurationException: If both ``log_model`` and ``offline``is set to ``True``.
.. rubric:: Example
>>> from anomalib.utils.loggers import AnomalibWandbLogger
>>> from pytorch_lightning import Trainer
>>> wandb_logger = AnomalibWandbLogger()
>>> trainer = Trainer(logger=wandb_logger)
Note: When logging manually through `wandb.log` or `trainer.logger.experiment.log`,
make sure to use `commit=False` so the logging step does not increase.
.. seealso::
- `Tutorial `__
on how to use W&B with PyTorch Lightning
- `W&B Documentation `__
.. py:method:: add_image(self, image: Union[numpy.ndarray, matplotlib.figure.Figure], name: Optional[str] = None, **kwargs: Any)
Interface to add image to wandb logger.
:param image: Image to log
:type image: Union[np.ndarray, Figure]
:param name: The tag of the image
:type name: Optional[str]
.. py:method:: save(self) -> None
Upload images to wandb server.
.. note:: There is a limit on the number of images that can be logged together to the `wandb` server.
.. py:function:: configure_logger(level: Union[int, str] = logging.INFO)
Get console logger by name.
:param level: Logger Level. Defaults to logging.INFO.
:type level: Union[int, str], optional
:returns: The expected logger.
:rtype: Logger
.. py:function:: get_experiment_logger(config: Union[omegaconf.dictconfig.DictConfig, omegaconf.listconfig.ListConfig]) -> Union[pytorch_lightning.loggers.LightningLoggerBase, Iterable[pytorch_lightning.loggers.LightningLoggerBase], bool]
Return a logger based on the choice of logger in the config file.
:param config: config.yaml file for the corresponding anomalib model.
:type config: DictConfig
:raises ValueError: for any logger types apart from false and tensorboard
:returns: Logger
:rtype: Union[LightningLoggerBase, Iterable[LightningLoggerBase], bool]