Publishing 2019 R1 content
[platform/upstream/dldt.git] / model-optimizer / extensions / front / mxnet / ssd_pattern_remove_reshape_test.py
1 """
2  Copyright (c) 2017-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.ssd_pattern_remove_reshape import SsdPatternRemoveReshape
20 from mo.utils.unittest.graph import build_graph
21 from mo.graph.graph import Node
22
23
24 class TestSsdPatternRemoveReshape(unittest.TestCase):
25     def test_pattern_remove_reshape(self):
26         graph = build_graph({'node_1': {'type': 'Identity', 'kind': 'op', 'op': 'Placeholder'},
27                              'node_2': {'type': 'Identity', 'kind': 'op'},
28                              'node_multi_box_prior1': {'type': '_contrib_MultiBoxPrior', 'kind': 'op',
29                                                        'op': '_contrib_MultiBoxPrior'},
30                              'node_multi_box_prior2': {'type': '_contrib_MultiBoxPrior', 'kind': 'op',
31                                                        'op': '_contrib_MultiBoxPrior'},
32                              'node_multi_box_prior3': {'type': '_contrib_MultiBoxPrior', 'kind': 'op',
33                                                        'op': '_contrib_MultiBoxPrior'},
34                              'node_concat': {'type': 'Concat', 'kind': 'op', 'op': 'Concat'},
35                              'node_reshape': {'type': 'Reshape', 'kind': 'op', 'op': 'Reshape'},
36                              'node_3': {'type': 'Identity', 'kind': 'op'},
37                              },
38                             [('node_1', 'node_2'),
39                              ('node_2', 'node_multi_box_prior1'),
40                              ('node_2', 'node_multi_box_prior2'),
41                              ('node_2', 'node_multi_box_prior3'),
42                              ('node_multi_box_prior1', 'node_concat'),
43                              ('node_multi_box_prior2', 'node_concat'),
44                              ('node_multi_box_prior3', 'node_concat'),
45                              ('node_concat', 'node_reshape'),
46                              ('node_reshape', 'node_3'), ],
47                             {
48                                 'node_concat': {'symbol_dict': {'attrs': {'dim': 3}}},
49                             })
50
51         pattern = SsdPatternRemoveReshape()
52         pattern.find_and_replace_pattern(graph)
53         node_concat = Node(graph, 'node_concat')
54         self.assertEqual(node_concat['symbol_dict']['attrs']['dim'], 2)
55         self.assertFalse(graph.has_node('node_reshape'))
56         self.assertTrue(graph.has_edge(Node(graph, 'node_concat').id, Node(graph, 'node_3').id))