Publishing 2019 R1 content
[platform/upstream/dldt.git] / model-optimizer / extensions / front / caffe / proposal_python_ext.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 import logging as log
17
18 from mo.front.extractor import CaffePythonFrontExtractorOp
19 from mo.ops.op import Op
20 from mo.utils.error import Error
21
22
23 class ProposalPythonFrontExtractor(CaffePythonFrontExtractorOp):
24     op = 'rpn.proposal_layer.ProposalLayer'
25     enabled = True
26
27     @staticmethod
28     def extract(node):
29         param = node.pb.python_param
30         attrs = CaffePythonFrontExtractorOp.parse_param_str(param.param_str)
31         update_attrs = {
32             'feat_stride': 16,
33             'base_size': 16,
34             'min_size': 16,
35             'ratio': [0.5, 1, 2],
36             'scale': [8, 16, 32],
37             'pre_nms_topn': 6000,
38             'post_nms_topn': 300,
39             'nms_thresh': 0.7
40         }
41         if 'ratios' in attrs and 'ratio' in attrs :
42             log.error('Both ratios and ratio found, value of ratios will be used', extra={'is_warning':True})
43         if 'scales' in attrs and 'scale' in attrs :
44             log.error('Both scales and scale found, value of scales will be used', extra={'is_warning':True})
45
46         if 'ratios' in attrs:
47             attrs['ratio']=attrs['ratios']
48             del attrs['ratios']
49         if 'scales' in attrs:
50             attrs['scale']=attrs['scales']
51             del attrs['scales']
52
53         update_attrs.update(attrs)
54         CaffePythonFrontExtractorOp.check_param(Op.get_op_class_by_name('Proposal'), update_attrs)
55         Op.get_op_class_by_name('Proposal').update_node_stat(node, update_attrs)
56         return __class__.enabled