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

        Validates and converts anomaly maps to float32 Mask objects.

        Args:
            anomaly_map (torch.Tensor | None): Input anomaly map tensor with shape either:
                - ``[T, H, W]`` for multiple frames
                - ``[T, 1, H, W]`` for multiple frames with channel dimension
                where ``H`` is height, ``W`` width, and ``T`` number of frames.

        Returns:
            Mask | None: Validated float32 mask or ``None``.

        Raises:
            TypeError: If ``anomaly_map`` is not a ``torch.Tensor`` or ``None``.
            ValueError: If anomaly map shape is invalid.

        Examples:
            >>> import torch
            >>> from anomalib.data.validators import VideoValidator
            >>> # Multi-frame anomaly map
            >>> amap = torch.rand(10, 1, 224, 224)
            >>> validated = VideoValidator.validate_anomaly_map(amap)
            >>> isinstance(validated, Mask)
            True
            >>> validated.shape
            torch.Size([10, 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 {3, 4}:
            msg = f"Anomaly map must have shape [T, H, W] or [T, 1, H, W], got shape {anomaly_map.shape}."
            raise ValueError(msg)
        if anomaly_map.ndim == 4:
            if anomaly_map.shape[1] != 1:
                msg = f"Anomaly map with 4 dimensions must have 1 channel, got {anomaly_map.shape[1]}."
                raise ValueError(msg)
            anomaly_map = anomaly_map.squeeze(1)

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

        Validates and converts anomaly maps to float32 Mask objects.

        Args:
            anomaly_map (torch.Tensor | None): Input anomaly map tensor with shape either:
                - ``[T, H, W]`` for multiple frames
                - ``[T, 1, H, W]`` for multiple frames with channel dimension
                where ``H`` is height, ``W`` width, and ``T`` number of frames.

        Returns:
            Mask | None: Validated float32 mask or ``None``.

        Raises:
            TypeError: If ``anomaly_map`` is not a ``torch.Tensor`` or ``None``.
            ValueError: If anomaly map shape is invalid.

        Examples:
            >>> import torch
            >>> from anomalib.data.validators import VideoValidator
            >>> # Multi-frame anomaly map
            >>> amap = torch.rand(10, 1, 224, 224)
            >>> validated = VideoValidator.validate_anomaly_map(amap)
            >>> isinstance(validated, Mask)
            True
            >>> validated.shape
            torch.Size([10, 224, 224])
        
src/anomalib/data/validators/torch/video.py