read_file read_file ( filename, name=None ) [source]

Reads and outputs the bytes contents of a file as a uint8 Tensor with one dimension.

  • filename (str) – Path of the file to be read.

  • 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 uint8 tensor.


>>> import cv2
>>> import paddle
>>> paddle.seed(2023)
>>> fake_img = (paddle.rand((400, 300, 3)).numpy() * 255).astype('uint8')
>>> cv2.imwrite('fake.jpg', fake_img)
>>> img_bytes ='fake.jpg')
>>> print(img_bytes.shape)