:py:mod:`anomalib.models.padim.anomaly_map` =========================================== .. py:module:: anomalib.models.padim.anomaly_map .. autoapi-nested-parse:: Anomaly Map Generator for the PaDiM model implementation. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: anomalib.models.padim.anomaly_map.AnomalyMapGenerator .. py:class:: AnomalyMapGenerator(image_size: Union[omegaconf.ListConfig, Tuple], sigma: int = 4) Generate Anomaly Heatmap. :param image_size: Size of the input image. The anomaly map is upsampled to this dimension. :type image_size: Union[ListConfig, Tuple] :param sigma: Standard deviation for Gaussian Kernel. Defaults to 4. :type sigma: int, optional .. py:method:: compute_distance(embedding: torch.Tensor, stats: List[torch.Tensor]) -> torch.Tensor :staticmethod: Compute anomaly score to the patch in position(i,j) of a test image. Ref: Equation (2), Section III-C of the paper. :param embedding: Embedding Vector :type embedding: Tensor :param stats: Mean and Covariance Matrix of the multivariate Gaussian distribution :type stats: List[Tensor] :returns: Anomaly score of a test image via mahalanobis distance. .. py:method:: up_sample(self, distance: torch.Tensor) -> torch.Tensor Up sample anomaly score to match the input image size. :param distance: Anomaly score computed via the mahalanobis distance. :type distance: Tensor :returns: Resized distance matrix matching the input image size .. py:method:: smooth_anomaly_map(self, anomaly_map: torch.Tensor) -> torch.Tensor Apply gaussian smoothing to the anomaly map. :param anomaly_map: Anomaly score for the test image(s). :type anomaly_map: Tensor :returns: Filtered anomaly scores .. py:method:: compute_anomaly_map(self, embedding: torch.Tensor, mean: torch.Tensor, inv_covariance: torch.Tensor) -> torch.Tensor Compute anomaly score. Scores are calculated based on embedding vector, mean and inv_covariance of the multivariate gaussian distribution. :param embedding: Embedding vector extracted from the test set. :type embedding: Tensor :param mean: Mean of the multivariate gaussian distribution :type mean: Tensor :param inv_covariance: Inverse Covariance matrix of the multivariate gaussian distribution. :type inv_covariance: Tensor :returns: Output anomaly score. .. py:method:: __call__(self, **kwds) Returns anomaly_map. Expects `embedding`, `mean` and `covariance` keywords to be passed explicitly. Example: >>> anomaly_map_generator = AnomalyMapGenerator(image_size=input_size) >>> output = anomaly_map_generator(embedding=embedding, mean=mean, covariance=covariance) :raises ValueError: `embedding`. `mean` or `covariance` keys are not found :returns: anomaly map :rtype: torch.Tensor