Publishing 2019 R1 content
[platform/upstream/dldt.git] / model-optimizer / extensions / front / mxnet / custom_test.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 import unittest
18
19 from extensions.front.mxnet.custom import CustomFrontExtractorOp
20 from mo.utils.unittest.graph import build_graph
21 from mo.front.extractor import FrontExtractorOp, MXNetCustomFrontExtractorOp
22 from mo.graph.graph import Node
23
24 attrs = {'test_attr': 1}
25
26
27 class FakeExtractor(MXNetCustomFrontExtractorOp):
28     @staticmethod
29     def extract(node: Node):
30         return True, attrs
31
32
33 class TestCustomFrontExtractorOp(unittest.TestCase):
34     @classmethod
35     def setUpClass(cls):
36         FrontExtractorOp.registered_ops['Custom'] = CustomFrontExtractorOp
37
38     def test_extract_custom_layer(self):
39         graph = build_graph(
40             {'node_1': {'type': 'Identity', 'value': None, 'kind': 'op', 'op': 'Placeholder'},
41              'node_2': {'type': 'Identity', 'value': None, 'kind': 'op'},
42              'node_custom': {'type': 'Custom', 'value': None, 'kind': 'op', 'op': 'Custom', },
43              'node_3': {'type': 'Identity', 'value': None, 'kind': 'op'},
44              },
45             [('node_1', 'node_2'),
46              ('node_2', 'node_custom'),
47              ('node_custom', 'node_3'),
48              ],
49             {
50                 'node_custom': {'symbol_dict': {'attrs': {'op_type': 'test_type'}}},
51             })
52
53         custom_node = Node(graph, 'node_custom')
54         custom_op = FakeExtractor()
55         supported, op_attrs = custom_op.extract(custom_node)
56         self.assertTrue(supported)
57         self.assertEquals(op_attrs, attrs)