BatchNormalization - 6 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.
BatchNormalization6 → 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).
|
8
|
-
|
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
|
-
The computation of ReduceMean and ReduceVar uses float to avoid overflow for float16 inputs.
|
31
|
-
|
32
|
-
When training_mode=False:
|
33
|
-
::
|
34
|
-
|
35
|
-
Y = (X - input_mean) / sqrt(input_var + epsilon) * scale + B
|
36
|
-
|
37
|
-
For previous (depreciated) non-spatial cases, implementors are suggested
|
38
|
-
to flatten the input shape to (N x C * D1 * D2 * ... * Dn) before a BatchNormalization Op.
|
39
|
-
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.
|
40
6
|
**Attributes**
|
41
7
|
* **epsilon**:
|
42
|
-
The epsilon value to use to avoid division by zero
|
8
|
+
The epsilon value to use to avoid division by zero, default is
|
9
|
+
1e-5f.
|
10
|
+
* **is_test**:
|
11
|
+
If set to nonzero, run spatial batch normalization in test mode,
|
12
|
+
default is 0.
|
43
13
|
* **momentum**:
|
44
14
|
Factor used in computing the running mean and variance.e.g.,
|
45
|
-
running_mean = running_mean * momentum + mean * (1 - momentum)
|
15
|
+
running_mean = running_mean * momentum + mean * (1 - momentum),
|
16
|
+
default is 0.9f.
|
46
|
-
* **
|
17
|
+
* **spatial**:
|
47
|
-
If
|
18
|
+
If true, compute the mean and variance across all spatial elements
|
48
|
-
|
19
|
+
If false, compute the mean and variance across per feature.Default
|
20
|
+
is 1.
|
49
21
|
**Inputs**
|
50
22
|
* **X** (heterogeneous) - **T**:
|
51
|
-
Input data tensor from the previous operator; dimensions
|
23
|
+
Input data tensor from the previous operator; dimensions for image
|
24
|
+
case are (N x C x H x W), where N is the batch size, C is the number
|
25
|
+
of channels, and H and W are the height and the width of the data.
|
26
|
+
For non image case, the dimensions are in the form of (N x C x D1 x
|
27
|
+
D2 ... Dn), where N is the batch size.
|
52
|
-
form of (N x C x D1 x D2 ... Dn), where N is the batch size, C is
|
53
|
-
the number of channels. Statistics are computed for every channel of
|
54
|
-
C over N and D1 to Dn dimensions. For image data, input dimensions
|
55
|
-
become (N x C x H x W). The op also accepts single dimension input
|
56
|
-
of size N in which case C is assumed to be 1
|
57
|
-
* **scale** (heterogeneous) - **
|
28
|
+
* **scale** (heterogeneous) - **T**:
|
58
|
-
|
29
|
+
The scale as a 1-dimensional tensor of size C to be applied to the
|
30
|
+
output.
|
59
|
-
* **B** (heterogeneous) - **
|
31
|
+
* **B** (heterogeneous) - **T**:
|
60
|
-
|
32
|
+
The bias as a 1-dimensional tensor of size C to be applied to the
|
33
|
+
output.
|
61
|
-
* **
|
34
|
+
* **mean** (heterogeneous) - **T**:
|
62
|
-
running (training) or estimated (testing)
|
35
|
+
The running mean (training) or the estimated mean (testing) as a
|
36
|
+
1-dimensional tensor of size C.
|
63
|
-
* **
|
37
|
+
* **var** (heterogeneous) - **T**:
|
64
|
-
running (training) or estimated (testing)
|
38
|
+
The running variance (training) or the estimated variance (testing)
|
65
|
-
|
39
|
+
as a 1-dimensional tensor of size C.
|
66
40
|
**Outputs**
|
67
|
-
Between 1 and
|
41
|
+
Between 1 and 5 outputs.
|
68
42
|
* **Y** (heterogeneous) - **T**:
|
69
|
-
The output tensor of the same shape as X
|
43
|
+
The output tensor of the same shape as X.
|
70
|
-
* **
|
44
|
+
* **mean** (optional, heterogeneous) - **T**:
|
71
|
-
The running mean after the BatchNormalization operator.
|
45
|
+
The running mean after the BatchNormalization operator. Must be in-
|
46
|
+
place with the input mean. Should not be used for testing.
|
72
|
-
* **
|
47
|
+
* **var** (optional, heterogeneous) - **T**:
|
73
|
-
The running variance after the BatchNormalization operator.
|
48
|
+
The running variance after the BatchNormalization operator. Must be
|
74
|
-
|
49
|
+
in-place with the input var. Should not be used for testing.
|
50
|
+
* **saved_mean** (optional, heterogeneous) - **T**:
|
51
|
+
Saved mean used during training to speed up gradient computation.
|
75
|
-
|
52
|
+
Should not be used for testing.
|
53
|
+
* **saved_var** (optional, heterogeneous) - **T**:
|
54
|
+
Saved variance used during training to speed up gradient
|
55
|
+
computation. Should not be used for testing.
|
76
56
|
**Type Constraints**
|
77
57
|
* **T** in (
|
78
|
-
tensor(bfloat16),
|
79
58
|
tensor(double),
|
80
59
|
tensor(float),
|
81
60
|
tensor(float16)
|
82
61
|
):
|
83
|
-
Constrain input and output types to float tensors
|
62
|
+
Constrain input and output types to float tensors.- * **T1** in (
|
84
|
-
tensor(bfloat16),
|
85
|
-
tensor(double),
|
86
|
-
tensor(float),
|
87
|
-
tensor(float16)
|
88
|
-
):
|
89
|
-
Constrain scale and bias types to float tensors.
|
90
|
-
* **T2** in (
|
91
|
-
tensor(bfloat16),
|
92
|
-
tensor(double),
|
93
|
-
tensor(float),
|
94
|
-
tensor(float16)
|
95
|
-
):
|
96
|
-
Constrain mean and variance types to float tensors.
|