Skip to content

Commit a15b5dd

Browse files
authored
Add adaptive pool2d op conversion (#1)
1 parent 9360347 commit a15b5dd

File tree

1 file changed

+17
-33
lines changed

1 file changed

+17
-33
lines changed

ngraph/frontend/paddlepaddle/src/op/pool2d.cpp

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "pool2d.hpp"
88
#include <ngraph/opsets/opset6.hpp>
9+
#include <ngraph/opsets/opset8.hpp>
910

1011
namespace ngraph
1112
{
@@ -138,56 +139,39 @@ namespace ngraph
138139
{
139140
PDPD_ASSERT(input_shape[2].is_static() && input_shape[3].is_static(),
140141
"pool2d: spatial dim must be static when using adaptive pool");
141-
uint64_t pool_size_Height, pool_size_Width;
142-
uint64_t input_h = input_shape[input_rank - 2].get_length();
143-
uint64_t input_w = input_shape[input_rank - 1].get_length();
142+
auto pool_size = std::vector<int64_t>(2, 0);
144143

145144
if (kernel_shape.size() == 1)
146145
{
147146
// Not tested: implemented according to spec, but can't generate real
148147
// model to test
149-
pool_size_Height = pool_size_Width = kernel_shape[0];
148+
pool_size[0] = pool_size[1] = kernel_shape[0];
150149
}
151150
else
152151
{
153-
pool_size_Height = kernel_shape[0];
154-
pool_size_Width = kernel_shape[1];
152+
pool_size[0] = kernel_shape[0];
153+
pool_size[1] = kernel_shape[1];
155154
}
156155

157-
uint64_t stride_h = int64_t(input_h / pool_size_Height);
158-
uint64_t stride_w = int64_t(input_w / pool_size_Width);
159-
uint64_t kernel_h = input_h - (pool_size_Height - 1) * stride_h;
160-
uint64_t kernel_w = input_w - (pool_size_Width - 1) * stride_w;
161-
162-
PDPD_ASSERT(stride_h >= 1 && stride_w >= 1,
163-
"Pool2d stride must be greater than 1");
156+
const Output<ngraph::Node> output_shape = ngraph::opset6::Constant::create(
157+
ngraph::element::i64, {pool_size.size()}, pool_size);
164158

165159
if (pooling_type == "max")
166160
{
167-
return node.default_single_output_mapping(
168-
{std::make_shared<ngraph::opset6::MaxPool>(
169-
data,
170-
ngraph::Strides{stride_h, stride_w},
171-
pad_begin,
172-
pad_end,
173-
ngraph::Shape{kernel_h, kernel_w},
174-
rounding_type,
175-
auto_pad)},
176-
{"Out"});
161+
std::vector<Output<Node>> pool_outputs;
162+
pool_outputs = std::make_shared<ngraph::opset8::AdaptiveMaxPool>(
163+
data, output_shape, ngraph::element::i64)
164+
->outputs();
165+
NamedOutputs outputs;
166+
outputs["Out"] = {pool_outputs[0]};
167+
outputs["Mask"] = {pool_outputs[1]};
168+
return outputs;
177169
}
178170
else
179171
{
180-
bool exclude_pad = node.get_attribute<bool>("exclusive", false);
181172
return node.default_single_output_mapping(
182-
{std::make_shared<ngraph::opset6::AvgPool>(
183-
data,
184-
ngraph::Strides{stride_h, stride_w},
185-
pad_begin,
186-
pad_end,
187-
ngraph::Shape{kernel_h, kernel_w},
188-
exclude_pad,
189-
rounding_type,
190-
auto_pad)},
173+
{std::make_shared<ngraph::opset8::AdaptiveAvgPool>(data,
174+
output_shape)},
191175
{"Out"});
192176
}
193177
}

0 commit comments

Comments
 (0)