encode_jpeg Union[Tensor, List[Tensor]], quality: int = 75) Union[Tensor, List[Tensor]][source]

Takes a (list of) input tensor(s) in CHW layout and returns a (list of) buffer(s) with the contents of the corresponding JPEG file(s).


Passing a list of CUDA tensors is more efficient than repeated individual calls to encode_jpeg. For CPU tensors the performance is equivalent.

  • input (Tensor[channels, image_height, image_width] or List[Tensor[channels, image_height, image_width]]) – (list of) uint8 image tensor(s) of c channels, where c must be 1 or 3

  • quality (int) – Quality of the resulting JPEG file(s). Must be a number between 1 and 100. Default: 75


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]])


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