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.priorbox import PriorBoxOp
22 from mo.graph.graph import Node
23 from mo.utils.unittest.graph import build_graph
25 nodes_attributes = {'node_1': {'type': 'Identity', 'value': None, 'kind': 'data'},
26 'pb': {'type': 'PriorBox', 'value': None, 'kind': 'op'},
27 'node_3': {'type': 'Identity', 'value': None, 'kind': 'data'},
28 'op_output': { 'kind': 'op', 'op': 'OpOutput'}
32 class TestPriorBoxPartialInfer(unittest.TestCase):
33 def test_caffe_priorbox_infer(self):
34 graph = build_graph(nodes_attributes,
38 ('node_3', 'op_output')
41 'node_3': {'shape': None},
42 'node_1': {'shape': np.array([1, 384, 19, 19])},
44 'aspect_ratio': np.array([1]),
46 'min_size': np.array([1]),
47 'max_size': np.array([1])
50 graph.graph['layout'] = 'NCHW'
51 pb_node = Node(graph, 'pb')
52 PriorBoxOp.priorbox_infer(pb_node)
53 exp_shape = np.array([1, 2, 4 * 19 * 19 * 2])
54 res_shape = graph.node['node_3']['shape']
55 for i in range(0, len(exp_shape)):
56 self.assertEqual(exp_shape[i], res_shape[i])
58 def test_caffe_priorbox_flip_infer(self):
59 graph = build_graph(nodes_attributes,
63 ('node_3', 'op_output')
66 'node_3': {'shape': None},
67 'node_1': {'shape': np.array([1, 384, 19, 19])},
69 'aspect_ratio': np.array([1, 2, 0.5]),
71 'min_size': np.array([1]),
72 'max_size': np.array([1])
75 graph.graph['layout'] = 'NCHW'
76 pb_node = Node(graph, 'pb')
77 PriorBoxOp.priorbox_infer(pb_node)
78 exp_shape = np.array([1, 2, 4 * 19 * 19 * 4])
79 res_shape = graph.node['node_3']['shape']
80 for i in range(0, len(exp_shape)):
81 self.assertEqual(exp_shape[i], res_shape[i])
83 def test_tf_priorbox_infer(self):
84 graph = build_graph(nodes_attributes,
88 ('node_3', 'op_output')
91 'node_3': {'shape': None},
92 'node_1': {'shape': np.array([1, 19, 19, 384])},
94 'aspect_ratio': np.array([1]),
96 'min_size': np.array([1]),
97 'max_size': np.array([1])
100 graph.graph['layout'] = 'NHWC'
101 pb_node = Node(graph, 'pb')
102 PriorBoxOp.priorbox_infer(pb_node)
103 exp_shape = np.array([1, 2, 4 * 19 * 19 * 2])
104 res_shape = graph.node['node_3']['shape']
105 for i in range(0, len(exp_shape)):
106 self.assertEqual(exp_shape[i], res_shape[i])
108 def test_tf_priorbox_flip_infer(self):
109 graph = build_graph(nodes_attributes,
113 ('node_3', 'op_output')
116 'node_3': {'shape': None},
117 'node_1': {'shape': np.array([1, 19, 19, 384])},
119 'aspect_ratio': np.array([1, 2, 0.5]),
121 'min_size': np.array([1]),
122 'max_size': np.array([1])
125 graph.graph['layout'] = 'NHWC'
126 pb_node = Node(graph, 'pb')
127 PriorBoxOp.priorbox_infer(pb_node)
128 exp_shape = np.array([1, 2, 4 * 19 * 19 * 4])
129 res_shape = graph.node['node_3']['shape']
130 for i in range(0, len(exp_shape)):
131 self.assertEqual(exp_shape[i], res_shape[i])