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.caffe.extractors.utils import get_spatial_attr
19 from mo.front.common.extractors.utils import layout_attrs
20 from mo.front.extractor import FrontExtractorOp
21 from mo.ops.pooling import Pooling
24 class PoolingFrontExtractor(FrontExtractorOp):
31 param = proto_layer.pooling_param
38 global_pooling = False
40 if hasattr(param, 'global_pooling') and param.global_pooling:
41 global_pooling = param.global_pooling
43 kernel = get_spatial_attr(kernel, 'kernel_size', 'kernel', param)
44 padding = get_spatial_attr(padding, 'pad', 'pad', param)
45 stride = get_spatial_attr(stride, 'stride', 'stride', param)
54 raise ValueError('Unknown Pooling Method!')
56 pooling_convention = 'full' # for Caffe rounding type should be ceil
59 if hasattr(param, 'ceil_mode') and not param.ceil_mode:
60 # If pooling has ceil_mode and ceil_mode is False using floor for rounding shapes in partial_infer
61 pooling_convention = 'valid'
65 'window': np.array([1, 1, kernel[1], kernel[0]], dtype=np.int64),
66 'stride': np.array([1, 1, stride[1], stride[0]], dtype=np.int64),
67 'pad': np.array([[0, 0], [0, 0], [padding[1], padding[1]], [padding[0], padding[0]]], dtype=np.int64),
68 'pad_spatial_shape': np.array([[padding[1], padding[1]], [padding[0], padding[0]]], dtype=np.int64),
69 'pool_method': method,
70 'exclude_pad': exclude_pad,
71 'global_pool': global_pooling,
72 'output_spatial_shape': None,
76 attrs.update(layout_attrs())
77 attrs['pooling_convention'] = pooling_convention
79 # update the attributes of the node
80 Pooling.update_node_stat(node, attrs)
81 return __class__.enabled