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

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

        Args:
            mask (``torch.Tensor`` | ``None``): Input ground truth mask.

        Returns:
            ``Mask`` | ``None``: Validated ground truth mask as a torchvision Mask
                object, or None.

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

        Example:
            >>> import torch
            >>> from anomalib.data.validators import ImageValidator
            >>> mask = torch.randint(0, 2, (1, 224, 224))  # [1, H, W]
            >>> validated_mask = ImageValidator.validate_gt_mask(mask)
            >>> isinstance(validated_mask, Mask)
            True
            >>> validated_mask.shape
            torch.Size([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}:
            msg = f"Mask must have shape [H, W] or [1, H, W] got shape {mask.shape}."
            raise ValueError(msg)
        if mask.ndim == 3:
            if mask.shape[0] != 1:
                msg = f"Mask must have 1 channel, got {mask.shape[0]}."
                raise ValueError(msg)
            mask = mask.squeeze(0)
        return Mask(mask, dtype=torch.bool)
Validate the ground truth mask.

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

        Args:
            mask (``torch.Tensor`` | ``None``): Input ground truth mask.

        Returns:
            ``Mask`` | ``None``: Validated ground truth mask as a torchvision Mask
                object, or None.

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

        Example:
            >>> import torch
            >>> from anomalib.data.validators import ImageValidator
            >>> mask = torch.randint(0, 2, (1, 224, 224))  # [1, H, W]
            >>> validated_mask = ImageValidator.validate_gt_mask(mask)
            >>> isinstance(validated_mask, Mask)
            True
            >>> validated_mask.shape
            torch.Size([224, 224])
        
src/anomalib/data/validators/torch/image.py