def compute_anomaly_map(
        self,
        patch_scores: torch.Tensor,
        image_size: tuple[int, int] | torch.Size | None = None,
    ) -> torch.Tensor:
        """Compute pixel-level anomaly heatmap from patch scores.

        Args:
            patch_scores (torch.Tensor): Patch-level anomaly scores with shape
                ``(B, 1, H, W)``
            image_size (tuple[int, int] | torch.Size | None, optional): Target
                size ``(H, W)`` to upsample anomaly map. If ``None``, keeps
                original size. Defaults to ``None``.

        Returns:
            torch.Tensor: Pixel-level anomaly scores after upsampling and
                smoothing, with shape ``(B, 1, H, W)``
        """
        if image_size is None:
            anomaly_map = patch_scores
        else:
            anomaly_map = F.interpolate(patch_scores, size=(image_size[0], image_size[1]))
        return self.blur(anomaly_map)
Compute pixel-level anomaly heatmap from patch scores.

        Args:
            patch_scores (torch.Tensor): Patch-level anomaly scores with shape
                ``(B, 1, H, W)``
            image_size (tuple[int, int] | torch.Size | None, optional): Target
                size ``(H, W)`` to upsample anomaly map. If ``None``, keeps
                original size. Defaults to ``None``.

        Returns:
            torch.Tensor: Pixel-level anomaly scores after upsampling and
                smoothing, with shape ``(B, 1, H, W)``
        
src/anomalib/models/image/patchcore/anomaly_map.py