diff --git a/compute/cker/include/cker/train/operation/AvgPool.h b/compute/cker/include/cker/train/operation/AvgPool.h index c16c5daddba..e306fc228eb 100644 --- a/compute/cker/include/cker/train/operation/AvgPool.h +++ b/compute/cker/include/cker/train/operation/AvgPool.h @@ -29,63 +29,6 @@ namespace cker { namespace train { -inline void AvgPool2D(const PoolParams ¶ms, const Shape &input_shape, const float *input_data, - const Shape &output_shape, float *output_data) -{ - assert(input_shape.DimensionsCount() == 4); - assert(output_shape.DimensionsCount() == 4); - const int batches = MatchingDim(input_shape, 0, output_shape, 0); - const int input_height = input_shape.Dims(1); - const int input_width = input_shape.Dims(2); - const int output_height = output_shape.Dims(1); - const int output_width = output_shape.Dims(2); - const int stride_height = params.stride_height; - const int stride_width = params.stride_width; - - // TODO(benoitjacob) make this a proper reference impl without Eigen! - const auto in_mat = MapAsMatrixWithLastDimAsRows(input_data, input_shape); - auto out_mat = MapAsMatrixWithLastDimAsRows(output_data, output_shape); - - // Prefill the output to 0. - out_mat.setZero(); - - for (int b = 0; b < batches; ++b) - { - for (int h = 0; h < output_height; ++h) - { - for (int w = 0; w < output_width; ++w) - { - // (h_start, h_end) * (w_start, w_end) is input range - // that output is projected from. - int h_start = h * stride_height - params.padding_values.height; - int h_end = std::min(h_start + params.filter_height, input_height); - h_start = h_start < 0 ? 0 : h_start; - - int w_start = w * stride_width - params.padding_values.width; - int w_end = std::min(w_start + params.filter_width, input_width); - w_start = w_start < 0 ? 0 : w_start; - - int count = (h_end - h_start) * (w_end - w_start); - if (h_end <= 0 || w_end <= 0 || count <= 0 || h_start >= input_height || - w_start >= input_width) - continue; - - int out_offset = NodeOffset(b, h, w, output_height, output_width); - for (int ph = h_start; ph < h_end; ++ph) - { - for (int pw = w_start; pw < w_end; ++pw) - { - int in_offset = NodeOffset(b, ph, pw, input_height, input_width); - out_mat.col(out_offset) += in_mat.col(in_offset); - } - } - out_mat.col(out_offset) /= count; - } - } - } - - out_mat.cwiseMin(params.float_activation_min).cwiseMax(params.float_activation_max); -} inline void AvgPool2DGrad(const PoolParams ¶ms, const Shape &incoming_shape, const float *incoming_data, const Shape &grad_shape, float *grad_data) diff --git a/compute/cker/src/train/AvgPool.test.cc b/compute/cker/src/train/AvgPool.test.cc index e65425c9be8..cb29bb742db 100644 --- a/compute/cker/src/train/AvgPool.test.cc +++ b/compute/cker/src/train/AvgPool.test.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,8 +48,8 @@ template class AvgPoolOpVerifier assert(expected_output.size() == _out_shape.FlatSize()); std::vector cacluated_output(_out_shape.FlatSize()); - nnfw::cker::train::AvgPool2D(_op_params, _in_shape, input.data(), _out_shape, - cacluated_output.data()); + nnfw::cker::AveragePool(_op_params, _in_shape, input.data(), _out_shape, + cacluated_output.data()); if (expect_eq) EXPECT_EQ(expected_output, cacluated_output); @@ -231,7 +231,7 @@ TEST(CKer_Operation, AvgPool2D) } } -TEST(CKer_Operation, neg_AvgPool) +TEST(CKer_Operation, neg_AvgPoolInvalidExpectedValue) { // Invalid expected value {