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.
18 from mo.front.common.extractors.utils import layout_attrs
19 from mo.front.extractor import FrontExtractorOp
20 from mo.front.kaldi.loader.utils import read_token_value, collect_until_whitespace, collect_until_token, \
21 read_binary_integer32_token, find_next_tag, read_placeholder
22 from mo.ops.pooling import Pooling
23 from mo.utils.error import Error
26 class MaxPoolingComponentFrontExtractor(FrontExtractorOp):
27 op = 'maxpoolingcomponent'
33 collect_until_token(pb, b'<PoolSize>')
34 kernel = read_binary_integer32_token(pb)
35 tag = find_next_tag(pb)
36 if tag == '<PoolStep>':
37 read_placeholder(pb, 1)
38 stride = read_binary_integer32_token(pb)
40 pool_stride = read_token_value(pb, b'<PoolStride>')
41 elif tag == '<PoolStride>':
44 read_placeholder(pb, 1)
45 pool_stride = read_binary_integer32_token(pb)
47 raise Error('Can not extract parameters for {}'.format(node))
50 'window': np.array([1, 1, 1, kernel], dtype=np.int64),
51 'stride': np.array([1, 1, stride, stride], dtype=np.int64),
52 'pool_stride': pool_stride,
53 'pool_step': pool_step,
54 'pad': np.array([[0, 0], [0, 0], [0, 0], [0, 0]], dtype=np.int64),
55 'pad_spatial_shape': np.array([[0, 0], [0, 0]], dtype=np.int64),
58 mapping_rule.update(layout_attrs())
59 Pooling.update_node_stat(node, mapping_rule)
60 return __class__.enabled