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 extensions.ops.argmax import ArgMaxOp
22 from mo.graph.graph import Node
23 from mo.utils.unittest.graph import build_graph
25 nodes_attributes = {'node_1': {'type': 'Identity', 'kind': 'op'},
26 'argmax': {'type': 'ArgMax', 'kind': 'op'},
27 'node_3': {'type': 'Identity', 'kind': 'op'},
28 'op_output': { 'kind': 'op', 'op': 'OpOutput'}
32 class TestArgMaxOp(unittest.TestCase):
33 def test_caffe_argmax_axis(self):
34 graph = build_graph(nodes_attributes,
35 [('node_1', 'argmax'),
37 ('node_3', 'op_output')
39 {'node_3': {'shape': None},
40 'node_1': {'shape': np.array([1, 3, 1025, 2049])},
48 argmax_node = Node(graph, 'argmax')
49 ArgMaxOp.argmax_infer(argmax_node)
50 exp_shape = np.array([1, 3, 100, 2049])
51 res_shape = graph.node['node_3']['shape']
52 for i in range(0, len(exp_shape)):
53 self.assertEqual(exp_shape[i], res_shape[i])
55 def test_caffe_argmax_axis_negative(self):
56 graph = build_graph(nodes_attributes,
57 [('node_1', 'argmax'),
59 ('node_3', 'op_output')
61 {'node_3': {'shape': None},
62 'node_1': {'shape': np.array([1, 3, 1025, 2049])},
70 argmax_node = Node(graph, 'argmax')
71 ArgMaxOp.argmax_infer(argmax_node)
72 exp_shape = np.array([1, 3, 1025, 100])
73 res_shape = graph.node['node_3']['shape']
74 self.assertEqual(argmax_node.axis, 3)
75 for i in range(0, len(exp_shape)):
76 self.assertEqual(exp_shape[i], res_shape[i])
78 def test_caffe_argmax_no_axis(self):
79 graph = build_graph(nodes_attributes,
80 [('node_1', 'argmax'),
82 ('node_3', 'op_output')
84 {'node_3': {'shape': None},
85 'node_1': {'shape': np.array([1, 3, 1025, 2049])},
92 argmax_node = Node(graph, 'argmax')
93 ArgMaxOp.argmax_infer(argmax_node)
94 exp_shape = np.array([1, 2, 100, 1])
95 res_shape = graph.node['node_3']['shape']
96 for i in range(0, len(exp_shape)):
97 self.assertEqual(exp_shape[i], res_shape[i])
99 def test_caffe_argmax_extend_shape(self):
100 graph = build_graph(nodes_attributes,
101 [('node_1', 'argmax'),
102 ('argmax', 'node_3'),
103 ('node_3', 'op_output')
105 {'node_3': {'shape': None},
106 'node_1': {'shape': np.array([1, 3])},
113 argmax_node = Node(graph, 'argmax')
114 ArgMaxOp.argmax_infer(argmax_node)
115 exp_shape = np.array([1, 2, 100])
116 res_shape = graph.node['node_3']['shape']
117 for i in range(0, len(exp_shape)):
118 self.assertEqual(exp_shape[i], res_shape[i])
120 def test_caffe_argmax_out_max_val_false(self):
121 graph = build_graph(nodes_attributes,
122 [('node_1', 'argmax'),
123 ('argmax', 'node_3'),
124 ('node_3', 'op_output')
126 {'node_3': {'shape': None},
127 'node_1': {'shape': np.array([1, 3])},
129 'out_max_val': False,
134 argmax_node = Node(graph, 'argmax')
135 ArgMaxOp.argmax_infer(argmax_node)
136 exp_shape = np.array([1, 1, 100])
137 res_shape = graph.node['node_3']['shape']
138 for i in range(0, len(exp_shape)):
139 self.assertEqual(exp_shape[i], res_shape[i])
141 def test_caffe_argmax_no_shape(self):
142 graph = build_graph(nodes_attributes,
143 [('node_1', 'argmax'),
144 ('argmax', 'node_3'),
145 ('node_3', 'op_output')
147 {'node_3': {'shape': None},
148 'node_1': {'shape': None},
150 'out_max_val': False,
155 argmax_node = Node(graph, 'argmax')
156 ArgMaxOp.argmax_infer(argmax_node)
157 res_shape = graph.node['node_3']['shape']
158 self.assertIsNone(res_shape)