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.front.caffe.pooling_ext import PoolingFrontExtractor
22 from mo.front.common.extractors.utils import layout_attrs
23 from mo.ops.pooling import Pooling
24 from mo.utils.unittest.extractors import PB, FakeMultiParam
28 def __init__(self, val):
29 self.pooling_param = val
32 class TestPooling(unittest.TestCase):
33 def test_pooling_ext_global(self):
42 node = PB({'pb': FakeProtoLayer(FakeMultiParam(params))})
43 PoolingFrontExtractor.extract(node)
46 'window': np.array([1, 1, 0, 0], dtype=np.int64),
47 'stride': np.array([1, 1, 1, 1], dtype=np.int64),
48 'pad': np.array([[0, 0], [0, 0], [0, 0], [0, 0]], dtype=np.int64),
49 'pad_spatial_shape': np.array([[0, 0], [0, 0]], dtype=np.int64),
51 'exclude_pad': 'true',
52 'infer': Pooling.infer,
54 'output_spatial_shape': None,
55 'pooling_convention': 'full',
56 'rounding_type': 'ceil'
59 exp_res.update(layout_attrs())
60 for i in exp_res.keys():
61 if i in ('window', 'stride',
62 'pad', 'pad_spatial_shape',
63 'spatial_dims', 'batch_dims',
65 np.testing.assert_array_equal(res[i], exp_res[i])
67 self.assertEqual(res[i], exp_res[i])
69 def test_pooling_ext(self):
78 node = PB({'pb': FakeProtoLayer(FakeMultiParam(params))})
79 PoolingFrontExtractor.extract(node)
82 'window': np.array([1, 1, 1, 1], dtype=np.int64),
83 'stride': np.array([1, 1, 2, 2], dtype=np.int64),
84 'pad': np.array([[0, 0], [0, 0], [3, 3], [3, 3]], dtype=np.int64),
85 'pad_spatial_shape': np.array([[3, 3], [3, 3]], dtype=np.int64),
87 'exclude_pad': 'false',
88 'infer': Pooling.infer,
90 'output_spatial_shape': None,
91 'pooling_convention': 'valid'
93 exp_res.update(layout_attrs())
94 for i in exp_res.keys():
95 if i in ('window', 'stride',
96 'pad', 'pad_spatial_shape',
97 'spatial_dims', 'batch_dims',
99 np.testing.assert_array_equal(res[i], exp_res[i])
101 self.assertEqual(res[i], exp_res[i])
103 def test_pooling_ext_exception(self):
111 node = PB({'pb': FakeProtoLayer(FakeMultiParam(params))})
112 self.assertRaises(ValueError, PoolingFrontExtractor.extract, node)