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.caffe.python_layer_extractor import PythonFrontExtractorOp
20 from mo.front.extractor import CaffePythonFrontExtractorOp
21 from mo.graph.graph import Node
22 from mo.utils.unittest.extractors import FakeMultiParam
23 from mo.utils.unittest.graph import FakeNode
26 class FakePythonProtoLayer:
27 def __init__(self, params: FakeMultiParam):
29 self.python_param = params
32 class FakePythonExtractor:
34 def extract(node: Node):
38 class TestPythonLayerExtractor(unittest.TestCase):
39 def test_python_extractor_for_op(self):
40 module = 'test_module'
42 CaffePythonFrontExtractorOp.registered_ops['{}.{}'.format(module, layer)] = \
43 lambda node: CaffePythonFrontExtractorOp.parse_param_str(node.pb.python_param.param_str)
44 params = FakeMultiParam({
47 'param_str': "'feat_stride': 16"
49 ext = PythonFrontExtractorOp.extract(FakeNode(FakePythonProtoLayer(params), None))
50 self.assertEqual({'feat_stride': 16}, ext)
52 def test_python_extractor_for_extractors(self):
53 module = 'test_module'
55 CaffePythonFrontExtractorOp.registered_ops['{}.{}'.format(module, layer)] = FakePythonExtractor
56 params = FakeMultiParam({
59 'param_str': "'feat_stride': 16"
61 self.assertTrue(PythonFrontExtractorOp.extract(FakeNode(FakePythonProtoLayer(params), None)))