updated readme files (#54)
[platform/upstream/dldt.git] / model-optimizer / extensions / front / kaldi / add_reshape_for_conv.py
1 """
2  Copyright (c) 2017-2018 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 import networkx as nx
18
19 from extensions.front.kaldi.replace_lstm_node_pattern import create_node
20 from mo.front.common.replacement import FrontReplacementOp
21 from mo.graph.graph import Node
22
23
24 class ReplaceConvolutionReshape(FrontReplacementOp):
25     op = "Convolution"
26     enabled = True
27
28     def replace_op(self, graph: nx.MultiDiGraph, node: Node):
29         input_nodes = node.in_nodes()
30
31         conv_attrs = graph.node[node.id]['pb'].__dict__
32         input_reshape = create_node(graph, 'Reshape_Convolution', {'type': 'Reshape',
33                                                                    'axis': 1,
34                                                                    'num_axes': -1,
35                                                                    'dim': None},
36                                     tuple(n.id for i, n in input_nodes.items()))
37         convolution = create_node(graph, 'Convolution', conv_attrs, tuple([input_reshape.id]))
38         output_reshape = create_node(graph, 'Convolution_Reshape', {'type': 'Reshape',
39                                                                     'axis': 1,
40                                                                     'num_axes': -1,
41                                                                     'dim': None},
42                                      tuple([convolution.id]))
43
44         return [output_reshape.id]