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.partial_infer.utils import convert_tf_padding_to_str
19 from mo.front.extractor import FrontExtractorOp
20 from mo.front.tf.extractors.utils import tf_data_format_spatial, tf_data_format_channel, tf_data_format_batch, \
22 from mo.ops.pooling import Pooling
25 class AvgPoolFrontExtractor(FrontExtractorOp):
31 attrs = create_pooling_attrs(node, 'avg')
32 attrs.update({'op': __class__.op})
33 # update the attributes of the node
34 Pooling.update_node_stat(node, attrs)
35 return __class__.enabled
38 class MaxPoolFrontExtractor(FrontExtractorOp):
44 attrs = create_pooling_attrs(node, 'max')
45 attrs.update({'op': __class__.op})
46 # update the attributes of the node
47 Pooling.update_node_stat(node, attrs)
48 return __class__.enabled
51 class MaxPool3DFrontExtractor(FrontExtractorOp):
57 attrs = create_pooling_attrs(node, 'max')
58 attrs.update({'op': __class__.op})
59 # update the attributes of the node
60 Pooling.update_node_stat(node, attrs)
61 return __class__.enabled
64 class AvgPool3DFrontExtractor(FrontExtractorOp):
70 attrs = create_pooling_attrs(node, 'avg')
71 attrs.update({'op': __class__.op})
72 # update the attributes of the node
73 Pooling.update_node_stat(node, attrs)
74 return __class__.enabled
77 def create_pooling_attrs(node, pool_method):
78 data_format = node.pb.attr["data_format"]
81 'auto_pad': convert_tf_padding_to_str(node.pb.attr['padding']),
82 'window': tf_int_list(node.pb.attr["ksize"].list),
83 'spatial_dims': tf_data_format_spatial(data_format),
84 'pad': None, # will be inferred when input shape is known
85 'stride': tf_int_list(node.pb.attr["strides"].list),
86 'pad_spatial_shape': None,
87 'output_spatial_shape': None,
88 'pool_method': pool_method,
90 'layout': data_format.s.decode(),
91 'exclude_pad': 'true',