read_file

paddle.vision.ops. read_file ( filename, name=None ) [source]

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

Parameters
  • 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.

Returns

A uint8 tensor.

Examples

>>> 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 = paddle.vision.ops.read_file('fake.jpg')
>>> print(img_bytes.shape)
[142773]