decode_jpeg¶
- paddle.vision.ops. 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.
- Parameters
-
x (Tensor) – A one dimensional uint8 tensor containing the raw bytes of the JPEG image.
mode (str, optional) – 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.
- Returns
-
A decoded image tensor with shape (image_channels, image_height, image_width)
- Return type
-
Tensor
Examples
>>> >>> import cv2 >>> import numpy as np >>> import paddle >>> paddle.device.set_device('gpu') >>> fake_img = (np.random.random( ... (400, 300, 3)) * 255).astype('uint8') >>> cv2.imwrite('fake.jpg', fake_img) >>> img_bytes = paddle.vision.ops.read_file('fake.jpg') >>> img = paddle.vision.ops.decode_jpeg(img_bytes) >>> print(img.shape) [3, 400, 300]