From bacaf9af9b23b01e646a2e206e119a9d8e099a70 Mon Sep 17 00:00:00 2001 From: SiCong Li Date: Mon, 19 Jun 2017 13:41:45 +0100 Subject: COMPMID-424 Add CL validation tests for Box3x3 * Add tests for different border modes * Add padding calculator Change-Id: Ic4708faddfb1c8e6b59d349cf9cb48c9a181d717 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/78105 Tested-by: Kaizen Reviewed-by: Moritz Pflanzer --- tests/validation/TensorOperations.h | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'tests/validation/TensorOperations.h') diff --git a/tests/validation/TensorOperations.h b/tests/validation/TensorOperations.h index fce257540b..569559352a 100644 --- a/tests/validation/TensorOperations.h +++ b/tests/validation/TensorOperations.h @@ -201,6 +201,7 @@ void vector_matrix_multiply(const int8_t *in, const int8_t *weights, const int8_ } } +// Return a tensor element at a specified coordinate with different border modes template ::value, int>::type = 0> T tensor_elem_at(const Tensor &in, Coordinates &coord, BorderMode border_mode, T constant_border_value) { @@ -209,14 +210,10 @@ T tensor_elem_at(const Tensor &in, Coordinates &coord, BorderMode border_mode const int width = static_cast(in.shape().x()); const int height = static_cast(in.shape().y()); - // If on border + // If coordinates beyond range of tensor's width or height if(x < 0 || y < 0 || x >= width || y >= height) { - if(border_mode == BorderMode::CONSTANT) - { - return constant_border_value; - } - else if(border_mode == BorderMode::REPLICATE) + if(border_mode == BorderMode::REPLICATE) { coord.set(0, std::max(0, std::min(x, width - 1))); coord.set(1, std::max(0, std::min(y, height - 1))); @@ -224,10 +221,7 @@ T tensor_elem_at(const Tensor &in, Coordinates &coord, BorderMode border_mode } else { - // Return a random value if on border and border_mode == UNDEFINED - std::mt19937 gen(user_config.seed.get()); - std::uniform_int_distribution distribution(0, 255); - return distribution(gen); + return constant_border_value; } } else @@ -257,8 +251,7 @@ void apply_2d_spatial_filter(Coordinates coord, const Tensor &in, Tensor { coord.set(0, i); coord.set(1, j); - double pixel_to_multiply = tensor_elem_at(in, coord, border_mode, constant_border_value); - val += static_cast(*filter_itr) * pixel_to_multiply; + val += static_cast(*filter_itr) * tensor_elem_at(in, coord, border_mode, constant_border_value); ++filter_itr; } } @@ -508,20 +501,16 @@ void bitwise_not(const Tensor &in, Tensor &out) } } -// 3-by-3 box filter +// Box3x3 filter template ::value>::type> -void box3x3(const Tensor &in, Tensor &out) +void box3x3(const Tensor &in, Tensor &out, BorderMode border_mode, T constant_border_value) { const std::array filter{ { 1, 1, 1, 1, 1, 1, 1, 1, 1 } }; - float scale = 1.f / static_cast(filter.size()); - const ValidRegion valid_region = shape_to_valid_region_undefined_border(in.shape(), BorderSize(1)); + float scale = 1.f / static_cast(filter.size()); for(int element_idx = 0; element_idx < in.num_elements(); ++element_idx) { const Coordinates id = index2coord(in.shape(), element_idx); - if(is_in_valid_region(valid_region, id)) - { - apply_2d_spatial_filter(id, in, out, TensorShape(3U, 3U), filter.data(), scale, BorderMode::UNDEFINED); - } + apply_2d_spatial_filter(id, in, out, TensorShape(3U, 3U), filter.data(), scale, border_mode, constant_border_value); } } -- cgit v1.2.1