From 2e16b357cd9e42a25edff8614a79e7da2fb39b45 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=84=B8=ED=9D=AC/On-Device=20Lab=28SR=29/Princip?= =?utf8?q?al=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 5 Aug 2019 17:17:26 +0900 Subject: [PATCH] [moco-tf] Fix pad for AvgPool2D in fix shape (#6196) * [moco-tf] Fix pad for AvgPool2D in fix shape This will merge fix pad for AvgPool2D node in fix shape transform Signed-off-by: SaeHie Park * remove local var only for assert * remove useless assert * remove unused header --- compiler/moco-tf/src/Transforms/FixShapeTransform.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/compiler/moco-tf/src/Transforms/FixShapeTransform.cpp b/compiler/moco-tf/src/Transforms/FixShapeTransform.cpp index 491fd25..d1d39e0 100644 --- a/compiler/moco-tf/src/Transforms/FixShapeTransform.cpp +++ b/compiler/moco-tf/src/Transforms/FixShapeTransform.cpp @@ -155,7 +155,23 @@ bool fix_shape(loco::AvgPool2D *node) shape_data->feature_shape(ofm_feature_shape); node->annot(std::move(shape_data)); + // calculate padding height, width + int32_t i_height = (output_height - 1) * stride_height + effective_window_height - input_height; + int32_t i_width = (output_width - 1) * stride_width + effective_window_width - input_width; + uint32_t pad_height = i_height >= 0 ? i_height : 0U; + uint32_t pad_width = i_width >= 0 ? i_width : 0U; + + // set padding values + node->pad()->top(pad_height / 2); + node->pad()->bottom(pad_height - node->pad()->top()); + node->pad()->left(pad_width / 2); + node->pad()->right(pad_width - node->pad()->left()); + + // clear annotation PaddingData + node->annot(nullptr); + INFO(l) << "Fix AvgPool2D shape = ifm" << ifm_feature_shape << " --> ofm" << ofm_feature_shape; + INFO(l) << " pad = " << *node->pad(); return true; } -- 2.7.4