Shortcuts

torchvision.transforms.v2.functional.pil_to_tensor

torchvision.transforms.v2.functional.pil_to_tensor(pic: Any) Tensor[source]

Convert a PIL Image to a tensor of the same type. This function does not support torchscript.

See PILToTensor for more details.

Note

A deep copy of the underlying array is performed.

Parameters:

pic (PIL Image) – Image to be converted to tensor.

Returns:

Converted image.

Return type:

Tensor

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources