def validate_gt_mask(mask: torch.Tensor | None) -> Mask | None:
        """Validate ground truth mask.

        Validates and converts ground truth masks to boolean Mask objects.

        Args:
            mask (torch.Tensor | None): Input mask tensor with shape either:
                - ``[H, W]`` for single frame
                - ``[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 boolean mask or ``None``.

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

        Examples:
            >>> import torch
            >>> from anomalib.data.validators import VideoValidator
            >>> # Multi-frame mask
            >>> mask = torch.randint(0, 2, (10, 1, 224, 224))
            >>> validated = VideoValidator.validate_gt_mask(mask)
            >>> isinstance(validated, Mask)
            True
            >>> validated.shape
            torch.Size([10, 224, 224])
        """
        if mask is None:
            return None
        if not isinstance(mask, torch.Tensor):
            msg = f"Mask must be a torch.Tensor, got {type(mask)}."
            raise TypeError(msg)
        if mask.ndim not in {2, 3, 4}:
            msg = f"Mask must have shape [H, W], [T, H, W] or [T, 1, H, W] got shape {mask.shape}."
            raise ValueError(msg)
        if mask.ndim == 4:
            if mask.shape[1] != 1:
                msg = f"Mask must have 1 channel, got {mask.shape[1]}."
                raise ValueError(msg)
            mask = mask.squeeze(1)
        return Mask(mask, dtype=torch.bool)
Validate ground truth mask.

        Validates and converts ground truth masks to boolean Mask objects.

        Args:
            mask (torch.Tensor | None): Input mask tensor with shape either:
                - ``[H, W]`` for single frame
                - ``[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 boolean mask or ``None``.

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

        Examples:
            >>> import torch
            >>> from anomalib.data.validators import VideoValidator
            >>> # Multi-frame mask
            >>> mask = torch.randint(0, 2, (10, 1, 224, 224))
            >>> validated = VideoValidator.validate_gt_mask(mask)
            >>> isinstance(validated, Mask)
            True
            >>> validated.shape
            torch.Size([10, 224, 224])
        
src/anomalib/data/validators/torch/video.py