Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.ops.batch_norm

mindspore.ops.batch_norm(input_x, running_mean, running_var, weight, bias, training=False, momentum=0.1, eps=1e-05)[source]

Batch Normalization for input data and updated parameters.

Batch Normalization is widely used in convolutional neural networks. This operation applies Batch Normalization over inputs to avoid internal covariate shift as described in the paper Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift. It rescales and recenters the features using a mini-batch of data and the learned parameters can be described in the following formula,

y=xmeanvariance+ϵγ+β

where γ is weight, β is bias, ϵ is eps, mean is the mean of x, variance is the variance of x.

Warning

  • For Atlas 200/300/500 inference product, the result accuracy fails to reach 1‰ due to the square root instruction.

Note

  • If training is False, weight, bias, running_mean and running_var are Tensors.

  • If training is True, weight, bias, running_mean and running_var are Parameters.

Parameters
  • input_x (Tensor) – Tensor of shape (N,C), with float16 or float32 data type.

  • running_mean (Union[Tensor, Parameter]) – The shape (C,), has the same data type with weight.

  • running_var (Union[Tensor, Parameter]) – The shape (C,), has the same data type with weight.

  • weight (Union[Tensor, Parameter]) – The shape (C,), with float16 or float32 data type.

  • bias (Union[Tensor, Parameter]) – The shape (C,), has the same data type with weight.

  • training (bool, optional) – If training is True, mean and variance are computed during training. If training is False, they're loaded from checkpoint during inference. Default: False .

  • momentum (float, optional) – The hyper parameter to compute moving average for running_mean and running_var (e.g. new_running_mean=(1momentum)running_mean+momentumcurrent_mean). Momentum value must be [0, 1]. Default: 0.1 .

  • eps (float, optional) – A small value added for numerical stability. Default: 1e-5, value must be (0, 1] .

Returns

output_x (Tensor) - The same type and shape as the input_x. The shape is (N,C).

Raises
  • TypeError – If training is not a bool.

  • TypeError – If dtype of eps or momentum is not float.

  • TypeError – If input_x, weight, bias, running_mean or running_var is not a Tensor.

  • TypeError – If dtype of input_x, weight is neither float16 nor float32.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> from mindspore import Tensor, ops
>>> input_x = Tensor([[1.0, 2.0], [3.0, 4.0]], mindspore.float32)
>>> running_mean = Tensor([0.5, 1.5], mindspore.float32)
>>> running_var = Tensor([0.1, 0.2], mindspore.float32)
>>> weight = Tensor([2.0, 2.0], mindspore.float32)
>>> bias = Tensor([-1.0, -1.0], mindspore.float32)
>>> output = ops.batch_norm(input_x, running_mean, running_var, weight, bias)
>>> print(output)
[[ 2.1621194  1.2360122]
 [14.810596  10.180061 ]]