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.
18 from unittest.mock import patch
20 from extensions.front.caffe.proposal_python_ext import ProposalPythonFrontExtractor
21 from extensions.ops.proposal import ProposalOp
22 from mo.utils.unittest.extractors import FakeMultiParam
23 from mo.utils.unittest.graph import FakeNode
24 from mo.ops.op import Op
27 class FakeProposalPythonProtoLayer:
28 def __init__(self, val):
29 self.python_param = val
32 class TestProposalPythonExt(unittest.TestCase):
35 Op.registered_ops['Proposal'] = ProposalOp
37 def test_proposal_no_pb_no_ml(self):
38 self.assertRaises(AttributeError, ProposalPythonFrontExtractor.extract, None)
40 @patch('mo.front.caffe.extractors.utils.merge_attrs')
41 def test_proposal_ext_ideal_numbers(self, merge_attrs):
43 'param_str': "'feat_stride': 16"
45 merge_attrs.return_value = params
47 fake_pl = FakeProposalPythonProtoLayer(FakeMultiParam(params))
48 fake_node = FakeNode(fake_pl, None)
50 ProposalPythonFrontExtractor.extract(fake_node)
62 'infer': ProposalOp.proposal_infer
65 for key in exp_res.keys():
66 self.assertEqual(fake_node[key], exp_res[key])
68 @patch('mo.front.caffe.extractors.utils.merge_attrs')
69 def test_proposal_ext_scales(self, merge_attrs):
71 'param_str': "'feat_stride': 16, 'scales': [1,2,3], 'ratios':[5, 6,7]"
73 merge_attrs.return_value = params
75 fake_pl = FakeProposalPythonProtoLayer(FakeMultiParam(params))
76 fake_node = FakeNode(fake_pl, None)
78 ProposalPythonFrontExtractor.extract(fake_node)
90 'infer': ProposalOp.proposal_infer
93 for key in exp_res.keys():
94 self.assertEqual(fake_node[key], exp_res[key])
96 @patch('mo.front.caffe.extractors.utils.merge_attrs')
97 def test_proposal_ext_scale(self, merge_attrs):
99 'param_str': "'feat_stride': 16, 'scale': [1,2,3], 'ratio':[5, 6,7]"
101 merge_attrs.return_value = params
103 fake_pl = FakeProposalPythonProtoLayer(FakeMultiParam(params))
104 fake_node = FakeNode(fake_pl, None)
106 ProposalPythonFrontExtractor.extract(fake_node)
115 'pre_nms_topn': 6000,
116 'post_nms_topn': 300,
118 'infer': ProposalOp.proposal_infer
121 for key in exp_res.keys():
122 self.assertEqual(fake_node[key], exp_res[key])