From 7fc3df909796bc535c778b547296eafec871fa5d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Shubham=20Gupta/SNAP=20/SRI-Bangalore/Engineer/=EC=82=BC?= =?utf8?q?=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 26 Nov 2018 06:41:57 +0530 Subject: [PATCH] Correction in Padding_Same untility function (#3629) This patch will correct the Paddin_Same function logic. Signed-off-by: shubham --- runtimes/pure_arm_compute/src/compilation.cc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/runtimes/pure_arm_compute/src/compilation.cc b/runtimes/pure_arm_compute/src/compilation.cc index b248f63..c736a93 100644 --- a/runtimes/pure_arm_compute/src/compilation.cc +++ b/runtimes/pure_arm_compute/src/compilation.cc @@ -177,8 +177,7 @@ Padding valid_padding(void) return padding; } -Padding same_padding(const nnfw::util::feature::Shape &ifm_shape, - const nnfw::util::feature::Shape &ofm_shape, const Stride &stride, uint32_t kw, +Padding same_padding(const nnfw::util::feature::Shape &ifm_shape, const Stride &stride, uint32_t kw, uint32_t kh) { Padding padding; @@ -190,10 +189,13 @@ Padding same_padding(const nnfw::util::feature::Shape &ifm_shape, // padding_to_beginning = total_padding / 2 // padding_to_end = (total_padding + 1)/2. // - const int32_t vertical_needed_input = (ofm_shape.H - 1) * stride.vertical + kh; + const int32_t out_size_height = (ifm_shape.H + stride.vertical - 1) / stride.vertical; + const int32_t out_size_width = (ifm_shape.W + stride.horizontal - 1) / stride.horizontal; + + const int32_t vertical_needed_input = (out_size_height - 1) * stride.vertical + kh; const int32_t vertical_total_padding = std::max(0, vertical_needed_input - ifm_shape.H); - const int32_t horizontal_needed_input = (ofm_shape.W - 1) * stride.horizontal + kw; + const int32_t horizontal_needed_input = (out_size_width - 1) * stride.horizontal + kw; const int32_t horizontal_total_padding = std::max(0, horizontal_needed_input - ifm_shape.W); padding.top = vertical_total_padding / 2; @@ -1028,7 +1030,7 @@ void Planner::visit(const ::internal::tflite::op::Conv2D::Implicit::Node &node) param.stride = stride; param.padding = (padding_type == ANEURALNETWORKS_PADDING_SAME) - ? same_padding(ifm_shape, ofm_shape, stride, ker_shape.W, ker_shape.H) + ? same_padding(ifm_shape, stride, ker_shape.W, ker_shape.H) : valid_padding(); param.activation = static_cast(_ctx.at(activation_index).asScalar()); @@ -1308,7 +1310,7 @@ void Planner::visit(const ::internal::tflite::op::DepthwiseConv2D::Implicit::Nod param.stride = stride; param.padding = (padding_type == ANEURALNETWORKS_PADDING_SAME) - ? same_padding(ifm_shape, ofm_shape, stride, ker_shape.W, ker_shape.H) + ? same_padding(ifm_shape, stride, ker_shape.W, ker_shape.H) : valid_padding(); param.multipler = multiplier; @@ -1641,7 +1643,7 @@ void Planner::visit(const ::internal::tflite::op::MaxPool2D::Implicit::Node &nod param.stride.horizontal = hstride; param.padding = (padding_type == ANEURALNETWORKS_PADDING_SAME) - ? same_padding(ifm_shape, ofm_shape, param.stride, kw, kh) + ? same_padding(ifm_shape, param.stride, kw, kh) : valid_padding(); param.activation = static_cast(_ctx.at(activation_index).asScalar()); @@ -1872,7 +1874,7 @@ void Planner::visit(const ::internal::tflite::op::AvgPool2D::Implicit::Node &nod param.stride.horizontal = hstride; param.padding = (padding_type == ANEURALNETWORKS_PADDING_SAME) - ? same_padding(ifm_shape, ofm_shape, param.stride, kw, kh) + ? same_padding(ifm_shape, param.stride, kw, kh) : valid_padding(); param.activation = static_cast(_ctx.at(activation_index).asScalar()); @@ -4440,7 +4442,7 @@ void Planner::visit(const ::internal::tflite::op::L2Pool2D::Implicit::Node &node param.stride.horizontal = hstride; param.padding = (padding_type == ANEURALNETWORKS_PADDING_SAME) - ? same_padding(ifm_shape, ofm_shape, param.stride, kw, kh) + ? same_padding(ifm_shape, param.stride, kw, kh) : valid_padding(); param.activation = static_cast(_ctx.at(activation_index).asScalar()); -- 2.7.4