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) – 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 (imge_channels, image_height, image_width)

Return type

Tensor

Examples

System Message: ERROR/3 (/usr/local/lib/python3.8/site-packages/paddle/vision/ops.py:docstring of paddle.vision.ops.decode_jpeg, line 21)

Error in “code-block” directive: maximum 1 argument(s) allowed, 5 supplied.

.. code-block:: python
    import cv2
    import paddle

    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)