Publishing 2019 R1 content
[platform/upstream/dldt.git] / model-optimizer / mo / front / mxnet / extractors / multibox_prior.py
1 """
2  Copyright (c) 2018-2019 Intel Corporation
3
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
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
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.
15 """
16
17 from mo.front.common.partial_infer.multi_box_prior import multi_box_prior_infer_mxnet
18 from mo.utils.error import Error
19
20
21 def multi_box_prior_ext(attr):
22     min_size = attr.tuple("sizes", float, (1, 1))
23     offset_y, offset_x = attr.tuple("offsets", float, (0.5, 0.5))
24     clip = 0 if not attr.bool("clip", False) else 1
25     aspect_ratio = attr.tuple("ratios", float, None)
26     step_y, step_x = attr.tuple("steps", float, (-1, -1))
27     if len(aspect_ratio) == 0:
28         aspect_ratio = [1.0]
29
30     node_attrs = {
31         'type': 'PriorBox',
32         'img_size': 0,
33         'img_h': 0,
34         'img_w': 0,
35         'step': step_x,
36         'step_h': 0,
37         'step_w': 0,
38         'offset': offset_x,
39         'variance': '0.100000,0.100000,0.200000,0.200000',
40         'flip': 0,
41         'clip': clip,
42         'min_size': min_size,
43         'max_size': '',
44         'aspect_ratio': list(aspect_ratio),
45         'scale_all_sizes': 0,
46         'infer': multi_box_prior_infer_mxnet
47     }
48     return node_attrs