Added unit tests and readme for model optimizer (#79)
[platform/upstream/dldt.git] / model-optimizer / extensions / front / onnx / pad_ext_test.py
1 """
2  Copyright (c) 2018 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 onnx
18
19 from extensions.front.onnx.pad_ext import PadFrontExtractor
20 from mo.utils.unittest.extractors import PB, BaseExtractorsTestingClass
21
22
23 class TestPad(BaseExtractorsTestingClass):
24     @staticmethod
25     def _create_node(pads=None, value=None, mode=None):
26         if pads is None:
27             pads = [1, 2, 3, 4]
28         if value is None:
29             value = 0.0
30         if mode is None:
31             mode = 'constant'
32         pb = onnx.helper.make_node(
33             'Pad',
34             pads=pads,
35             mode=mode,
36             value=value,
37             inputs=['a'],
38             outputs=['b']
39         )
40         node = PB({'pb': pb})
41         return node
42
43     def test_ok(self):
44         node = self._create_node()
45         PadFrontExtractor.extract(node)
46         self.res = node
47
48         self.expected = {
49             'pads': [[1, 3], [2, 4]],
50             'mode': 'constant',
51             'fill_value': 0
52         }
53
54         self.compare()
55
56     def test_reflect(self):
57         node = self._create_node(mode='reflect')
58         PadFrontExtractor.extract(node)
59         self.res = node
60
61         self.expected = {
62             'pads': [[1, 3], [2, 4]],
63             'mode': 'reflect',
64             'fill_value': 0
65         }
66
67         self.compare()
68
69     def test_non_zero_fill_value(self):
70         node = self._create_node(value=1.0)
71         PadFrontExtractor.extract(node)
72         self.res = node
73
74         self.expected = {
75             'pads': [[1, 3], [2, 4]],
76             'mode': 'constant',
77             'fill_value': 1.0
78         }
79
80         self.compare()