From 4c2dd54d6983275530ef20f9dbb4ce6080c7307b Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Mon, 13 Nov 2017 12:58:41 +0000 Subject: COMPMID-671: Add global pooling layer support. Change-Id: Iead7497cc03e1e7bde440d2965a7bf54cbfa88bf Reviewed-on: http://mpd-gerrit.cambridge.arm.com/95579 Tested-by: Kaizen Reviewed-by: Joel Liang Reviewed-by: Gian Marco Iodice --- tests/validation/CL/PoolingLayer.cpp | 11 ++++++++++- tests/validation/CPP/PoolingLayer.cpp | 13 +++++++++---- tests/validation/fixtures/PoolingLayerFixture.h | 20 ++++++++++---------- 3 files changed, 29 insertions(+), 15 deletions(-) (limited to 'tests') diff --git a/tests/validation/CL/PoolingLayer.cpp b/tests/validation/CL/PoolingLayer.cpp index b3d56122db..c7c3b4192e 100644 --- a/tests/validation/CL/PoolingLayer.cpp +++ b/tests/validation/CL/PoolingLayer.cpp @@ -78,6 +78,9 @@ DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid pad/size combination TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid pad/size combination TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8, 0), // Invalid parameters + TensorInfo(TensorShape(15U, 13U, 5U), 1, DataType::F32, 0), // Non-rectangular Global Pooling + TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, 0), // Invalid output Global Pooling + TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, 0), }), framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16, 0), TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32, 0), @@ -86,6 +89,9 @@ DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32, 0), TensorInfo(TensorShape(25U, 16U, 2U), 1, DataType::F32, 0), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8, 0), + TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32, 0), + TensorInfo(TensorShape(2U, 2U, 5U), 1, DataType::F32, 0), + TensorInfo(TensorShape(1U, 1U, 5U), 1, DataType::F32, 0), })), framework::dataset::make("PoolInfo", { PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), @@ -94,8 +100,11 @@ DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 2, 0)), PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 0, 2)), PoolingLayerInfo(PoolingType::L2, 3, PadStrideInfo(1, 1, 0, 0)), + PoolingLayerInfo(PoolingType::AVG), + PoolingLayerInfo(PoolingType::MAX), + PoolingLayerInfo(PoolingType::AVG), })), - framework::dataset::make("Expected", { true, false, true, false, true, true, true })), + framework::dataset::make("Expected", { true, false, true, false, true, true, true, true, true, false })), input_info, output_info, pool_info, expected) { ARM_COMPUTE_EXPECT(bool(CLPoolingLayer::validate(&input_info, &output_info, pool_info)) == expected, framework::LogLevel::ERRORS); diff --git a/tests/validation/CPP/PoolingLayer.cpp b/tests/validation/CPP/PoolingLayer.cpp index 90a48e0c44..1a7dd4cbb7 100644 --- a/tests/validation/CPP/PoolingLayer.cpp +++ b/tests/validation/CPP/PoolingLayer.cpp @@ -40,10 +40,11 @@ namespace TensorShape calculate_output_shape(TensorShape shape, PoolingLayerInfo info) { TensorShape dst_shape = shape; + const int pool_size = info.is_global_pooling() ? shape.x() : info.pool_size(); const std::pair scaled_dims = arm_compute::scaled_dimensions(shape.x(), shape.y(), - info.pool_size(), - info.pool_size(), + pool_size, + pool_size, info.pad_stride_info()); dst_shape.set(0, scaled_dims.first); dst_shape.set(1, scaled_dims.second); @@ -55,7 +56,9 @@ TensorShape calculate_output_shape(TensorShape shape, PoolingLayerInfo info) template ::value, int>::type> SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info) { - const int pool_size = info.pool_size(); + ARM_COMPUTE_ERROR_ON(info.is_global_pooling() && (src.shape().x() != src.shape().y())); + + const int pool_size = info.is_global_pooling() ? src.shape().x() : info.pool_size(); PoolingType type = info.pool_type(); int pool_stride_x = info.pad_stride_info().stride().first; int pool_stride_y = info.pad_stride_info().stride().second; @@ -164,7 +167,9 @@ SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info) template ::value, int>::type> SimpleTensor pooling_layer(const SimpleTensor &src, PoolingLayerInfo info) { - const int pool_size = info.pool_size(); + ARM_COMPUTE_ERROR_ON(info.is_global_pooling() && (src.shape().x() != src.shape().y())); + + const int pool_size = info.is_global_pooling() ? src.shape().x() : info.pool_size(); PoolingType type = info.pool_type(); int pool_stride_x = info.pad_stride_info().stride().first; int pool_stride_y = info.pad_stride_info().stride().second; diff --git a/tests/validation/fixtures/PoolingLayerFixture.h b/tests/validation/fixtures/PoolingLayerFixture.h index d6190e2977..14192517fc 100644 --- a/tests/validation/fixtures/PoolingLayerFixture.h +++ b/tests/validation/fixtures/PoolingLayerFixture.h @@ -47,15 +47,14 @@ class PoolingLayerValidationGenericFixture : public framework::Fixture { public: template - void setup(TensorShape shape, PoolingType pool_type, int pool_size, PadStrideInfo pad_stride_info, bool exclude_padding, - DataType data_type, int fractional_bits, QuantizationInfo quantization_info) + void setup(TensorShape shape, PoolingLayerInfo pool_info, DataType data_type, int fractional_bits, QuantizationInfo quantization_info) { _fractional_bits = fractional_bits; _quantization_info = quantization_info; - PoolingLayerInfo info(pool_type, pool_size, pad_stride_info, exclude_padding); + _pool_info = pool_info; - _target = compute_target(shape, info, data_type, fractional_bits, quantization_info); - _reference = compute_reference(shape, info, data_type, fractional_bits, quantization_info); + _target = compute_target(shape, pool_info, data_type, fractional_bits, quantization_info); + _reference = compute_reference(shape, pool_info, data_type, fractional_bits, quantization_info); } protected: @@ -125,6 +124,7 @@ protected: SimpleTensor _reference{}; int _fractional_bits{}; QuantizationInfo _quantization_info{}; + PoolingLayerInfo _pool_info{}; }; template @@ -134,7 +134,7 @@ public: template void setup(TensorShape shape, PoolingType pool_type, int pool_size, PadStrideInfo pad_stride_info, bool exclude_padding, DataType data_type) { - PoolingLayerValidationGenericFixture::setup(shape, pool_type, pool_size, pad_stride_info, exclude_padding, + PoolingLayerValidationGenericFixture::setup(shape, PoolingLayerInfo(pool_type, pool_size, pad_stride_info, exclude_padding), data_type, 0, QuantizationInfo()); } }; @@ -146,7 +146,7 @@ public: template void setup(TensorShape shape, PoolingType pool_type, int pool_size, PadStrideInfo pad_stride_info, bool exclude_padding, DataType data_type, int fractional_bits) { - PoolingLayerValidationGenericFixture::setup(shape, pool_type, pool_size, pad_stride_info, exclude_padding, + PoolingLayerValidationGenericFixture::setup(shape, PoolingLayerInfo(pool_type, pool_size, pad_stride_info, exclude_padding), data_type, fractional_bits, QuantizationInfo()); } }; @@ -158,19 +158,19 @@ public: template void setup(TensorShape shape, PoolingType pool_type, int pool_size, PadStrideInfo pad_stride_info, bool exclude_padding, DataType data_type, QuantizationInfo quantization_info) { - PoolingLayerValidationGenericFixture::setup(shape, pool_type, pool_size, pad_stride_info, exclude_padding, + PoolingLayerValidationGenericFixture::setup(shape, PoolingLayerInfo(pool_type, pool_size, pad_stride_info, exclude_padding), data_type, 0, quantization_info); } }; template -class GlobalPoolingLayerValidationFixture : public PoolingLayerValidationFixture +class GlobalPoolingLayerValidationFixture : public PoolingLayerValidationGenericFixture { public: template void setup(TensorShape shape, PoolingType pool_type, DataType data_type) { - PoolingLayerValidationFixture::setup(shape, pool_type, shape.x(), PadStrideInfo(1, 1, 0, 0), true, data_type); + PoolingLayerValidationGenericFixture::setup(shape, PoolingLayerInfo(pool_type), data_type, 0, QuantizationInfo()); } }; } // namespace validation -- cgit v1.2.1