2 Copyright (c) 2018 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.
22 from extensions.front.onnx.crop_ext import CropFrontExtractor
23 from mo.utils.unittest.graph import build_graph
24 from mo.graph.graph import Node
27 class CropONNXExtractorTest(unittest.TestCase):
29 def _create_node(attrs: dict):
30 pb = onnx.helper.make_node("Crop", ["X"], ["Y"], **attrs)
31 graph = build_graph({'node_0': {'pb': pb}}, [])
32 return Node(graph, 'node_0')
36 # Commonly used attributes in the tests
37 # Each test takes these ones and then adds/modifies/deletes particular fields
39 # test input ONNX attributes
41 border=[5, 10, 15, 20],
43 # reference output Node attributes
46 crop_begin=np.array([10, 5]),
47 crop_end=np.array([20, 15]),
54 node = __class__._create_node(inp)
55 CropFrontExtractor.extract(node)
56 return node.graph.node[node.id]
58 def _match(self, out, ref):
59 for key in ref.keys():
60 status = out[key] == ref[key]
61 if type(status) in [list, np.ndarray]:
62 status = np.all(status)
63 self.assertTrue(status, 'Mismatch for field {}, observed: {}, expected: {}'.format(key, out[key], ref[key]))
65 def test_default(self):
66 inp, ref = self._base_attrs()
67 out = self._extract(inp)
70 def test_with_scale(self):
71 inp, ref = self._base_attrs()
72 inp['scale'] = np.array([34, 50])
76 ref['dim'] = np.array([34, 50])
77 ref['offset'] = np.array([10, 5])
79 out = self._extract(inp)