decode_jpeg decode_jpeg ( x, mode='unchanged', name=None ) [source]

Decodes a JPEG image into a 3 dimensional RGB Tensor or 1 dimensional Gray Tensor. Optionally converts the image to the desired format. The values of the output tensor are uint8 between 0 and 255.

  • x (Tensor) – A one dimensional uint8 tensor containing the raw bytes of the JPEG image.

  • mode (str) – The read mode used for optionally converting the image. Default: ‘unchanged’.

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.


A decoded image tensor with shape (imge_channels, image_height, image_width)

Return type



# required: gpu
import cv2
import numpy as np
import paddle

fake_img = (np.random.random(
            (400, 300, 3)) * 255).astype('uint8')

cv2.imwrite('fake.jpg', fake_img)

img_bytes ='fake.jpg')
img =