diff options
author | James Ward <james.ward@arm.com> | 2023-10-23 11:47:25 +0000 |
---|---|---|
committer | James Ward <james.ward@arm.com> | 2023-10-23 11:48:34 +0000 |
commit | 29e46cfdbcdf87e9ef7fc4be8cdda64d2d88a6cc (patch) | |
tree | ccfb173422880e992db7a7a7bf4afe1eb2cd669a /reference_model/src/ops/tensor_ops.cc | |
parent | 5a9e0cda44bf937c325df42b493cfa8d97b70e52 (diff) | |
download | reference_model-29e46cfdbcdf87e9ef7fc4be8cdda64d2d88a6cc.tar.gz |
Fix AvgPool2D regression
Signed-off-by: James Ward <james.ward@arm.com>
Change-Id: I414899d0f504af00da185e0fc4119f3bde2bae3a
Diffstat (limited to 'reference_model/src/ops/tensor_ops.cc')
-rw-r--r-- | reference_model/src/ops/tensor_ops.cc | 41 |
1 files changed, 3 insertions, 38 deletions
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<Dtype, AccDtype>::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 <TOSA_REF_TYPE Dtype, TOSA_REF_TYPE AccDtype> -ETensor1<int32_t> OpAvgPool2d<Dtype, AccDtype>::calculate_div_map_1d( - int in_size, int out_size, int kernel_size, int stride, int32_t pad_left, int32_t pad_right) -{ - ETensor1<int32_t> 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 <TOSA_REF_TYPE Dtype, TOSA_REF_TYPE AccDtype> @@ -549,12 +516,10 @@ int OpAvgPool2d<Dtype, AccDtype>::eval() input_val = input_val - (InEigenType)attribute->input_zp(); } - ETensor4<InEigenType> 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<Dtype, AccDtype>::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); } } } |