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 values of the input image need to be in the range [0.0, 1.0]. If not so, call ToTensor first.
- Parameters
mean (Union[float, sequence]) – list or tuple of mean values for each channel, arranged in channel order. The values must be in the range [0.0, 1.0]. If a single float is provided, it will be filled to the same length as the channel.
std (Union[float, sequence]) – list or tuple of standard deviation values for each channel, arranged in channel order. The values must be in the range (0.0, 1.0]. If a single float is provided, it will be filled to the same length as the channel.
- Raises
TypeError – If the input is not numpy.ndarray.
TypeError – If the dimension of input is not 3.
NotImplementedError – If the dtype of input is a subdtype of np.integer.
ValueError – If the lengths of the mean and std are not equal.
ValueError – If the length of the mean or std is neither equal to the channel length nor 1.
- 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")