Transpose

class paddle.vision.transforms. Transpose ( order=(2, 0, 1), keys=None ) [source]

Transpose input data to a target format. For example, most transforms use HWC mode image, while the Neural Network might use CHW mode input tensor. output image will be an instance of numpy.ndarray.

Parameters
  • order (list|tuple, optional) – Target order of input data. Default: (2, 0, 1).

  • keys (list[str]|tuple[str], optional) – Same as BaseTransform. Default: None.

Examples

import numpy as np
from PIL import Image
from paddle.vision.transforms import Transpose

transform = Transpose()

fake_img = Image.fromarray((np.random.rand(300, 320, 3) * 255.).astype(np.uint8))

fake_img = transform(fake_img)
print(fake_img.shape)