def validate_gt_mask(mask: torch.Tensor | None) -> Mask | None:
        """Validate the ground truth masks for a batch.

        Validates that the input ground truth masks have the correct shape and format.
        Converts masks to boolean type.

        Args:
            mask (torch.Tensor | None): Input ground truth masks. Should be one of:
                - Shape ``(H,W)`` for single mask
                - Shape ``(N,H,W)`` for batch of masks
                - Shape ``(N,1,H,W)`` for batch with channel dimension

        Returns:
            Mask | None: Validated ground truth masks as boolean tensor.

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

        Examples:
            >>> import torch
            >>> from anomalib.data.validators import VideoBatchValidator
            >>> # Create 10 frame masks
            >>> gt_masks = torch.rand(10, 224, 224) > 0.5
            >>> validated_masks = VideoBatchValidator.validate_gt_mask(gt_masks)
            >>> print(validated_masks.shape)
            torch.Size([10, 224, 224])
            >>> # Create 4 single-frame masks
            >>> single_frame_masks = torch.rand(4, 456, 256) > 0.5
            >>> validated_single_frame = VideoBatchValidator.validate_gt_mask(
            ...     single_frame_masks
            ... )
            >>> print(validated_single_frame.shape)
            torch.Size([4, 456, 256])
        """
        if mask is None:
            return None
        if not isinstance(mask, torch.Tensor):
            msg = f"Ground truth mask must be a torch.Tensor, got {type(mask)}."
            raise TypeError(msg)
        if mask.ndim not in {2, 3, 4}:
            msg = f"Ground truth mask must have shape [H, W] or [N, H, W] or [N, 1, H, W] got shape {mask.shape}."
            raise ValueError(msg)
        if mask.ndim == 2:
            mask = mask.unsqueeze(0)
        if mask.ndim == 4:
            if mask.shape[1] != 1:
                msg = f"Ground truth mask must have 1 channel, got {mask.shape[1]}."
                raise ValueError(msg)
            mask = mask.squeeze(1)
        return Mask(mask, dtype=torch.bool)
Validate the ground truth masks for a batch.

        Validates that the input ground truth masks have the correct shape and format.
        Converts masks to boolean type.

        Args:
            mask (torch.Tensor | None): Input ground truth masks. Should be one of:
                - Shape ``(H,W)`` for single mask
                - Shape ``(N,H,W)`` for batch of masks
                - Shape ``(N,1,H,W)`` for batch with channel dimension

        Returns:
            Mask | None: Validated ground truth masks as boolean tensor.

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

        Examples:
            >>> import torch
            >>> from anomalib.data.validators import VideoBatchValidator
            >>> # Create 10 frame masks
            >>> gt_masks = torch.rand(10, 224, 224) > 0.5
            >>> validated_masks = VideoBatchValidator.validate_gt_mask(gt_masks)
            >>> print(validated_masks.shape)
            torch.Size([10, 224, 224])
            >>> # Create 4 single-frame masks
            >>> single_frame_masks = torch.rand(4, 456, 256) > 0.5
            >>> validated_single_frame = VideoBatchValidator.validate_gt_mask(
            ...     single_frame_masks
            ... )
            >>> print(validated_single_frame.shape)
            torch.Size([4, 456, 256])
        
src/anomalib/data/validators/torch/video.py