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 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.
dtype (str) – The dtype of the numpy.ndarray output when pad_channel is set True. Only “float32” and “float16” are supported (default=”float32”).
- 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 length 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.
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")