(pic)
return img
Convert a ``PIL Image`` to a tensor of the same type.
    This function does not support torchscript.

    See :class:`~torchvision.transforms.PILToTensor` for more details.

    Args:
        pic (PIL Image): Image to be converted to tensor.

    Returns:
        Tensor: Converted image.
Convert a ``PIL Image`` to a tensor of the same type.
    This function does not support torchscript.
Convert a PIL Image to a tensor of the same type . This function does not support torchscript .
def pil_to_tensor(pic):
    """Convert a ``PIL Image`` to a tensor of the same type.
    This function does not support torchscript.

    See :class:`~torchvision.transforms.PILToTensor` for more details.

    Args:
        pic (PIL Image): Image to be converted to tensor.

    Returns:
        Tensor: Converted image.
    """
    if not F_pil._is_pil_image(pic):
        raise TypeError('pic should be PIL Image. Got {}'.format(type(pic)))

    if accimage is not None and isinstance(pic, accimage.Image):
        # accimage format is always uint8 internally, so always return uint8 here
        nppic = np.zeros([pic.channels, pic.height, pic.width], dtype=np.uint8)
        pic.copyto(nppic)
        return torch.as_tensor(nppic)

    # handle PIL Image
    img = torch.as_tensor(np.asarray(pic))
    img = img.view(pic.size[1], pic.size[0], len(pic.getbands()))
    # put it from HWC to CHW format
    img = img.permute((2, 0, 1))
    return img
def pil_to_tensor ( pic ) : if not F_pil . _is_pil_image ( pic ) : raise TypeError ( 'pic should be PIL Image. Got {}' . format ( type ( pic ) ) ) if accimage is not None and isinstance ( pic , accimage . Image ) : # accimage format is always uint8 internally, so always return uint8 here nppic = np . zeros ( [ pic . channels , pic . height , pic . width ] , dtype = np . uint8 ) pic . copyto ( nppic ) return torch . as_tensor ( nppic ) # handle PIL Image img = torch . as_tensor ( np . asarray ( pic ) ) img = img . view ( pic . size [ 1 ] , pic . size [ 0 ] , len ( pic . getbands ( ) ) ) # put it from HWC to CHW format img = img . permute ( ( 2 , 0 , 1 ) ) return img