2 Copyright (c) 2018 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.front.caffe.extractors.utils import get_canonical_axis_index
24 def flatten_infer(node):
26 Infers shape of flatten node as it is done in Caffe.
27 Output shape: [Batch is the same, Production of other dims]
29 node: graph flatten node
32 input_shape = node.in_node(0).shape
33 if input_shape is None:
36 # TODO: Should check that input_shape[1:] part doesn't contain -1 elements
37 axis = get_canonical_axis_index(input_shape, node.axis)
38 end_axis = node.end_axis if node.has('end_axis') else -1
39 end_axis = get_canonical_axis_index(input_shape, end_axis)
40 prod_axes = np.prod(input_shape[axis: end_axis + 1])
41 node.out_node(0).shape = np.array([*input_shape[0: axis], prod_axes, *input_shape[end_axis + 1:]], dtype=np.int64)
42 log.debug('input_shape: {}, output_shape: {}'.format(input_shape, node.out_node().shape))