BatchNormalization - 7 vs 15

Next section compares an older to a newer version of the same operator after both definition are converted into markdown text. Green means an addition to the newer version, red means a deletion. Anything else is unchanged.

BatchNormalization7 → BatchNormalization15 RENAMED
@@ -1 +1 @@
1
1
  Carries out batch normalization as described in the paper
2
2
  https://arxiv.org/abs/1502.03167. Depending on the mode it is being run,
3
+ There are five required inputs 'X', 'scale', 'B', 'input_mean' and
4
+ 'input_var'.
5
+ Note that 'input_mean' and 'input_var' are expected to be the estimated
6
+ statistics in inference mode (training_mode=False, default),
7
+ and the running statistics in training mode (training_mode=True).
3
- there are multiple cases for the number of outputs, which we list below:
8
+ There are multiple cases for the number of outputs, which we list below:
4
- Output case #1: Y, mean, var, saved_mean, saved_var (training mode)
9
+ * Output case #1: Y, running_mean, running_var (training_mode=True)
5
- Output case #2: Y (test mode)
10
+ * Output case #2: Y (training_mode=False)
11
+
12
+ When training_mode=False, extra outputs are invalid.
13
+ The outputs are updated as follows when training_mode=True:
14
+
15
+ running_mean = input_mean * momentum + current_mean * (1 - momentum)
16
+ running_var = input_var * momentum + current_var * (1 - momentum)
17
+
18
+ Y = (X - current_mean) / sqrt(current_var + epsilon) * scale + B
19
+
20
+ where:
21
+
22
+ current_mean = ReduceMean(X, axis=all_except_channel_index)
23
+ current_var = ReduceVar(X, axis=all_except_channel_index)
24
+
25
+ Notice that ReduceVar refers to the population variance, and it equals to
26
+ sum(sqrd(x_i - x_avg)) / N
27
+ where N is the population size (this formula does not use sample size N - 1).
28
+
29
+ The computation of ReduceMean and ReduceVar uses float to avoid overflow for float16 inputs.
30
+
31
+ When training_mode=False:
32
+
33
+ Y = (X - input_mean) / sqrt(input_var + epsilon) * scale + B
34
+
35
+
36
+ For previous (depreciated) non-spatial cases, implementors are suggested
37
+ to flatten the input shape to (N x C * D1 * D2 * ... * Dn) before a BatchNormalization Op.
6
- This operator has **optional** inputs/outputs. See [ONNX IR](https://github.com/onnx/onnx/blob/main/docs/IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted.
38
+ This operator has **optional** inputs/outputs. See [ONNX IR](https://github.com/onnx/onnx/blob/main/docs/IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted.
7
39
  ### Attributes
8
40
  * **epsilon - FLOAT** (default is '1e-05'):
9
41
  The epsilon value to use to avoid division by zero.
10
42
  * **momentum - FLOAT** (default is '0.9'):
11
43
  Factor used in computing the running mean and variance.e.g., running_mean = running_mean * momentum + mean * (1 - momentum).
12
- * **spatial - INT** (default is '1'):
44
+ * **training_mode - INT** (default is '0'):
13
- If true, compute the mean and variance across per activation. If false, compute the mean and variance across per feature over each mini-batch.
45
+ If set to true, it indicates BatchNormalization is being used for training, and outputs 1 and 2 are to be computed.
14
46
  ### Inputs
15
47
  - **X** (heterogeneous) - **T**:
16
- Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
48
+ Input data tensor from the previous operator; dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size, C is the number of channels. Statistics are computed for every channel of C over N and D1 to Dn dimensions. For image data, input dimensions become (N x C x H x W). The op also accepts single dimension input of size N in which case C is assumed to be 1
17
- - **scale** (heterogeneous) - **T**:
49
+ - **scale** (heterogeneous) - **T1**:
18
- If spatial is true, the dimension of scale is (C). If spatial is false, the dimensions of scale are (C x D1 x ... x Dn)
50
+ Scale tensor of shape (C).
19
- - **B** (heterogeneous) - **T**:
51
+ - **B** (heterogeneous) - **T1**:
20
- If spatial is true, the dimension of bias is (C). If spatial is false, the dimensions of bias are (C x D1 x ... x Dn)
52
+ Bias tensor of shape (C).
21
- - **mean** (heterogeneous) - **T**:
53
+ - **input_mean** (heterogeneous) - **T2**:
22
- If spatial is true, the dimension of the running mean (training) or the estimated mean (testing) is (C). If spatial is false, the dimensions of the running mean (training) or the estimated mean (testing) are (C x D1 x ... x Dn).
54
+ running (training) or estimated (testing) mean tensor of shape (C).
23
- - **var** (heterogeneous) - **T**:
55
+ - **input_var** (heterogeneous) - **T2**:
24
- If spatial is true, the dimension of the running variance(training) or the estimated variance (testing) is (C). If spatial is false, the dimensions of the running variance(training) or the estimated variance (testing) are (C x D1 x ... x Dn).
56
+ running (training) or estimated (testing) variance tensor of shape (C).
25
57
  ### Outputs
26
- Between 1 and 5 outputs.
58
+ Between 1 and 3 outputs.
27
59
  - **Y** (heterogeneous) - **T**:
28
60
  The output tensor of the same shape as X
29
- - **mean** (optional, heterogeneous) - **T**:
61
+ - **running_mean** (optional, heterogeneous) - **T2**:
30
62
  The running mean after the BatchNormalization operator.
31
- - **var** (optional, heterogeneous) - **T**:
63
+ - **running_var** (optional, heterogeneous) - **T2**:
64
+ The running variance after the BatchNormalization operator. This op uses the population size (N) for calculating variance, and not the sample size N-1.
32
- The running variance after the BatchNormalization operator.
33
- - **saved_mean** (optional, heterogeneous) - **T**:
34
-
35
- Saved mean used during training to speed up gradient computation.
36
- - **saved_var** (optional, heterogeneous) - **T**:
37
-
38
- Saved variance used during training to speed up gradient computation.
39
65
  ### Type Constraints
40
- * **T** in ( tensor(double), tensor(float), tensor(float16) ):
66
+ * **T** in ( tensor(bfloat16), tensor(double), tensor(float), tensor(float16) ):
67
+ * **T1** in ( tensor(bfloat16), tensor(double), tensor(float), tensor(float16) ):
68
+
69
+ Constrain scale and bias types to float tensors.
70
+ * **T2** in ( tensor(bfloat16), tensor(double), tensor(float), tensor(float16) ):
71
+
41
- Constrain input and output types to float tensors.+ Constrain input and output types to float tensors.
72
+ Constrain mean and variance types to float tensors.