2 Copyright (c) 2018-2019 Intel Corporation
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
19 from mo.back.replacement import BackReplacementPattern
20 from mo.graph.graph import Graph
23 class ShufflenetReLUReorder(BackReplacementPattern):
25 This pass is workaround for GPU plugin
32 ('relu', dict(kind='op', type='ReLU')),
33 ('relu_data', dict(kind='data')),
34 ('reshape1', dict(kind='op', type='Reshape')),
35 ('reshape1_data', dict(kind='data')),
36 ('transpose', dict(kind='op', type='Permute')),
37 ('transpose_data', dict(kind='data')),
38 ('reshape2', dict(kind='op', type='Reshape')),
39 ('reshape2_data', dict(kind='data')),
40 ('conv', dict(kind='op', type='Convolution'))
42 edges=[('relu', 'relu_data'),
43 ('relu_data', 'reshape1'),
44 ('reshape1', 'reshape1_data'),
45 ('reshape1_data', 'transpose'),
46 ('transpose', 'transpose_data'),
47 ('transpose_data', 'reshape2'),
48 ('reshape2', 'reshape2_data'),
49 ('reshape2_data', 'conv'),
53 def replace_pattern(self, graph: Graph, match: dict):
55 reshape1 = match['reshape1']
56 reshape2_data = match['reshape2_data']
59 if np.max(conv.pad) == 0:
62 relu_input = relu.in_node()
64 # Disconnect InputData-x->ReLU->Data-x->Reshape1
65 edge_attrs = graph.get_edge_data(relu.out_node().id, reshape1.id)[0]
66 graph.remove_edge(relu_input.id, relu.id)
67 graph.remove_edge(relu.out_node().id, reshape1.id)
69 # Connect InputData-->Reshape1
70 graph.add_edges_from([(relu_input.id, reshape1.id, edge_attrs)])
72 # Insert ReLU: Reshape2Data->ReLU->Data->Convolution
73 edge_attrs = graph.get_edge_data(reshape2_data.id, conv.id)[0]
74 graph.remove_edge(reshape2_data.id, conv.id)
75 graph.add_edges_from([(reshape2_data.id, relu.id, {'in': 0}), (relu.out_node().id, conv.id, edge_attrs)])