Publishing 2019 R1 content
[platform/upstream/dldt.git] / model-optimizer / extensions / middle / FusedBatchNormTrainingCatch.py
1 """
2  Copyright (c) 2018-2019 Intel Corporation
3
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 """
16
17 from mo.graph.graph import Graph
18 from mo.middle.replacement import MiddleReplacementPattern
19 from mo.utils.error import Error
20
21
22 class FusedBatchNormTrainingCatch(MiddleReplacementPattern):
23     """
24     Replaces FusedBatchNorm(input, beta, gamma, mean, variance) with non-constant mean and variance,
25     but with constant beta and gamma to a sub-expression consisting of a combinatin of Eltwise and Power
26     layers and ScaleShift.
27     """
28
29     enabled = True
30     replacement_id = "Fused_Batch_Norm_is_training_true_catcher"
31
32     def run_after(self):
33         from extensions.middle.pass_separator import MiddleStart
34         return [MiddleStart]
35
36     def run_before(self):
37         from extensions.middle.pass_separator import MiddleFinish
38         return [MiddleFinish]
39
40     def pattern(self):
41         return dict(
42             nodes=[
43                 ('op', dict(kind='op', op='FusedBatchNorm', is_training=True))],
44             edges=[]
45         )
46
47     def replace_pattern(self, graph: Graph, match: dict):
48         raise Error('FusedBatchNorm doesn\'t support is_training=True. Node {}'.format(match['op'].id))