From 29e46cfdbcdf87e9ef7fc4be8cdda64d2d88a6cc Mon Sep 17 00:00:00 2001 From: James Ward Date: Mon, 23 Oct 2023 11:47:25 +0000 Subject: Fix AvgPool2D regression Signed-off-by: James Ward Change-Id: I414899d0f504af00da185e0fc4119f3bde2bae3a --- reference_model/src/ops/tensor_ops.cc | 41 +++-------------------------------- 1 file changed, 3 insertions(+), 38 deletions(-) (limited to 'reference_model/src/ops/tensor_ops.cc') diff --git a/reference_model/src/ops/tensor_ops.cc b/reference_model/src/ops/tensor_ops.cc index 65e05db..2d54d8e 100644 --- a/reference_model/src/ops/tensor_ops.cc +++ b/reference_model/src/ops/tensor_ops.cc @@ -458,39 +458,6 @@ int OpAvgPool2d::checkTensorAttributes() return 0; } -// This calculates the number of padding elements used for each location along an axis -// Average pooling only divides by the number of elements used, not including padding. -// This function uses left/right, but is also used for vertical padding with top/bottom -template -ETensor1 OpAvgPool2d::calculate_div_map_1d( - int in_size, int out_size, int kernel_size, int stride, int32_t pad_left, int32_t pad_right) -{ - ETensor1 result(out_size); - - result.setConstant(kernel_size); - - // adjust divisors on the left side for padding - // We start at the leftmost output element, and remove pad_left - (index * stride) elements - // until we have no more padding being used - for (int index = 0; (index <= pad_left / stride) && (index < out_size); index++) - { - int32_t adjust = pad_left - (index * stride); - result(index) -= adjust; - } - - // The process repeats on the right side. Padding starts taking effect as we - // near the rightmost input element. The first output element which touches - // padding is defined in the initialization of index below. Then we keep moving - // to the right, increasing padding until we get to the last output element. - int index = std::max(0, ((pad_left + in_size - kernel_size) / stride) + 1); - for (; index < out_size; index++) - { - int32_t adjust = ((index * stride) + kernel_size) - (pad_left + in_size); - result(index) -= adjust; - } - return result; -} - // assuming input and output tensor have same scales like tflite reference // so no need to scale input and output template @@ -549,12 +516,10 @@ int OpAvgPool2d::eval() input_val = input_val - (InEigenType)attribute->input_zp(); } - ETensor4 input_padded = input_val.pad(pad); - if (g_func_config.abs_mode) { - // in abs_mode: take abs values of input_padded - input_padded = input_padded.abs(); + // in abs_mode: take abs values of input_val + input_val = input_val.abs(); } // assuming input and output have same scales @@ -585,7 +550,7 @@ int OpAvgPool2d::eval() if ((0 <= y && y < in_height) && (0 <= x && x < in_width)) { ++filter_count; - acc = acc + (AccEigenType)input_padded(ob, y, x, oc); + acc = acc + (AccEigenType)input_val(ob, y, x, oc); } } } -- cgit v1.2.1