:py:mod:`anomalib.models.components.base.anomaly_module` ======================================================== .. py:module:: anomalib.models.components.base.anomaly_module .. autoapi-nested-parse:: Base Anomaly Module for Training Task. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: anomalib.models.components.base.anomaly_module.AnomalyModule Attributes ~~~~~~~~~~ .. autoapisummary:: anomalib.models.components.base.anomaly_module.logger .. py:data:: logger .. py:class:: AnomalyModule Bases: :py:obj:`pytorch_lightning.LightningModule`, :py:obj:`abc.ABC` AnomalyModule to train, validate, predict and test images. Acts as a base class for all the Anomaly Modules in the library. .. py:method:: forward(batch) Forward-pass input tensor to the module. :param batch: Input Tensor :type batch: Tensor :returns: Output tensor from the model. :rtype: Tensor .. py:method:: validation_step(batch, batch_idx) -> dict :abstractmethod: To be implemented in the subclasses. .. py:method:: predict_step(batch: Any, batch_idx: int, _dataloader_idx: Optional[int] = None) -> Any Step function called during :meth:`~pytorch_lightning.trainer.trainer.Trainer.predict`. By default, it calls :meth:`~pytorch_lightning.core.lightning.LightningModule.forward`. Override to add any processing logic. :param batch: Current batch :type batch: Tensor :param batch_idx: Index of current batch :type batch_idx: int :param _dataloader_idx: Index of the current dataloader :type _dataloader_idx: int :returns: Predicted output .. py:method:: test_step(batch, _) Calls validation_step for anomaly map/score calculation. :param batch: Input batch :type batch: Tensor :param _: Index of the batch. :returns: Dictionary containing images, features, true labels and masks. These are required in `validation_epoch_end` for feature concatenation. .. py:method:: validation_step_end(val_step_outputs) Called at the end of each validation step. .. py:method:: test_step_end(test_step_outputs) Called at the end of each test step. .. py:method:: validation_epoch_end(outputs) Compute threshold and performance metrics. :param outputs: Batch of outputs from the validation step .. py:method:: test_epoch_end(outputs) Compute and save anomaly scores of the test set. :param outputs: Batch of outputs from the validation step .. py:method:: _compute_adaptive_threshold(outputs) .. py:method:: _collect_outputs(image_metric, pixel_metric, outputs) .. py:method:: _post_process(outputs) Compute labels based on model predictions. .. py:method:: _outputs_to_cpu(output) .. py:method:: _log_metrics() Log computed performance metrics.