diff options
author | Giorgio Arena <giorgio.arena@arm.com> | 2018-05-01 11:47:24 +0100 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:50:48 +0000 |
commit | 3c520c5a6ca9352560828fdf389d31e38b85afeb (patch) | |
tree | 9a7cbbb2fdf0f9f6c8e42cfd36d2ea8b842fe3d4 | |
parent | 6c4212789a530c3655258779219c4ed7f0397b86 (diff) | |
download | ComputeLibrary-3c520c5a6ca9352560828fdf389d31e38b85afeb.tar.gz |
COMPMID-1089 CLPoolingLayer fix padding and add output shape computation to ShapeCalculator
Change-Id: Ide83424e9fe6b8102ed9e3c355c099c3912e7e61
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/129635
Tested-by: Jenkins <bsgcomp@arm.com>
Reviewed-by: Michele DiGiorgio <michele.digiorgio@arm.com>
Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
13 files changed, 87 insertions, 94 deletions
diff --git a/arm_compute/core/utils/misc/ShapeCalculator.h b/arm_compute/core/utils/misc/ShapeCalculator.h index a0bc4eab54..757e423d4f 100644 --- a/arm_compute/core/utils/misc/ShapeCalculator.h +++ b/arm_compute/core/utils/misc/ShapeCalculator.h @@ -331,21 +331,22 @@ inline TensorShape compute_pool_shape(const ITensorInfo &input, PoolingLayerInfo unsigned int pooled_w = 0; unsigned int pooled_h = 0; + TensorShape output_shape{ input.tensor_shape() }; + const bool is_global_pooling = pool_info.is_global_pooling(); - const int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH); - const int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT); - const unsigned int pool_size_x = is_global_pooling ? input.tensor_shape()[idx_width] : pool_info.pool_size().width; - const unsigned int pool_size_y = is_global_pooling ? input.tensor_shape()[idx_height] : pool_info.pool_size().height; + const unsigned int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH); + const unsigned int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT); + const unsigned int pool_size_x = is_global_pooling ? output_shape[idx_width] : pool_info.pool_size().width; + const unsigned int pool_size_y = is_global_pooling ? output_shape[idx_height] : pool_info.pool_size().height; - std::tie(pooled_w, pooled_h) = scaled_dimensions(input.dimension(idx_width), - input.dimension(idx_height), + std::tie(pooled_w, pooled_h) = scaled_dimensions(output_shape[idx_width], + output_shape[idx_height], pool_size_x, pool_size_y, pool_info.pad_stride_info()); - TensorShape output_shape{ input.tensor_shape() }; - output_shape.set(get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH), pooled_w); - output_shape.set(get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT), pooled_h); + output_shape.set(idx_width, pooled_w); + output_shape.set(idx_height, pooled_h); return output_shape; } diff --git a/src/core/CL/kernels/CLPoolingLayerKernel.cpp b/src/core/CL/kernels/CLPoolingLayerKernel.cpp index 7907d01daa..ad4712d746 100644 --- a/src/core/CL/kernels/CLPoolingLayerKernel.cpp +++ b/src/core/CL/kernels/CLPoolingLayerKernel.cpp @@ -143,7 +143,7 @@ std::tuple<Status, Window, CLPoolingConfig> validate_and_configure_window(ITenso win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration)); AccessWindowRectangle input_access(input, -pool_pad_left, -pool_pad_top, num_elems_read_per_iteration, pool_size_y, - pool_stride_x * num_elems_processed_per_iteration, pool_stride_y); + pool_stride_x, pool_stride_y); AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration); window_changed = update_window_and_padding(win, input_access, output_access); output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); @@ -155,7 +155,7 @@ std::tuple<Status, Window, CLPoolingConfig> validate_and_configure_window(ITenso win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration)); AccessWindowRectangle input_access(input, -1, -1, num_elems_processed_per_iteration, pool_size_y, - pool_stride_x * num_elems_processed_per_iteration, pool_stride_y); + pool_stride_x, pool_stride_y); AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration); window_changed = update_window_and_padding(win, input_access, output_access); output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); diff --git a/tests/benchmark/fixtures/PoolingLayerFixture.h b/tests/benchmark/fixtures/PoolingLayerFixture.h index bd7c155348..a8263fbcdc 100644 --- a/tests/benchmark/fixtures/PoolingLayerFixture.h +++ b/tests/benchmark/fixtures/PoolingLayerFixture.h @@ -26,6 +26,7 @@ #include "arm_compute/core/TensorShape.h" #include "arm_compute/core/Types.h" +#include "arm_compute/core/utils/misc/ShapeCalculator.h" #include "tests/Globals.h" #include "tests/Utils.h" #include "tests/framework/Fixture.h" @@ -36,16 +37,24 @@ namespace test { namespace benchmark { +using namespace arm_compute::misc::shape_calculator; + /** Fixture that can be used for NEON and CL */ template <typename TensorType, typename Function, typename Accessor> class PoolingLayerFixture : public framework::Fixture { public: template <typename...> - void setup(TensorShape src_shape, TensorShape dst_shape, PoolingLayerInfo info, DataType data_type, DataLayout data_layout, int batches) + void setup(TensorShape src_shape, PoolingLayerInfo info, DataType data_type, DataLayout data_layout, int batches) { // Set batched in source and destination shapes const unsigned int fixed_point_position = 4; + + TensorInfo src_info(src_shape, 1, data_type, fixed_point_position); + src_info.set_data_layout(data_layout); + + TensorShape dst_shape = compute_pool_shape(src_info, info); + src_shape.set(src_shape.num_dimensions(), batches); dst_shape.set(dst_shape.num_dimensions(), batches); diff --git a/tests/datasets/PoolingLayerDataset.h b/tests/datasets/PoolingLayerDataset.h index 36818010a5..363aabad96 100644 --- a/tests/datasets/PoolingLayerDataset.h +++ b/tests/datasets/PoolingLayerDataset.h @@ -37,15 +37,13 @@ namespace datasets class PoolingLayerDataset { public: - using type = std::tuple<TensorShape, TensorShape, PoolingLayerInfo>; + using type = std::tuple<TensorShape, PoolingLayerInfo>; struct iterator { iterator(std::vector<TensorShape>::const_iterator src_it, - std::vector<TensorShape>::const_iterator dst_it, std::vector<PoolingLayerInfo>::const_iterator infos_it) : _src_it{ std::move(src_it) }, - _dst_it{ std::move(dst_it) }, _infos_it{ std::move(infos_it) } { } @@ -54,20 +52,18 @@ public: { std::stringstream description; description << "In=" << *_src_it << ":"; - description << "Out=" << *_dst_it << ":"; description << "Info=" << *_infos_it << ":"; return description.str(); } PoolingLayerDataset::type operator*() const { - return std::make_tuple(*_src_it, *_dst_it, *_infos_it); + return std::make_tuple(*_src_it, *_infos_it); } iterator &operator++() { ++_src_it; - ++_dst_it; ++_infos_it; return *this; @@ -75,24 +71,22 @@ public: private: std::vector<TensorShape>::const_iterator _src_it; - std::vector<TensorShape>::const_iterator _dst_it; std::vector<PoolingLayerInfo>::const_iterator _infos_it; }; iterator begin() const { - return iterator(_src_shapes.begin(), _dst_shapes.begin(), _infos.begin()); + return iterator(_src_shapes.begin(), _infos.begin()); } int size() const { - return std::min(_src_shapes.size(), std::min(_dst_shapes.size(), _infos.size())); + return std::min(_src_shapes.size(), _infos.size()); } - void add_config(TensorShape src, TensorShape dst, PoolingLayerInfo info) + void add_config(TensorShape src, PoolingLayerInfo info) { _src_shapes.emplace_back(std::move(src)); - _dst_shapes.emplace_back(std::move(dst)); _infos.emplace_back(std::move(info)); } @@ -102,7 +96,6 @@ protected: private: std::vector<TensorShape> _src_shapes{}; - std::vector<TensorShape> _dst_shapes{}; std::vector<PoolingLayerInfo> _infos{}; }; @@ -113,10 +106,10 @@ public: PoolingLayerDatasetSpecial() { // Special cases - add_config(TensorShape(60U, 52U, 3U, 2U), TensorShape(13U, 11U, 32U), PoolingLayerInfo(PoolingType::AVG, Size2D(100, 100), PadStrideInfo(5, 5, 50, 50), true)); + add_config(TensorShape(60U, 52U, 3U, 2U), PoolingLayerInfo(PoolingType::AVG, Size2D(100, 100), PadStrideInfo(5, 5, 50, 50), true)); // Asymmetric padding - add_config(TensorShape(112U, 112U, 32U), TensorShape(56U, 56U, 32U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::FLOOR))); - add_config(TensorShape(14U, 14U, 832U), TensorShape(7U, 7U, 832U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(1, 1, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(112U, 112U, 32U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::FLOOR))); + add_config(TensorShape(14U, 14U, 832U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(1, 1, 0, 0, DimensionRoundingType::CEIL))); } }; } // namespace datasets diff --git a/tests/datasets/system_tests/alexnet/AlexNetPoolingLayerDataset.h b/tests/datasets/system_tests/alexnet/AlexNetPoolingLayerDataset.h index 739d24ca18..241f2569ef 100644 --- a/tests/datasets/system_tests/alexnet/AlexNetPoolingLayerDataset.h +++ b/tests/datasets/system_tests/alexnet/AlexNetPoolingLayerDataset.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -42,9 +42,9 @@ class AlexNetPoolingLayerDataset final : public PoolingLayerDataset public: AlexNetPoolingLayerDataset() { - add_config(TensorShape(55U, 55U, 96U), TensorShape(27U, 27U, 96U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0))); - add_config(TensorShape(27U, 27U, 256U), TensorShape(13U, 13U, 256U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0))); - add_config(TensorShape(13U, 13U, 256U), TensorShape(6U, 6U, 256U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0))); + add_config(TensorShape(55U, 55U, 96U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0))); + add_config(TensorShape(27U, 27U, 256U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0))); + add_config(TensorShape(13U, 13U, 256U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0))); } }; } // namespace datasets diff --git a/tests/datasets/system_tests/googlenet/inceptionv1/GoogLeNetInceptionV1PoolingLayerDataset.h b/tests/datasets/system_tests/googlenet/inceptionv1/GoogLeNetInceptionV1PoolingLayerDataset.h index b775667ac8..652ac6be2b 100644 --- a/tests/datasets/system_tests/googlenet/inceptionv1/GoogLeNetInceptionV1PoolingLayerDataset.h +++ b/tests/datasets/system_tests/googlenet/inceptionv1/GoogLeNetInceptionV1PoolingLayerDataset.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -44,25 +44,25 @@ public: { // FIXME: Add support for 7x7 pooling layer pool5/7x7_s1 // pool1/3x3_s2 - add_config(TensorShape(112U, 112U, 64U), TensorShape(56U, 56U, 64U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(112U, 112U, 64U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // pool2/3x3_s2 - add_config(TensorShape(56U, 56U, 192U), TensorShape(28U, 28U, 192U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(56U, 56U, 192U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // inception_3a/pool - add_config(TensorShape(28U, 28U, 192U), TensorShape(28U, 28U, 192U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); + add_config(TensorShape(28U, 28U, 192U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); // inception_3b/pool - add_config(TensorShape(28U, 28U, 256U), TensorShape(28U, 28U, 256U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); + add_config(TensorShape(28U, 28U, 256U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); // pool3/3x3_s2 - add_config(TensorShape(28U, 28U, 480U), TensorShape(14U, 14U, 480U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(28U, 28U, 480U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // inception_4a/pool - add_config(TensorShape(14U, 14U, 480U), TensorShape(14U, 14U, 480U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); + add_config(TensorShape(14U, 14U, 480U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); // inception_4b/pool, inception_4c/pool, inception_4d/pool - add_config(TensorShape(14U, 14U, 512U), TensorShape(14U, 14U, 512U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); + add_config(TensorShape(14U, 14U, 512U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); // inception_4e/pool - add_config(TensorShape(14U, 14U, 528U), TensorShape(14U, 14U, 528U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); + add_config(TensorShape(14U, 14U, 528U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); // pool4/3x3_s2 - add_config(TensorShape(14U, 14U, 832U), TensorShape(7U, 7U, 832U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(14U, 14U, 832U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // inception_5a/pool, inception_5b/pool - add_config(TensorShape(7U, 7U, 832U), TensorShape(7U, 7U, 832U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); + add_config(TensorShape(7U, 7U, 832U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); } }; } // namespace datasets diff --git a/tests/datasets/system_tests/googlenet/inceptionv4/GoogLeNetInceptionV4PoolingLayerDataset.h b/tests/datasets/system_tests/googlenet/inceptionv4/GoogLeNetInceptionV4PoolingLayerDataset.h index a58fd797ec..12eefdd5e5 100644 --- a/tests/datasets/system_tests/googlenet/inceptionv4/GoogLeNetInceptionV4PoolingLayerDataset.h +++ b/tests/datasets/system_tests/googlenet/inceptionv4/GoogLeNetInceptionV4PoolingLayerDataset.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -44,19 +44,19 @@ public: { // FIXME: Add support for global pooling layer pool_8x8_s1 // inception_stem1_pool - add_config(TensorShape(147U, 147U, 64U), TensorShape(73U, 73U, 64U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(147U, 147U, 64U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // inception_stem3_pool - add_config(TensorShape(71U, 71U, 192U), TensorShape(35U, 35U, 192U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(71U, 71U, 192U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // inception_a1_pool_ave, inception_a2_pool_ave, inception_a3_pool_ave, inception_a4_pool_ave - add_config(TensorShape(35U, 35U, 384U), TensorShape(35U, 35U, 384U), PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); + add_config(TensorShape(35U, 35U, 384U), PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); // reduction_a_pool - add_config(TensorShape(35U, 35U, 384U), TensorShape(17U, 17U, 384U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(35U, 35U, 384U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // inception_b1_pool_ave, inception_b2_pool_ave, inception_b3_pool_ave, inception_b4_pool_ave, inception_b5_pool_ave, inception_b6_pool_ave, inception_b7_pool_ave - add_config(TensorShape(17U, 17U, 1024U), TensorShape(17U, 17U, 1024U), PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); + add_config(TensorShape(17U, 17U, 1024U), PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); // reduction_b_pool - add_config(TensorShape(17U, 17U, 1024U), TensorShape(8U, 8U, 1024U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(17U, 17U, 1024U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // inception_c1_pool_ave, inception_c2_pool_ave, inception_c3_pool_ave - add_config(TensorShape(8U, 8U, 1536U), TensorShape(8U, 8U, 1536U), PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); + add_config(TensorShape(8U, 8U, 1536U), PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL))); } }; } // namespace datasets diff --git a/tests/datasets/system_tests/lenet5/LeNet5PoolingLayerDataset.h b/tests/datasets/system_tests/lenet5/LeNet5PoolingLayerDataset.h index bcd11dc5b9..5740dc34d6 100644 --- a/tests/datasets/system_tests/lenet5/LeNet5PoolingLayerDataset.h +++ b/tests/datasets/system_tests/lenet5/LeNet5PoolingLayerDataset.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -42,8 +42,8 @@ class LeNet5PoolingLayerDataset final : public PoolingLayerDataset public: LeNet5PoolingLayerDataset() { - add_config(TensorShape(24U, 24U, 20U), TensorShape(12U, 12U, 20U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0))); - add_config(TensorShape(8U, 8U, 50U), TensorShape(4U, 4U, 50U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0))); + add_config(TensorShape(24U, 24U, 20U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0))); + add_config(TensorShape(8U, 8U, 50U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0))); } }; } // namespace datasets diff --git a/tests/datasets/system_tests/squeezenet/SqueezeNetPoolingLayerDataset.h b/tests/datasets/system_tests/squeezenet/SqueezeNetPoolingLayerDataset.h index cb2edbc5ec..b1283cdc05 100644 --- a/tests/datasets/system_tests/squeezenet/SqueezeNetPoolingLayerDataset.h +++ b/tests/datasets/system_tests/squeezenet/SqueezeNetPoolingLayerDataset.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -43,11 +43,11 @@ public: SqueezeNetPoolingLayerDataset() { // pool1 - add_config(TensorShape(111U, 111U, 64U), TensorShape(55U, 55U, 64U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(111U, 111U, 64U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // pool3 - add_config(TensorShape(55U, 55U, 128U), TensorShape(27U, 27U, 128U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(55U, 55U, 128U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // pool5 - add_config(TensorShape(27U, 27U, 256U), TensorShape(13U, 13U, 256U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(27U, 27U, 256U), PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); //FIXME: Add support for global pooling. } }; diff --git a/tests/datasets/system_tests/vgg/vgg16/VGG16PoolingLayerDataset.h b/tests/datasets/system_tests/vgg/vgg16/VGG16PoolingLayerDataset.h index affbcc5022..35221dddf6 100644 --- a/tests/datasets/system_tests/vgg/vgg16/VGG16PoolingLayerDataset.h +++ b/tests/datasets/system_tests/vgg/vgg16/VGG16PoolingLayerDataset.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -43,15 +43,15 @@ public: VGG16PoolingLayerDataset() { // pool1 - add_config(TensorShape(224U, 224U, 64U), TensorShape(112U, 112U, 64U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(224U, 224U, 64U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // pool2 - add_config(TensorShape(112U, 112U, 128U), TensorShape(56U, 56U, 128U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(112U, 112U, 128U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // pool3 - add_config(TensorShape(56U, 56U, 256U), TensorShape(28U, 28U, 256U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(56U, 56U, 256U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // pool4 - add_config(TensorShape(28U, 28U, 512U), TensorShape(14U, 14U, 512U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(28U, 28U, 512U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // pool5 - add_config(TensorShape(14U, 14U, 512U), TensorShape(7U, 7U, 512U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(14U, 14U, 512U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); } }; } // namespace datasets diff --git a/tests/datasets/system_tests/yolo/v2/YOLOV2PoolingLayerDataset.h b/tests/datasets/system_tests/yolo/v2/YOLOV2PoolingLayerDataset.h index 62222f3a88..ddbad6b4d3 100644 --- a/tests/datasets/system_tests/yolo/v2/YOLOV2PoolingLayerDataset.h +++ b/tests/datasets/system_tests/yolo/v2/YOLOV2PoolingLayerDataset.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -43,15 +43,15 @@ public: YOLOV2PoolingLayerDataset() { // pool1 - add_config(TensorShape(416U, 416U, 32U), TensorShape(208U, 208U, 32U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(416U, 416U, 32U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // pool2 - add_config(TensorShape(208U, 208U, 64U), TensorShape(104U, 104U, 64U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(208U, 208U, 64U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // pool5 - add_config(TensorShape(104U, 104U, 128U), TensorShape(52U, 52U, 128U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(104U, 104U, 128U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // pool8 - add_config(TensorShape(52U, 52U, 256U), TensorShape(26U, 26U, 256U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(52U, 52U, 256U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); // pool13 - add_config(TensorShape(26U, 26U, 512U), TensorShape(13U, 13U, 512U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); + add_config(TensorShape(26U, 26U, 512U), PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))); } }; } // namespace datasets diff --git a/tests/validation/fixtures/PoolingLayerFixture.h b/tests/validation/fixtures/PoolingLayerFixture.h index 3c28b3b64d..a40baf415a 100644 --- a/tests/validation/fixtures/PoolingLayerFixture.h +++ b/tests/validation/fixtures/PoolingLayerFixture.h @@ -175,9 +175,8 @@ class SpecialPoolingLayerValidationFixture : public PoolingLayerValidationGeneri { public: template <typename...> - void setup(TensorShape src_shape, TensorShape dst_shape, PoolingLayerInfo pool_info, DataType data_type) + void setup(TensorShape src_shape, PoolingLayerInfo pool_info, DataType data_type) { - ARM_COMPUTE_UNUSED(dst_shape); PoolingLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(src_shape, pool_info, data_type, DataLayout::NCHW, 0, QuantizationInfo()); } }; diff --git a/tests/validation/reference/PoolingLayer.cpp b/tests/validation/reference/PoolingLayer.cpp index 071c20ed56..f3f456b26e 100644 --- a/tests/validation/reference/PoolingLayer.cpp +++ b/tests/validation/reference/PoolingLayer.cpp @@ -25,6 +25,7 @@ #include "Permute.h" #include "arm_compute/core/Types.h" +#include "arm_compute/core/utils/misc/ShapeCalculator.h" #include "tests/validation/FixedPoint.h" #include "tests/validation/Helpers.h" @@ -36,24 +37,7 @@ namespace validation { namespace reference { -namespace -{ -TensorShape calculate_output_shape(TensorShape shape, const PoolingLayerInfo &info) -{ - TensorShape dst_shape = shape; - const int pool_size_x = info.is_global_pooling() ? shape.x() : info.pool_size().width; - const int pool_size_y = info.is_global_pooling() ? shape.y() : info.pool_size().height; - const std::pair<unsigned int, unsigned int> scaled_dims = arm_compute::scaled_dimensions(shape.x(), - shape.y(), - pool_size_x, - pool_size_y, - info.pad_stride_info()); - dst_shape.set(0, scaled_dims.first); - dst_shape.set(1, scaled_dims.second); - - return dst_shape; -} -} // namespace +using namespace arm_compute::misc::shape_calculator; template <typename T> SimpleTensor<T> pooling_layer_nchw(const SimpleTensor<T> &src, SimpleTensor<T> &dst, const PoolingLayerInfo &info) @@ -187,7 +171,10 @@ SimpleTensor<T> pooling_layer(const SimpleTensor<T> &src, const PoolingLayerInfo bool exclude_padding = info.exclude_padding(); // Create reference - SimpleTensor<T> dst{ calculate_output_shape(src.shape(), info), src.data_type(), 1, src.fixed_point_position() }; + TensorInfo src_info(src.shape(), 1, src.data_type(), src.fixed_point_position()); + src_info.set_data_layout(src.data_layout()); + + SimpleTensor<T> dst{ compute_pool_shape(src_info, info), src.data_type(), 1, src.fixed_point_position() }; const auto w_dst = static_cast<int>(dst.shape()[0]); const auto h_dst = static_cast<int>(dst.shape()[1]); @@ -300,18 +287,22 @@ SimpleTensor<uint8_t> pooling_layer<uint8_t>(const SimpleTensor<uint8_t> &src, c template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type> SimpleTensor<T> pooling_layer(const SimpleTensor<T> &src, const PoolingLayerInfo &info) { + TensorInfo src_info(src.shape(), 1, src.data_type(), src.fixed_point_position()); + src_info.set_data_layout(src.data_layout()); + + SimpleTensor<T> dst{ compute_pool_shape(src_info, info), src.data_type(), 1, src.fixed_point_position() }; + if(src.data_layout() == DataLayout::NHWC) { SimpleTensor<T> src_nchw = reference::permute<T>(src, PermutationVector(1U, 2U, 0U)); - SimpleTensor<T> dst{ calculate_output_shape(src_nchw.shape(), info), src_nchw.data_type(), 1, src_nchw.fixed_point_position() }; + SimpleTensor<T> dst_nchw = reference::permute<T>(dst, PermutationVector(1U, 2U, 0U)); - pooling_layer_nchw<T>(src_nchw, dst, info); + pooling_layer_nchw<T>(src_nchw, dst_nchw, info); - return reference::permute<T>(dst, PermutationVector(2U, 0U, 1U)); + return reference::permute<T>(dst_nchw, PermutationVector(2U, 0U, 1U)); } else { - SimpleTensor<T> dst{ calculate_output_shape(src.shape(), info), src.data_type(), 1, src.fixed_point_position() }; return pooling_layer_nchw<T>(src, dst, info); } } |