From 99e396f857b3d89cfb6dad9618c1a7c3ebcdda7f Mon Sep 17 00:00:00 2001 From: wenbin Date: Sat, 23 Oct 2021 16:45:56 +0800 Subject: [PATCH] disable padding if dynamic shape (#36648) * disable padding if dynamic shape * add parentheses * correct --- paddle/fluid/inference/tensorrt/convert/pool2d_op.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/inference/tensorrt/convert/pool2d_op.cc b/paddle/fluid/inference/tensorrt/convert/pool2d_op.cc index 05cd7bad5cbac..35c9658108ab5 100644 --- a/paddle/fluid/inference/tensorrt/convert/pool2d_op.cc +++ b/paddle/fluid/inference/tensorrt/convert/pool2d_op.cc @@ -138,8 +138,11 @@ class Pool2dOpConverter : public OpConverter { if (engine_->with_dynamic_shape()) { if (!adaptive && !global_pooling && !ceil_mode) { - if ((g_post_pad.w() > 0 || g_post_pad.h() > 0) && - (padding_algorithm != "SAME")) { + // input_shape.d < 0 means we can't get shape info here. + // we may suffer from issue if shape is not met finally. + if ((padding_algorithm != "SAME") && + ((g_post_pad.w() > 0 && input_shape.d[input_dims - 2] > 0) || + (g_post_pad.h() > 0 && input_shape.d[input_dims - 1] > 0))) { auto *pad_layer = TRT_ENGINE_ADD_LAYER(engine_, Padding, *input1, g_pre_pad, g_post_pad); PADDLE_ENFORCE_NOT_NULL( @@ -148,6 +151,7 @@ class Pool2dOpConverter : public OpConverter { "created. The pointer to pad layer is `NULL`.")); input1 = pad_layer->getOutput(0); } + auto *pool_layer = TRT_ENGINE_ADD_LAYER(engine_, Pooling, *input1, nv_pool_type, nv_ksize); pool_layer->setStride(nv_strides);