def validate_anomaly_map(anomaly_map: torch.Tensor | None) -> Mask | None:
        """Validate the anomaly map.

        This method validates and normalizes input anomaly maps. It handles:
            - Single channel maps only
            - [H, W] and [1, H, W] formats
            - Type conversion to float32
            - None inputs return None

        Args:
            anomaly_map (``torch.Tensor`` | ``None``): Input anomaly map.

        Returns:
            ``Mask`` | ``None``: Validated anomaly map as a torchvision Mask object,
                or None.

        Raises:
            TypeError: If ``anomaly_map`` is not a torch.Tensor.
            ValueError: If ``anomaly_map`` dimensions or channels are invalid.

        Example:
            >>> import torch
            >>> from anomalib.data.validators import ImageValidator
            >>> anomaly_map = torch.rand(1, 224, 224)  # [1, H, W]
            >>> validated_map = ImageValidator.validate_anomaly_map(anomaly_map)
            >>> isinstance(validated_map, Mask)
            True
            >>> validated_map.shape
            torch.Size([224, 224])
        """
        if anomaly_map is None:
            return None
        if not isinstance(anomaly_map, torch.Tensor):
            msg = f"Anomaly map must be a torch.Tensor, got {type(anomaly_map)}."
            raise TypeError(msg)
        if anomaly_map.ndim not in {2, 3}:
            msg = f"Anomaly map must have shape [H, W] or [1, H, W], got shape {anomaly_map.shape}."
            raise ValueError(msg)
        if anomaly_map.ndim == 3:
            if anomaly_map.shape[0] != 1:
                msg = f"Anomaly map with 3 dimensions must have 1 channel, got {anomaly_map.shape[0]}."
                raise ValueError(msg)
            anomaly_map = anomaly_map.squeeze(0)

        return Mask(anomaly_map, dtype=torch.float32)
Validate the anomaly map.

        This method validates and normalizes input anomaly maps. It handles:
            - Single channel maps only
            - [H, W] and [1, H, W] formats
            - Type conversion to float32
            - None inputs return None

        Args:
            anomaly_map (``torch.Tensor`` | ``None``): Input anomaly map.

        Returns:
            ``Mask`` | ``None``: Validated anomaly map as a torchvision Mask object,
                or None.

        Raises:
            TypeError: If ``anomaly_map`` is not a torch.Tensor.
            ValueError: If ``anomaly_map`` dimensions or channels are invalid.

        Example:
            >>> import torch
            >>> from anomalib.data.validators import ImageValidator
            >>> anomaly_map = torch.rand(1, 224, 224)  # [1, H, W]
            >>> validated_map = ImageValidator.validate_anomaly_map(anomaly_map)
            >>> isinstance(validated_map, Mask)
            True
            >>> validated_map.shape
            torch.Size([224, 224])
        
src/anomalib/data/validators/torch/image.py