import torch


def rgb_to_grayscale(image: torch.Tensor) -> torch.Tensor:
    """
        Convert a RGB image to grayscale version of image.
        The image data is assumed to be in the range of (0, 1).
    """
    if not isinstance(image, torch.Tensor):
        raise TypeError("Input type is not a torch.Tensor. Got {}".format(
            type(image)))

    if len(image.shape) < 3 or image.shape[-3] != 3:
        raise ValueError("Input size must have a shape of (*, 3, H, W). Got {}"
                         .format(image.shape))

    r = image[..., 0:1, :, :]
    g = image[..., 1:2, :, :]
    b = image[..., 2:3, :, :]

    gray = 0.299 * r + 0.587 * g + 0.114 * b
    return gray