2 Copyright (c) 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.
22 from extensions.front.onnx.priorbox_ext import PriorBoxFrontExtractor
23 from extensions.ops.priorbox import PriorBoxOp
24 from mo.ops.op import Op
25 from mo.utils.unittest.extractors import PB
28 class TestPriorBoxExt(unittest.TestCase):
30 def _create_priorbox_node(aspect_ratio=[], min_size=np.array([]), max_size=np.array([]),
31 flip=False, clip=False, variance=None, img_size=0, img_h=0,
32 img_w=0, step=0, step_h=0, step_w=0, offset=0):
33 pb = onnx.helper.make_node(
37 aspect_ratio=aspect_ratio,
57 Op.registered_ops['PriorBox'] = PriorBoxOp
59 def test_priorbox_no_pb_no_ml(self):
60 self.assertRaises(AttributeError, PriorBoxFrontExtractor.extract, None)
62 def test_priorbox_ext_ideal_numbers(self):
63 node = self._create_priorbox_node(aspect_ratio=np.array([2, 3], dtype=np.float),
64 variance=np.array([0.2, 0.3, 0.2, 0.3]),
65 img_size=300, step=5.0, offset=0.6, flip=True)
67 PriorBoxFrontExtractor.extract(node)
74 'aspect_ratio': np.array([2, 3], dtype=np.float),
75 'variance': [0.2, 0.3, 0.2, 0.3],
85 for key in exp_res.keys():
86 if key in ['variance', 'aspect_ratio', 'step_h', 'step_w', 'offset']:
87 np.testing.assert_almost_equal(node[key], exp_res[key])
89 self.assertEqual(node[key], exp_res[key])