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.common.layout import get_width_dim, get_height_dim
20 from mo.front.extractor import attr_getter
21 from mo.graph.graph import Node, Graph
22 from mo.ops.op import Op
28 def __init__(self, graph: Graph, attrs: dict):
33 'max_size': np.array([]),
34 'min_size': np.array([]),
35 'aspect_ratio': np.array([]),
38 'infer': PriorBoxOp.priorbox_infer
40 super().__init__(graph, mandatory_props, attrs)
42 def supported_attrs(self):
59 def backend_attrs(self):
65 ('min_size', lambda node: attr_getter(node, 'min_size')),
66 ('max_size', lambda node: attr_getter(node, 'max_size')),
67 ('aspect_ratio', lambda node: attr_getter(node, 'aspect_ratio')),
68 ('variance', lambda node: attr_getter(node, 'variance')),
72 def priorbox_infer(node: Node):
73 layout = node.graph.graph['layout']
74 data_shape = node.in_node(0).shape
76 # calculate all different aspect_ratios (the first one is always 1)
77 # in aspect_ratio 1/x values will be added for all except 1 if flip is True
79 ar_seen.extend(node.aspect_ratio.copy())
81 for s in node.aspect_ratio:
84 ar_seen = np.unique(np.array(ar_seen).round(decimals=6))
87 if len(node.min_size) > 0:
88 num_ratios = len(ar_seen) * len(node.min_size)
90 num_ratios = num_ratios + len(node.max_size)
92 res_prod = data_shape[get_height_dim(layout, 4)] * data_shape[get_width_dim(layout, 4)] * num_ratios * 4
93 node.out_node(0).shape = np.array([1, 2, res_prod], dtype=np.int64)