Add a section of how to link IE with CMake project (#99)
[platform/upstream/dldt.git] / model-optimizer / extensions / front / mxnet / add_input_data_to_prior_boxes_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 import numpy as np
20 from argparse import Namespace
21
22 from mo.graph.graph import Node
23 from extensions.front.mxnet.add_input_data_to_prior_boxes import AddInputDataToPriorBoxes
24 from mo.utils.unittest.graph import build_graph
25
26
27 class TestMxnetPipeline(unittest.TestCase):
28     def test_mxnet_pipeline_1(self):
29         graph = build_graph(
30             {'data': {'type': 'Identity', 'value': None, 'kind': 'op', 'op': 'Placeholder'},
31              'node_2': {'type': 'Identity', 'value': None, 'kind': 'op'},
32              'node_multi_box': {'type': '_contrib_MultiBoxPrior', 'kind': 'op', 'op': '_contrib_MultiBoxPrior'},
33              },
34             [('data', 'node_2'),
35              ('node_2', 'node_multi_box')],
36             {
37                 'data': {'shape': np.array([1, 3, 227, 227])},
38                 'node_2': {'shape': np.array([1, 3, 10, 10])},
39             })
40
41         graph.graph['cmd_params'] = Namespace(input=None)
42         AddInputDataToPriorBoxes().find_and_replace_pattern(graph)
43         node_multi_box = Node(graph, 'node_multi_box')
44
45         node_input1 = node_multi_box.in_node(0)
46         node_input2 = node_multi_box.in_node(1)
47         self.assertEqual(node_input1.name, 'node_2')
48         self.assertEqual(node_input2.name, 'data')
49
50     def test_mxnet_pipeline_2(self):
51         graph = build_graph(
52             {'node_1': {'type': 'Identity', 'value': None, 'kind': 'op', 'op': 'Placeholder'},
53              'node_2': {'type': 'Identity', 'value': None, 'kind': 'op'},
54              'node_multi_box': {'type': '_contrib_MultiBoxPrior', 'kind': 'op', 'op': '_contrib_MultiBoxPrior'},
55              },
56             [('node_1', 'node_2'),
57              ('node_2', 'node_multi_box')],
58             {
59                 'node_1': {'shape': np.array([1, 3, 227, 227])},
60                 'node_2': {'shape': np.array([1, 3, 10, 10])},
61             })
62
63         graph.graph['cmd_params'] = Namespace(input='node_1')
64         AddInputDataToPriorBoxes().find_and_replace_pattern(graph)
65         node_multi_box = Node(graph, 'node_multi_box')
66
67         node_input1 = node_multi_box.in_node(0)
68         node_input2 = node_multi_box.in_node(1)
69         self.assertEqual(node_input1.name, 'node_2')
70         self.assertEqual(node_input2.name, 'node_1')