mindspore.dataset.vision.py_transforms.Normalize

class mindspore.dataset.vision.py_transforms.Normalize(mean, std)[source]

Normalize the input numpy.ndarray image of shape (C, H, W) with the specified mean and standard deviation.

\[output_{c} = \frac{input_{c} - mean_{c}}{std_{c}}\]

Note

The pixel values of the input image need to be in range of [0.0, 1.0]. If not so, please call mindspore.dataset.vision.py_transforms.ToTensor first.

Parameters
  • mean (Union[float, Sequence[float]]) – Mean pixel values for each channel, must be in range of [0.0, 1.0]. If float is provided, it will be applied to each channel. If Sequence[float] is provided, it should have the same length with channel and be arranged in channel order.

  • std (Union[float, Sequence[float]]) – Standard deviation values for each channel, must be in range of (0.0, 1.0]. If float is provided, it will be applied to each channel. If Sequence[float] is provided, it should have the same length with channel and be arranged in channel order.

Raises
Supported Platforms:

CPU

Examples

>>> from mindspore.dataset.transforms.py_transforms import Compose
>>>
>>> transforms_list = Compose([py_vision.Decode(),
...                            py_vision.RandomHorizontalFlip(0.5),
...                            py_vision.ToTensor(),
...                            py_vision.Normalize((0.491, 0.482, 0.447), (0.247, 0.243, 0.262))])
>>> # apply the transform to dataset through map function
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns="image")