mindspore.ops.BNTrainingUpdate

class mindspore.ops.BNTrainingUpdate(*args, **kwargs)[source]

For the BatchNorm operation, this operator updates the moving averages for training and is used in conjunction with BNTrainingReduce. Where the moving averages is a method of analyzing data points by creating a series of averages of different subsets of the entire data set.

Parameters
  • isRef (bool) – If a ref. Default: True. Ref indicates whether to enable the output multiplexing input address.

  • epsilon (float) – A small value added to variance avoid dividing by zero. Default: 1e-5.

  • factor (float) – A weight for updating the mean and variance. Default: 0.1.

Inputs:
  • input_x (Tensor) - A 4-D Tensor with float16 or float32 data type. Tensor of shape \((N, C, A, B)\).

  • sum (Tensor) - A 1-D Tensor with float16 or float32 data type for the output of operator BNTrainingReduce. Tensor of shape \((C,)\).

  • square_sum (Tensor) - A 1-D Tensor with float16 or float32 data type for the output of operator BNTrainingReduce. Tensor of shape \((C,)\).

  • scale (Tensor) - A 1-D Tensor with float16 or float32, for the scaling factor. Tensor of shape \((C,)\).

  • offset (Tensor) - A 1-D Tensor with float16 or float32, for the scaling offset. Tensor of shape \((C,)\).

  • mean (Tensor) - A 1-D Tensor with float16 or float32, for the scaling mean. Tensor of shape \((C,)\).

  • variance (Tensor) - A 1-D Tensor with float16 or float32, for the update variance. Tensor of shape \((C,)\).

Outputs:
  • y (Tensor) - Tensor, has the same shape and data type as input_x.

  • mean (Tensor) - Tensor for the updated mean, with float32 data type. Has the same shape as variance.

  • variance (Tensor) - Tensor for the updated variance, with float32 data type. Has the same shape as variance.

  • batch_mean (Tensor) - Tensor for the mean of input_x, with float32 data type. Has the same shape as variance.

  • batch_variance (Tensor) - Tensor for the mean of variance, with float32 data type. Has the same shape as variance.

Raises
  • TypeError – If isRef is not a bool.

  • TypeError – If dtype of epsilon or factor is not float.

  • TypeError – If input_x, sum, square_sum, scale, offset, mean or variance is not a Tensor.

  • TypeError – If dtype of input_x, sum, square_sum, scale, offset, mean or variance is neither float16 nor float32.

Supported Platforms:

Ascend

Examples

>>> input_x = Tensor(np.ones([1, 2, 2, 2]), mindspore.float32)
>>> sum_val = Tensor(np.ones([2]), mindspore.float32)
>>> square_sum = Tensor(np.ones([2]), mindspore.float32)
>>> scale = Tensor(np.ones([2]), mindspore.float32)
>>> offset = Tensor(np.ones([2]), mindspore.float32)
>>> mean = Tensor(np.ones([2]), mindspore.float32)
>>> variance = Tensor(np.ones([2]), mindspore.float32)
>>> bn_training_update = ops.BNTrainingUpdate()
>>> output = bn_training_update(input_x, sum_val, square_sum, scale, offset, mean, variance)
>>> print(output)
(Tensor(shape=[1, 2, 2, 2], dtype=Float32, value=
[[[[ 2.73200464e+00,  2.73200464e+00],
   [ 2.73200464e+00,  2.73200464e+00]],
  [[ 2.73200464e+00,  2.73200464e+00],
   [ 2.73200464e+00,  2.73200464e+00]]]]), Tensor(shape=[2], dtype=Float32, value= [9.24999952e-01,
9.24999952e-01]), Tensor(shape=[2], dtype=Float32, value= [ 9.24999952e-01, 9.24999952e-01]),
Tensor(shape=[2], dtype=Float32, value= [ 2.50000000e-01, 2.50000000e-01]), Tensor(shape=[2], dtype=Float32,
value= [ 1.87500000e-01, 1.87500000e-01]))