Publishing 2019 R1 content
[platform/upstream/dldt.git] / model-optimizer / extensions / ops / correlation_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
21 from extensions.ops.correlation import CorrelationOp
22 from mo.graph.graph import Node
23 from mo.utils.unittest.graph import build_graph
24
25 nodes_attributes = {'node_1': {'type': 'Identity', 'kind': 'op'},
26                     'node_2': {'type': 'Identity', 'kind': 'op'},
27                     'corr': {'type': 'Correlation', 'kind': 'op'},
28                     'node_3': {'type': 'Identity', 'kind': 'op'},
29                     'op_output': {'kind': 'op', 'op': 'OpOutput'}
30                     }
31
32
33 class TestConcatPartialInfer(unittest.TestCase):
34     def test_tf_concat_infer(self):
35         graph = build_graph(nodes_attributes,
36                             [
37                                 ('node_1', 'corr'),
38                                 ('node_2', 'corr'),
39                                 ('corr', 'node_3'),
40                                 ('node_3', 'op_output')
41                             ],
42                             {
43                                 'node_3': {'shape': None},
44                                 'node_1': {'shape': np.array([1, 3, 227, 227])},
45                                 'node_2': {'shape': np.array([1, 3, 227, 227])},
46                                 'corr': {'pad': 20,
47                                          'kernel_size': 1,
48                                          'max_displacement': 20,
49                                          'stride_1': 1,
50                                          'stride_2': 2,
51                                          'single_direction': 0,
52                                          'do_abs': False,
53                                          'correlation_type': 0}
54                             })
55
56         corr_node = Node(graph, 'corr')
57         CorrelationOp.corr_infer(corr_node)
58         exp_shape = np.array([1, 441, 227, 227])
59         res_shape = graph.node['node_3']['shape']
60         for i in range(0, len(exp_shape)):
61             self.assertEqual(exp_shape[i], res_shape[i])