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.
21 from mo.front.common.partial_infer.concat import concat_infer
22 from mo.graph.graph import Node
23 from mo.utils.unittest.graph import build_graph
25 nodes_attributes = {'node_1': {'kind': 'data', 'value': None},
26 'node_2': {'kind': 'data', 'value': None},
27 'concat': {'type': 'Concat', 'kind': 'op'},
28 'node_3': {'kind': 'data'},
29 'op_output': { 'kind': 'op', 'op': 'OpOutput'},
33 class TestConcatPartialInfer(unittest.TestCase):
34 def test_tf_concat_infer(self):
35 graph = build_graph(nodes_attributes,
36 [('node_1', 'concat'),
39 ('node_3', 'op_output')
41 {'node_3': {'shape': None},
42 'node_1': {'shape': np.array([1, 3, 227, 227])},
43 'node_2': {'shape': np.array([1, 3, 227, 227])},
47 concat_node = Node(graph, 'concat')
48 concat_infer(concat_node)
49 exp_shape = np.array([1, 3, 454, 227])
50 res_shape = graph.node['node_3']['shape']
51 for i in range(0, len(exp_shape)):
52 self.assertEqual(exp_shape[i], res_shape[i])
54 def test_tf_concat_infer_negative_axis(self):
55 graph = build_graph(nodes_attributes,
56 [('node_1', 'concat'),
59 ('node_3', 'op_output')
61 {'node_3': {'shape': None},
62 'node_1': {'shape': np.array([1, 3, 227, 227])},
63 'node_2': {'shape': np.array([1, 3, 227, 227])},
64 'concat': {'axis': -1}
67 concat_node = Node(graph, 'concat')
68 concat_infer(concat_node)
69 exp_shape = np.array([1, 3, 227, 454])
70 res_shape = graph.node['node_3']['shape']
71 for i in range(0, len(exp_shape)):
72 self.assertEqual(exp_shape[i], res_shape[i])
74 def test_tf_concat_infer_not_match(self):
75 graph = build_graph(nodes_attributes,
76 [('node_1', 'concat'),
79 ('node_3', 'op_output')
81 {'node_3': {'shape': None},
82 'node_1': {'shape': np.array([1, 3, 227, 227])},
83 'node_2': {'shape': np.array([1, 2, 227, 227])},
87 concat_node = Node(graph, 'concat')
88 concat_infer(concat_node)
89 res_shape = graph.node['node_3']['shape']
90 self.assertIsNone(res_shape)
92 def test_tf_concat_infer_no_shape(self):
93 graph = build_graph(nodes_attributes,
94 [('node_1', 'concat'),
97 ('node_3', 'op_output')
99 {'node_3': {'shape': None},
100 'node_1': {'shape': np.array([1, 3, 227, 227])},
101 'node_2': {'shape': None},
102 'concat': {'axis': 2}
105 concat_node = Node(graph, 'concat')
106 concat_infer(concat_node)
107 res_shape = graph.node['node_3']['shape']
108 self.assertIsNone(res_shape)