class Normalize ( mean=0.0, std=1.0, data_format='CHW', to_rgb=False, keys=None ) [source]

Normalize the input data with mean and standard deviation. Given mean: (M1,...,Mn) and std: (S1,..,Sn) for n channels, this transform will normalize each channel of the input data. output[channel] = (input[channel] - mean[channel]) / std[channel]

  • mean (int|float|list|tuple) – Sequence of means for each channel.

  • std (int|float|list|tuple) – Sequence of standard deviations for each channel.

  • data_format (str, optional) – Data format of img, should be ‘HWC’ or ‘CHW’. Default: ‘CHW’.

  • to_rgb (bool, optional) – Whether to convert to rgb. Default: False.

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


import numpy as np
from PIL import Image
from import Normalize

normalize = Normalize(mean=[127.5, 127.5, 127.5],
                      std=[127.5, 127.5, 127.5],

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

fake_img = normalize(fake_img)
print(fake_img.max, fake_img.max)