Publishing 2019 R1 content
[platform/upstream/dldt.git] / model-optimizer / mo / front / kaldi / extractors / max_pooling_ext_test.py
1 """
2  Copyright (c) 2018-2019 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 from mo.front.kaldi.extractors.common_ext_test import KaldiFrontExtractorTest
18
19 from mo.front.kaldi.extractors.max_pooling_ext import MaxPoolingComponentFrontExtractor
20 from mo.front.kaldi.loader.utils_test import TestKaldiUtilsLoading
21 from mo.ops.op import Op
22 from mo.ops.pooling import Pooling
23
24
25 class MaxPoolingComponentFrontExtractorTest(KaldiFrontExtractorTest):
26     @classmethod
27     def register_op(cls):
28         Op.registered_ops['Pooling'] = Pooling
29
30     @classmethod
31     def create_pb_for_test_node(cls):
32         pb = KaldiFrontExtractorTest.write_tag_with_value('<PoolSize>', 2)
33         pb += KaldiFrontExtractorTest.write_tag_with_value('<PoolStep>', 2)
34         pb += KaldiFrontExtractorTest.write_tag_with_value('<PoolStride>', 4)
35         cls.test_node['parameters'] = TestKaldiUtilsLoading.bytesio_from(pb)
36         MaxPoolingComponentFrontExtractor.extract(cls.test_node)
37
38     def test_assertion(self):
39         self.assertRaises(AttributeError, MaxPoolingComponentFrontExtractor.extract, None)
40
41     def test_attrs(self):
42         val_attrs = {
43             'window': [1, 1, 1, 2],
44             'stride': [1, 1, 2, 2],
45             'pool_stride': 4,
46             'pad': [[[0, 0], [0, 0], [0, 0], [0, 0]]]
47         }
48         for attr in val_attrs:
49             if isinstance(val_attrs[attr], list):
50                 self.assertTrue((self.test_node[attr] == val_attrs[attr]).all())
51             else:
52                 self.assertEqual(self.test_node[attr], val_attrs[attr])