class 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.

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

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


import numpy as np
from PIL import Image
from import Transpose

transform = Transpose()

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

fake_img = transform(fake_img)