mindspore.dataset.vision.py_transforms.NormalizePad

class mindspore.dataset.vision.py_transforms.NormalizePad(mean, std, dtype='float32')[source]

Normalize the input numpy.ndarray image of shape (C, H, W) with the specified mean and standard deviation, then pad an extra channel filled with zeros.

\[\begin{split}output_{c} = \begin{cases} \frac{input_{c} - mean_{c}}{std_{c}}, & \text{if} \quad 0 \le c < 3 \text{;}\\ 0, & \text{if} \quad c = 3 \text{.} \end{cases}\end{split}\]

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.

  • dtype (str) – The dtype of the output image. Only “float32” and “float16” are supported. Default: “float32”.

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.NormalizePad((0.491, 0.482, 0.447), (0.247, 0.243, 0.262), "float32")])
>>> # apply the transform to dataset through map function
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns="image")