Table of Contents
Shortcuts

# decode_jpeg

torchvision.io.decode_jpeg(input: Tensor, mode: ImageReadMode = ImageReadMode.UNCHANGED, device: str = 'cpu') → Tensor

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

      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

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.