MeanVarianceNormalization#

  • Domain: ai.onnx

  • Since version: 29

Computes mean-variance normalization of X: Y = (X - mean) / (sqrt(variance) + epsilon), where mean = ReduceMean(X, axes) and variance = ReduceMean((X - mean)^2, axes). Each reduction computes the arithmetic mean over axes and retains the reduced dimensions with size 1 for broadcasting. An empty axes list reduces over all dimensions.

The default epsilon is 1e-9 and is added after the square root. For float16 and bfloat16 inputs, X is converted to float32 before computation. Otherwise, computation uses the input type. epsilon is converted to the computation type, and the result is cast to the input type. Y has the same shape and element type as X.

Inputs

  • X (T): Input tensor

Outputs

  • Y (T): Output tensor

Attributes

  • axes (int[]): Axes over which to compute mean and variance. Values must be in [-r, r-1], where r is the rank of X; negative values count from the last dimension. An empty list reduces over all dimensions. The default is [0, 2, 3], which computes per-channel statistics for an NCHW tensor.

  • epsilon (float): Value added to the standard deviation in the denominator.

Type Constraints

  • T: Constrain input and output types to floating-point tensors. Allowed types: tensor(bfloat16), tensor(double), tensor(float), tensor(float16).

Examples#

test_cc_mvn_epsilon

Node:
  MeanVarianceNormalization(X) -> (Y)
  Attributes:
    axes = [1, -1]
    epsilon = 1.0
Inputs:
  X: shape=(2, 3, 4), dtype=float64
    [[[ 0.,  1.,  2.,  3.],
      [ 4.,  5.,  6.,  7.],
      [ 8.,  9., 10., 11.]],

     [[12., 13., 14., 15.],
      [16., 17., 18., 19.],
      [20., 21., 22., 23.]]]

Outputs:
  Y: shape=(2, 3, 4), dtype=float64
    [[[-1.23538524, -1.01076974, -0.78615425, -0.56153875],
      [-0.33692325, -0.11230775,  0.11230775,  0.33692325],
      [ 0.56153875,  0.78615425,  1.01076974,  1.23538524]],

     [[-1.23538524, -1.01076974, -0.78615425, -0.56153875],
      [-0.33692325, -0.11230775,  0.11230775,  0.33692325],
      [ 0.56153875,  0.78615425,  1.01076974,  1.23538524]]]

test_cc_mvn_zero_variance

Node:
  MeanVarianceNormalization(X) -> (Y)
  Attributes:
    axes = [0]
Inputs:
  X: shape=(2,), dtype=float32
    [1., 1.]

Outputs:
  Y: shape=(2,), dtype=float32
    [0., 0.]

Differences with previous version (13)#

SchemaDiff: MeanVarianceNormalization (domain 'ai.onnx')

  • old version: 13

  • new version: 29

  • breaking: no

Attributes:

  • added ‘epsilon’: type=FLOAT; required=False; default=1e-09

Documentation:

  • line similarity: 0.48 (+9/-2 lines)

--- MeanVarianceNormalization v13
+++ MeanVarianceNormalization v29
@@ -1,7 +1,14 @@

 Computes mean-variance normalization of `X`:
-`Y = (X - mean) / (sqrt(variance) + 1e-9)`, where
+`Y = (X - mean) / (sqrt(variance) + epsilon)`, where
 `mean = ReduceMean(X, axes)` and
-`variance = ReduceMean(X^2, axes) - mean^2`.
+`variance = ReduceMean((X - mean)^2, axes)`.
 Each reduction computes the arithmetic mean over `axes` and retains the
 reduced dimensions with size 1 for broadcasting.
+An empty `axes` list reduces over all dimensions.
+
+The default `epsilon` is 1e-9 and is added after the square root.
+For float16 and bfloat16 inputs, `X` is converted to float32 before computation.
+Otherwise, computation uses the input type. `epsilon` is converted to the
+computation type, and the result is cast to the input type.
+`Y` has the same shape and element type as `X`.

Version History#