decode_jpeg¶
- torchvision.io.decode_jpeg(input: Union[Tensor, list[torch.Tensor]], mode: ImageReadMode = ImageReadMode.UNCHANGED, device: Union[str, device] = 'cpu', apply_exif_orientation: bool = False) Union[Tensor, list[torch.Tensor]][source]¶
[DEPRECATED] Use TorchCodec instead.
Decode JPEG image(s) into 3D RGB or grayscale Tensor(s), on CPU or CUDA.
Warning
The image decoding and encoding capabilities of TorchVision are deprecated since torchvision 0.29 and will be removed in a future release. They are superseded by the more complete decoders and encoders of TorchCodec (from torchcodec 0.16). Please see this migration guide on how to migrate your code.
The values of the output tensor are uint8 between 0 and 255.
Note
When using a CUDA device, passing a list of tensors is more efficient than repeated individual calls to
decode_jpeg. When using CPU the performance is equivalent. The CUDA version of this function has explicitly been designed with thread-safety in mind. This function does not return partial results in case of an error.- Parameters:
input (Tensor[1] or list[Tensor[1]]) – a (list of) one dimensional uint8 tensor(s) containing the raw bytes of the JPEG image. The tensor(s) must be on CPU, regardless of the
deviceparameter.mode (str or ImageReadMode) – The mode to convert the image to, e.g. “RGB”. Default is “UNCHANGED”. See
ImageReadModefor 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.
Warning
The device parameter is in Beta stage, and backward compatibility is not guaranteed.
apply_exif_orientation (bool) – apply EXIF orientation transformation to the output tensor. Default: False. Only implemented for JPEG format on CPU.
- Returns:
The values of the output tensor(s) are uint8 between 0 and 255.
output.devicewill be set to the specifieddevice- Return type:
output (Tensor[image_channels, image_height, image_width] or list[Tensor[image_channels, image_height, image_width]])