decode_jpeg Tensor, mode: ImageReadMode = ImageReadMode.UNCHANGED, device: str = 'cpu', apply_exif_orientation: bool = False) 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.

  • 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. The supported modes are: ImageReadMode.UNCHANGED, ImageReadMode.GRAY and ImageReadMode.RGB 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


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


    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".

  • apply_exif_orientation (bool) – apply EXIF orientation transformation to the output tensor. Default: False. Only implemented for JPEG format on CPU.


output (Tensor[image_channels, image_height, image_width])


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources