Shortcuts

decode_jpeg

torchvision.io.decode_jpeg(input: torch.Tensor, mode: torchvision.io.image.ImageReadMode = <ImageReadMode.UNCHANGED: 0>, device: str = 'cpu')torch.Tensor[source]

Decodes a JPEG image into a 3 dimensional RGB or grayscale Tensor. Optionally converts the image to the desired format. The values of the output tensor are uint8 between 0 and 255.

Parameters
  • input (Tensor[1]) – a one dimensional uint8 tensor containing the raw bytes of the JPEG image. This tensor must be on CPU, regardless of the device parameter.

  • mode (ImageReadMode) – the read mode used for optionally converting the image. Default: ImageReadMode.UNCHANGED. See ImageReadMode class for more information on various available modes.

  • device (str or torch.device) –

    The device on which the decoded image will be stored. If a cuda device is specified, the image will be decoded with nvjpeg. This is only supported for CUDA version >= 10.1

    Warning

    The device parameter is in Beta stage, and backward compatibility is not guaranteed.

    Warning

    There is a memory leak in the nvjpeg library for CUDA versions < 11.6. Make sure to rely on CUDA 11.6 or above before using device="cuda".

Returns

output (Tensor[image_channels, image_height, image_width])

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