Shortcuts

PILToTensor

class torchvision.transforms.PILToTensor[source]

Convert a PIL Image to a tensor of the same type - this does not scale values.

This transform does not support torchscript.

Convert a PIL Image with H height, W width, and C channels to a Tensor of shape (C x H x W).

Example

>>> from PIL import Image
>>> import torchvision.transforms as T
>>> img = Image.new("RGB", (320, 240))  # size (W=320, H=240)
>>> tensor = T.PILToTensor()(img)
>>> print(tensor.shape)
torch.Size([3, 240, 320])

Examples using PILToTensor:

How to use CutMix and MixUp

How to use CutMix and MixUp

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