:py:mod:`anomalib.models.reverse_distillation` ============================================== .. py:module:: anomalib.models.reverse_distillation .. autoapi-nested-parse:: Reverse Distillation Model. Subpackages ----------- .. toctree:: :titlesonly: :maxdepth: 3 components/index.rst Submodules ---------- .. toctree:: :titlesonly: :maxdepth: 1 anomaly_map/index.rst lightning_model/index.rst loss/index.rst torch_model/index.rst Package Contents ---------------- Classes ~~~~~~~ .. autoapisummary:: anomalib.models.reverse_distillation.ReverseDistillation anomalib.models.reverse_distillation.ReverseDistillationLightning .. py:class:: ReverseDistillation(input_size: Tuple[int, int], backbone: str, layers: List[str], anomaly_map_mode: str, lr: float, beta1: float, beta2: float, pre_trained: bool = True) Bases: :py:obj:`anomalib.models.components.AnomalyModule` PL Lightning Module for Reverse Distillation Algorithm. :param input_size: Size of model input :type input_size: Tuple[int, int] :param backbone: Backbone of CNN network :type backbone: str :param layers: Layers to extract features from the backbone CNN :type layers: List[str] :param pre_trained: Boolean to check whether to use a pre_trained backbone. :type pre_trained: bool, optional .. py:method:: configure_optimizers() Configures optimizers for decoder and bottleneck. .. note:: This method is used for the existing CLI. When PL CLI is introduced, configure optimizers method will be deprecated, and optimizers will be configured from either config.yaml file or from CLI. :returns: Adam optimizer for each decoder :rtype: Optimizer .. py:method:: training_step(batch, _) -> Dict[str, torch.Tensor] Training Step of Reverse Distillation Model. Features are extracted from three layers of the Encoder model. These are passed to the bottleneck layer that are passed to the decoder network. The loss is then calculated based on the cosine similarity between the encoder and decoder features. :param batch: Input batch :type batch: Tensor :param _: Index of the batch. :returns: Feature Map .. py:method:: validation_step(batch, _) Validation Step of Reverse Distillation Model. Similar to the training step, encoder/decoder features are extracted from the CNN for each batch, and anomaly map is computed. :param batch: Input batch :type batch: Tensor :param _: Index of the batch. :returns: Dictionary containing images, anomaly maps, true labels and masks. These are required in `validation_epoch_end` for feature concatenation. .. py:class:: ReverseDistillationLightning(hparams: Union[omegaconf.DictConfig, omegaconf.ListConfig]) Bases: :py:obj:`ReverseDistillation` PL Lightning Module for Reverse Distillation Algorithm. :param hparams: Model parameters :type hparams: Union[DictConfig, ListConfig] .. py:method:: configure_callbacks() Configure model-specific callbacks. .. note:: This method is used for the existing CLI. When PL CLI is introduced, configure callback method will be deprecated, and callbacks will be configured from either config.yaml file or from CLI.