BatchNormalization - 1 vs 14#

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.

BatchNormalization1 → BatchNormalization14 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).
8
- There are multiple cases for the number of outputs, which we list below:
3
+ 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)
5
+ Output case #2: Y (test mode)
9
- Output case #1: Y, running_mean, running_var (training_mode=True)
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
-
16
- running_mean = input_mean * momentum + current_mean * (1 - momentum)
17
- running_var = input_var * momentum + current_var * (1 - momentum)
18
-
19
- Y = (X - current_mean) / sqrt(current_var + epsilon) * scale + B
20
-
21
- where:
22
-
23
- current_mean = ReduceMean(X, axis=all_except_channel_index)
24
- current_var = ReduceVar(X, axis=all_except_channel_index)
25
-
26
- Notice that ReduceVar refers to the population variance, and it equals to
27
- sum(sqrd(x_i - x_avg)) / N
28
- where N is the population size (this formula does not use sample size N - 1).
29
-
30
- When training_mode=False:
31
- ::
32
-
33
- Y = (X - input_mean) / sqrt(input_var + epsilon) * scale + B
34
-
35
- For previous (depreciated) non-spatial cases, implementors are suggested
36
- to flatten the input shape to (N x C * D1 * D2 * ... * Dn) before a BatchNormalization Op.
37
- This operator has **optional** inputs/outputs. See ONNX <https://github.com/onnx/onnx/blob/master/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
6
  **Attributes**
7
+ * **consumed_inputs** (required):
8
+ legacy optimization attribute.
39
9
  * **epsilon**:
40
- The epsilon value to use to avoid division by zero.
10
+ The epsilon value to use to avoid division by zero, default is
11
+ 1e-5f.
12
+ * **is_test**:
13
+ If set to nonzero, run spatial batch normalization in test mode,
14
+ default is 0.
41
15
  * **momentum**:
42
16
  Factor used in computing the running mean and variance.e.g.,
43
- running_mean = running_mean * momentum + mean * (1 - momentum).
17
+ running_mean = running_mean * momentum + mean * (1 - momentum),
18
+ default is 0.9f.
44
- * **training_mode**:
19
+ * **spatial**:
45
- If set to true, it indicates BatchNormalization is being used for
20
+ If true, compute the mean and variance across all spatial elements
46
- training, and outputs 1, 2, 3, and 4 would be populated.
21
+ If false, compute the mean and variance across per feature.Default
22
+ is 1.
47
23
  **Inputs**
48
24
  * **X** (heterogeneous) - **T**:
25
+ The input 4-dimensional tensor of shape NCHW.
49
- Input data tensor from the previous operator; dimensions are in the
50
- form of (N x C x D1 x D2 ... Dn), where N is the batch size, C is
51
- the number of channels. Statistics are computed for every channel of
52
- C over N and D1 to Dn dimensions. For image data, input dimensions
53
- become (N x C x H x W). The op also accepts single dimension input
54
- of size N in which case C is assumed to be 1
55
26
  * **scale** (heterogeneous) - **T**:
56
- Scale tensor of shape (C).
27
+ The scale as a 1-dimensional tensor of size C to be applied to the
28
+ output.
57
29
  * **B** (heterogeneous) - **T**:
58
- Bias tensor of shape (C).
30
+ The bias as a 1-dimensional tensor of size C to be applied to the
31
+ output.
59
- * **input_mean** (heterogeneous) - **U**:
32
+ * **mean** (heterogeneous) - **T**:
60
- running (training) or estimated (testing) mean tensor of shape (C).
33
+ The running mean (training) or the estimated mean (testing) as a
34
+ 1-dimensional tensor of size C.
61
- * **input_var** (heterogeneous) - **U**:
35
+ * **var** (heterogeneous) - **T**:
62
- running (training) or estimated (testing) variance tensor of shape
36
+ The running variance (training) or the estimated variance (testing)
63
- (C).
37
+ as a 1-dimensional tensor of size C.
64
38
  **Outputs**
65
- Between 1 and 3 outputs.
39
+ Between 1 and 5 outputs.
66
40
  * **Y** (heterogeneous) - **T**:
67
- The output tensor of the same shape as X
41
+ The output 4-dimensional tensor of the same shape as X.
68
- * **running_mean** (optional, heterogeneous) - **U**:
42
+ * **mean** (optional, heterogeneous) - **T**:
69
- The running mean after the BatchNormalization operator.
43
+ The running mean after the BatchNormalization operator. Must be in-
44
+ place with the input mean. Should not be used for testing.
70
- * **running_var** (optional, heterogeneous) - **U**:
45
+ * **var** (optional, heterogeneous) - **T**:
71
- The running variance after the BatchNormalization operator. This op
46
+ The running variance after the BatchNormalization operator. Must be
72
- uses the population size (N) for calculating variance, and not the
47
+ in-place with the input var. Should not be used for testing.
48
+ * **saved_mean** (optional, heterogeneous) - **T**:
49
+ Saved mean used during training to speed up gradient computation.
73
- sample size N-1.
50
+ Should not be used for testing.
51
+ * **saved_var** (optional, heterogeneous) - **T**:
52
+ Saved variance used during training to speed up gradient
53
+ computation. Should not be used for testing.
74
54
  **Type Constraints**
75
55
  * **T** in (
76
- tensor(bfloat16),
77
56
  tensor(double),
78
57
  tensor(float),
79
58
  tensor(float16)
80
59
  ):
81
- Constrain input and output types to float tensors.
60
+ Constrain input and output types to float tensors.- * **U** in (
82
- tensor(bfloat16),
83
- tensor(double),
84
- tensor(float),
85
- tensor(float16)
86
- ):
87
- Constrain mean and variance types to float tensors. It allows all
88
- float type for U.