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.
20 from mo.front.common.layout import get_batch_dim, get_features_dim, get_height_dim, get_width_dim, shape_for_layout
21 from mo.graph.graph import Node
24 def roipooling_infer(node: Node):
26 Sets shape of output node according specified parameters input blobs and node
27 Sets number from the first input blob, channels from the second one, height and width are specified
32 shapes = [node.in_node(i).shape for i in range(len(node.in_nodes()))]
33 if any(s is None for s in shapes):
35 if len(node.in_nodes()) == 4: # TensorFlow case of CropAndResize operation
36 crop_size = node.in_node(3).value
38 log.error('The ROIPooling size is not known for node {}'.format(node.soft_get('name')))
40 if not isinstance(crop_size, np.ndarray) or len(crop_size) != 2:
41 log.error('The ROIPooling size is should have 2 elements for node {}'.format(node.soft_get('name')))
42 node.pooled_h = crop_size[0]
43 node.pooled_w = crop_size[1]
44 node.graph.remove_edge(node.in_node(3).id, node.id)
45 node.graph.remove_edge(node.in_node(2).id, node.id)
47 layout = node.graph.graph['layout']
48 assert len(layout) == 4
50 node.out_node().shape = shape_for_layout(layout,
51 batch=shapes[1][get_batch_dim(layout, 4)],
52 features=shapes[0][get_features_dim(layout, 4)],