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.
19 from mo.front.caffe.extractors.utils import get_canonical_axis_index
20 from mo.front.common.layout import get_batch_dim, get_height_dim, get_width_dim, shape_for_layout
21 from mo.front.extractor import attr_getter
22 from mo.graph.graph import Node, Graph
23 from mo.ops.op import Op
26 class RegionYoloOp(Op):
29 def __init__(self, graph: Graph, attrs: Node):
35 'infer': RegionYoloOp.regionyolo_infer
37 super().__init__(graph, mandatory_props, attrs)
39 def supported_attrs(self):
51 def backend_attrs(self):
59 ('anchors', lambda node: attr_getter(node, 'anchors')),
60 ('mask', lambda node: attr_getter(node, 'mask'))
64 def regionyolo_infer(node: Node):
65 input_shape = node.in_node(0).shape
66 if input_shape is None:
68 axis = get_canonical_axis_index(input_shape, node.axis)
69 end_axis = get_canonical_axis_index(input_shape, node.end_axis)
71 node.end_axis = end_axis
73 flat_dim = np.prod(input_shape[axis: end_axis + 1])
74 node.out_node().shape = np.array([*input_shape[:axis], flat_dim, *input_shape[end_axis + 1:]])
76 layout = node.graph.graph['layout']
77 assert len(layout) == 4
79 node.out_node().shape = shape_for_layout(layout,
80 batch=input_shape[get_batch_dim(layout, 4)],
81 features=(node.classes + node.coords + 1) * len(node.mask),
82 height=input_shape[get_height_dim(layout, 4)],
83 width=input_shape[get_width_dim(layout, 4)])