Normalize¶
- class paddle.vision.transforms. 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)
forn
channels, this transform will normalize each channel of the input data.output[channel] = (input[channel] - mean[channel]) / std[channel]
- Parameters
-
mean (int|float|list|tuple, optional) – Sequence of means for each channel.
std (int|float|list|tuple, optional) – 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.
- Shape:
-
img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
output(PIL.Image|np.ndarray|Paddle.Tensor): A normalized array or tensor.
- Returns
-
A callable object of Normalize.
Examples
>>> import paddle >>> from paddle.vision.transforms import Normalize >>> paddle.seed(2023) >>> normalize = Normalize(mean=[127.5, 127.5, 127.5], ... std=[127.5, 127.5, 127.5], ... data_format='HWC') ... >>> fake_img = paddle.rand([300,320,3]).numpy() * 255. >>> fake_img = normalize(fake_img) >>> print(fake_img.shape) (300, 320, 3) >>> print(fake_img.max(), fake_img.min()) 0.99999464 -0.9999929