Publishing 2019 R1 content
[platform/upstream/dldt.git] / model-optimizer / mo / ops / split.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 import copy
17
18 import numpy as np
19 from mo.graph.graph import Node, Graph
20 from mo.ops.op import Op, PermuteAttrs
21
22
23 class Split(Op):
24     op = 'Split'
25     enabled = True
26
27     def __init__(self, graph: Graph, attrs: dict):
28         super().__init__(graph, {
29             'type': 'Split',
30             'op': 'Split',
31             'axis': 1,
32             'input_port': 0,
33             'in_ports_count': 1,
34             'infer': Split.infer
35         }, attrs)
36
37     def supported_attrs(self):
38         return ['axis', 'num_split']
39
40     @staticmethod
41     def infer(node: Node):
42         input_node = node.in_node(0)
43         outputs = node.out_nodes()
44         out_shape = copy.copy(input_node.shape)
45         out_shape[node.axis] = np.int64(input_node.shape[node.axis] / node.num_split)
46         for idx, output in outputs.items():
47             output.shape = out_shape
48         PermuteAttrs.create_permute_attrs(node, attrs=[('axis', 'input:0')])
49