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.

Shape:
  • img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).

  • output(np.ndarray|Paddle.Tensor): A transposed array or tensor. If input

    is a PIL.Image, output will be converted to np.ndarray automatically.

Returns

A callable object of Transpose.

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)
(3, 300, 320)