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.
21 from mo.graph.graph import Graph
22 from mo.ops.op import Op
25 class FlattenONNX(Op):
29 def __init__(self, graph: Graph, attrs: dict):
30 super().__init__(graph, {
33 'infer': __class__.infer,
41 Infers shape of flatten node as it is done in onnx.
43 node: graph flatten node
45 if not node.has_valid('axis'):
46 log.debug('Can\'t calculate output shape for {} node due to missing axis attribute'.format(node.name))
49 if node.in_node(0).shape is None:
50 log.debug('Can\'t calculate output shape for {} node due to shape for input node is None'.format(node.name))
53 if len(node.in_nodes()) != 1:
55 'Can\'t calculate output shape for {} node. Number of input nodes should be equal 1 instead of {}'.format(
56 node.name, len(node.in_nodes())))
60 shape = node.in_node(0).shape
61 dim = [np.prod(shape[0:axis]), np.prod(shape[axis:])]
62 node['dim'] = np.array(dim)
63 node.out_node().shape = np.array(dim)
64 if node.in_node(0).has_valid('value'):
65 node.out_node().value = np.reshape(node.in_node(0).value, dim)