encode_jpeg¶
- torchvision.io.encode_jpeg(input: Union[Tensor, list[torch.Tensor]], quality: int = 75) Union[Tensor, list[torch.Tensor]][source]¶
[DEPRECATED] Use TorchCodec instead.
Encode RGB tensor(s) into raw encoded jpeg bytes, 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.
Note
Passing a list of CUDA tensors is more efficient than repeated individual calls to
encode_jpeg. For CPU tensors the performance is equivalent.- Parameters:
input (Tensor[channels, image_height, image_width] or List[Tensor[channels, image_height, image_width]]) – (list of) uint8 image tensor(s) of
cchannels, wherecmust be 1 or 3quality (int) – Quality of the resulting JPEG file(s). Must be a number between 1 and 100. Default: 75
- Returns:
A (list of) one dimensional uint8 tensor(s) that contain the raw bytes of the JPEG file.
- Return type:
output (Tensor[1] or list[Tensor[1]])