Publishing R3
[platform/upstream/dldt.git] / model-optimizer / mo / ops / split.py
1 """
2  Copyright (c) 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 import copy
17
18 import networkx as nx
19 import numpy as np
20 from mo.graph.graph import Node
21 from mo.ops.op import Op
22
23
24 class Split(Op):
25     op = 'Split'
26     enabled = True
27
28     def __init__(self, graph: nx.MultiDiGraph, attrs: dict):
29         super().__init__(graph, {
30             'type': 'Split',
31             'op': 'Split',
32             'axis': 1,
33             'input_port': 0,
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.pb.num_split)
46         for idx, output in outputs.items():
47             output.shape = out_shape