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.
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
TypeError – If the input image is not of type
numpy.ndarray
.TypeError – If dimension of the input image is not 3.
NotImplementedError – If dtype of the input image is int.
ValueError – If lengths of mean and std are not equal.
ValueError – If length of mean or std is neither equal to 1 nor equal to the length of channel.
- 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")