2 Copyright (c) 2018 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.
20 from mo.ops.pooling import Pooling
21 from mo.graph.graph import unique_id
22 from mo.middle.replacement import MiddleReplacementPattern
23 from mo.front.common.layout import get_features_dim
25 class PadToPoolingMiddleReplacer(MiddleReplacementPattern):
32 ('pad', dict(kind='op', op='Pad'))
37 def replace_pattern(self, graph: nx.MultiDiGraph, match: dict):
39 input = node.in_node()
40 output = node.out_node()
41 if len(output.out_nodes()) > 0:
42 ndim = len(input.shape)
44 graph.remove_edge(input.id, node.id)
45 graph.remove_edge(node.id, output.id)
46 pool_node = unique_id(graph, node.name + '/Pool_')
47 Pooling(graph, dict(name=pool_node, window=np.ones(ndim, dtype=np.int64),
48 output_spatial_shape=None,
49 batch_dims=np.array([0], dtype=np.int64),
50 channel_dims=np.array([get_features_dim(graph.graph['layout'], ndim)], dtype=np.int64),
51 stride=np.array(np.ones(ndim, dtype=np.int64)),
52 pad=pad, exclude_pad='false', pool_method='max')).create_node_with_data(inputs=[input], data_nodes=[output])