BatchNormalization - 9 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.
BatchNormalization9 → 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
|
-
|
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
6
|
For previous (depreciated) non-spatial cases, implementors are suggested
|
35
|
-
to flatten the input shape to (N x C
|
7
|
+
to flatten the input shape to (N x C*D1*D2 ..*Dn) before a BatchNormalization Op.
|
36
8
|
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.
|
37
9
|
**Attributes**
|
38
10
|
* **epsilon**:
|
39
11
|
The epsilon value to use to avoid division by zero.
|
40
12
|
* **momentum**:
|
41
13
|
Factor used in computing the running mean and variance.e.g.,
|
42
14
|
running_mean = running_mean * momentum + mean * (1 - momentum).
|
43
|
-
* **training_mode**:
|
44
|
-
If set to true, it indicates BatchNormalization is being used for
|
45
|
-
training, and outputs 1, 2, 3, and 4 would be populated.
|
46
15
|
**Inputs**
|
47
16
|
* **X** (heterogeneous) - **T**:
|
48
17
|
Input data tensor from the previous operator; dimensions are in the
|
49
18
|
form of (N x C x D1 x D2 ... Dn), where N is the batch size, C is
|
50
19
|
the number of channels. Statistics are computed for every channel of
|
51
20
|
C over N and D1 to Dn dimensions. For image data, input dimensions
|
52
21
|
become (N x C x H x W). The op also accepts single dimension input
|
53
22
|
of size N in which case C is assumed to be 1
|
54
23
|
* **scale** (heterogeneous) - **T**:
|
55
24
|
Scale tensor of shape (C).
|
56
25
|
* **B** (heterogeneous) - **T**:
|
57
26
|
Bias tensor of shape (C).
|
58
|
-
* **
|
27
|
+
* **mean** (heterogeneous) - **T**:
|
59
28
|
running (training) or estimated (testing) mean tensor of shape (C).
|
60
|
-
* **
|
29
|
+
* **var** (heterogeneous) - **T**:
|
61
30
|
running (training) or estimated (testing) variance tensor of shape
|
62
31
|
(C).
|
63
32
|
**Outputs**
|
64
|
-
Between 1 and
|
33
|
+
Between 1 and 5 outputs.
|
65
34
|
* **Y** (heterogeneous) - **T**:
|
66
35
|
The output tensor of the same shape as X
|
67
|
-
* **
|
36
|
+
* **mean** (optional, heterogeneous) - **T**:
|
68
37
|
The running mean after the BatchNormalization operator.
|
69
|
-
* **
|
38
|
+
* **var** (optional, heterogeneous) - **T**:
|
70
|
-
The running variance after the BatchNormalization operator.
|
39
|
+
The running variance after the BatchNormalization operator.
|
40
|
+
* **saved_mean** (optional, heterogeneous) - **T**:
|
71
|
-
|
41
|
+
Saved mean used during training to speed up gradient computation.
|
42
|
+
* **saved_var** (optional, heterogeneous) - **T**:
|
43
|
+
Saved variance used during training to speed up gradient
|
72
|
-
|
44
|
+
computation.
|
73
45
|
**Type Constraints**
|
74
46
|
* **T** in (
|
75
|
-
tensor(bfloat16),
|
76
47
|
tensor(double),
|
77
48
|
tensor(float),
|
78
49
|
tensor(float16)
|
79
50
|
):
|
80
|
-
Constrain input and output types to float tensors
|
51
|
+
Constrain input and output types to float tensors.- * **U** in (
|
81
|
-
tensor(bfloat16),
|
82
|
-
tensor(double),
|
83
|
-
tensor(float),
|
84
|
-
tensor(float16)
|
85
|
-
):
|
86
|
-
Constrain mean and variance types to float tensors. It allows all
|
87
|
-
float type for U.
|