diff options
author | morgolock <pablo.tello@arm.com> | 2020-04-03 16:57:46 +0100 |
---|---|---|
committer | Pablo Marquez <pablo.tello@arm.com> | 2020-05-05 09:36:00 +0000 |
commit | e383c35c336002ce15945ed48facd7d4ba715aa8 (patch) | |
tree | 70dd9d20ec48bf8f41d30a6bbcee957779de8fe0 /tests/validation | |
parent | 6f7585b21a13f4792ef1a55ac943997491ba8aec (diff) | |
download | ComputeLibrary-e383c35c336002ce15945ed48facd7d4ba715aa8.tar.gz |
MLCE-166: Add support for extracting indices in NEPoolingLayer 2x2 NHWC
* Added support for pooling indices in NHWC Poolsize 2x2
Change-Id: Ib2a3468e794f58bbf2c03aba9f6b184b9d76b183
Signed-off-by: morgolock <pablo.tello@arm.com>
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/2997
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Manuel Bottini <manuel.bottini@arm.com>
Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'tests/validation')
-rw-r--r-- | tests/validation/NEON/PoolingLayer.cpp | 3 | ||||
-rw-r--r-- | tests/validation/fixtures/PoolingLayerFixture.h | 12 | ||||
-rw-r--r-- | tests/validation/reference/PoolingLayer.cpp | 47 | ||||
-rw-r--r-- | tests/validation/reference/PoolingLayer.h | 7 |
4 files changed, 41 insertions, 28 deletions
diff --git a/tests/validation/NEON/PoolingLayer.cpp b/tests/validation/NEON/PoolingLayer.cpp index a5876dcd0a..4b073d5352 100644 --- a/tests/validation/NEON/PoolingLayer.cpp +++ b/tests/validation/NEON/PoolingLayer.cpp @@ -35,7 +35,6 @@ #include "tests/framework/datasets/Datasets.h" #include "tests/validation/Validation.h" #include "tests/validation/fixtures/PoolingLayerFixture.h" - namespace arm_compute { namespace test @@ -129,7 +128,7 @@ TEST_SUITE(FP32) FIXTURE_DATA_TEST_CASE(RunIndices, NEPoolingLayerIndicesFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), combine(PoolingLayerIndicesDatasetFPSmall, framework::dataset::make("DataType", DataType::F32))), - framework::dataset::make("DataLayout", { DataLayout::NCHW }) + framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }) )) { diff --git a/tests/validation/fixtures/PoolingLayerFixture.h b/tests/validation/fixtures/PoolingLayerFixture.h index 7f2d7ac225..eb40cea0c2 100644 --- a/tests/validation/fixtures/PoolingLayerFixture.h +++ b/tests/validation/fixtures/PoolingLayerFixture.h @@ -35,7 +35,6 @@ #include "tests/framework/Fixture.h" #include "tests/validation/reference/PoolingLayer.h" #include <random> - namespace arm_compute { namespace test @@ -59,7 +58,7 @@ public: _pool_info = pool_info; _target = compute_target(shape, pool_info, data_type, data_layout, input_qinfo, output_qinfo, indices); - _reference = compute_reference(shape, pool_info, data_type, input_qinfo, output_qinfo, indices); + _reference = compute_reference(shape, pool_info, data_type, data_layout, input_qinfo, output_qinfo, indices); } protected: @@ -92,7 +91,7 @@ protected: TensorType src = create_tensor<TensorType>(shape, data_type, 1, input_qinfo, data_layout); const TensorShape dst_shape = misc::shape_calculator::compute_pool_shape(*(src.info()), info); TensorType dst = create_tensor<TensorType>(dst_shape, data_type, 1, output_qinfo, data_layout); - _target_indices = create_tensor<TensorType>(dst_shape, DataType::U32, 1); + _target_indices = create_tensor<TensorType>(dst_shape, DataType::U32, 1, output_qinfo, data_layout); // Create and configure function FunctionType pool_layer; @@ -120,15 +119,14 @@ protected: return dst; } - SimpleTensor<T> compute_reference(const TensorShape &shape, PoolingLayerInfo info, DataType data_type, + SimpleTensor<T> compute_reference(TensorShape shape, PoolingLayerInfo info, DataType data_type, DataLayout data_layout, QuantizationInfo input_qinfo, QuantizationInfo output_qinfo, bool indices) { // Create reference - SimpleTensor<T> src{ shape, data_type, 1, input_qinfo }; + SimpleTensor<T> src(shape, data_type, 1, input_qinfo); // Fill reference fill(src); - - return reference::pooling_layer<T>(src, info, output_qinfo, indices ? &_ref_indices : nullptr); + return reference::pooling_layer<T>(src, info, output_qinfo, indices ? &_ref_indices : nullptr, data_layout); } TensorType _target{}; diff --git a/tests/validation/reference/PoolingLayer.cpp b/tests/validation/reference/PoolingLayer.cpp index 1a1aebd1b4..778e28d7c1 100644 --- a/tests/validation/reference/PoolingLayer.cpp +++ b/tests/validation/reference/PoolingLayer.cpp @@ -38,7 +38,7 @@ namespace reference using namespace arm_compute::misc::shape_calculator; template <typename T, typename ACC_T, typename std::enable_if<is_floating_point<T>::value, int>::type> -SimpleTensor<T> pooling_layer_internal(const SimpleTensor<T> &src, const PoolingLayerInfo &info, SimpleTensor<uint32_t> *indices) +SimpleTensor<T> pooling_layer_internal(const SimpleTensor<T> &src, const PoolingLayerInfo &info, SimpleTensor<uint32_t> *indices, DataLayout data_layout) { ARM_COMPUTE_ERROR_ON(info.is_global_pooling && (src.shape().x() != src.shape().y())); // Create reference @@ -62,8 +62,10 @@ SimpleTensor<T> pooling_layer_internal(const SimpleTensor<T> &src, const Pooling const auto h_src = static_cast<int>(src.shape()[1]); const int upper_dims = src.shape().total_size() / (w_src * h_src); - const auto w_dst = static_cast<int>(dst.shape()[0]); - const auto h_dst = static_cast<int>(dst.shape()[1]); + const auto w_dst = static_cast<int>(dst.shape()[0]); + const auto h_dst = static_cast<int>(dst.shape()[1]); + TensorShape shape_nhwc(src.shape()); + permute(shape_nhwc, PermutationVector(2U, 0U, 1U)); if(type == PoolingType::MAX) { @@ -89,8 +91,15 @@ SimpleTensor<T> pooling_layer_internal(const SimpleTensor<T> &src, const Pooling const auto val = static_cast<ACC_T>(src[r * h_src * w_src + y * w_src + x]); if(val > max_val) { - max_val = val; - max_index = coord2index(src.shape(), Coordinates(x, y, r)); + max_val = val; + if(data_layout == DataLayout::NCHW) + { + max_index = coord2index(src.shape(), Coordinates(x, y, r)); + } + else + { + max_index = coord2index(shape_nhwc, Coordinates(r, x, y)); + } } } } @@ -159,48 +168,52 @@ SimpleTensor<T> pooling_layer_internal(const SimpleTensor<T> &src, const Pooling return dst; } -template SimpleTensor<float> pooling_layer_internal<float>(const SimpleTensor<float> &src, const PoolingLayerInfo &info, SimpleTensor<uint32_t> *indices); -template SimpleTensor<half> pooling_layer_internal<half>(const SimpleTensor<half> &src, const PoolingLayerInfo &info, SimpleTensor<uint32_t> *indices); -template SimpleTensor<half> pooling_layer_internal<half, float>(const SimpleTensor<half> &src, const PoolingLayerInfo &info, SimpleTensor<uint32_t> *indices); +template SimpleTensor<float> pooling_layer_internal<float>(const SimpleTensor<float> &src, const PoolingLayerInfo &info, SimpleTensor<uint32_t> *indices, DataLayout data_layout); + +template SimpleTensor<half> pooling_layer_internal<half>(const SimpleTensor<half> &src, const PoolingLayerInfo &info, SimpleTensor<uint32_t> *indices, DataLayout data_layout); + +template SimpleTensor<half> pooling_layer_internal<half, float>(const SimpleTensor<half> &src, const PoolingLayerInfo &info, SimpleTensor<uint32_t> *indices, DataLayout data_layout); template <typename T> -SimpleTensor<T> pooling_layer(const SimpleTensor<T> &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices) +SimpleTensor<T> pooling_layer(const SimpleTensor<T> &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices, DataLayout data_layout) { ARM_COMPUTE_UNUSED(output_qinfo); - return pooling_layer_internal<T, T>(src, info, indices); + return pooling_layer_internal<T, T>(src, info, indices, data_layout); } template <> -SimpleTensor<uint8_t> pooling_layer<uint8_t>(const SimpleTensor<uint8_t> &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices) +SimpleTensor<uint8_t> pooling_layer<uint8_t>(const SimpleTensor<uint8_t> &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices, + DataLayout data_layout) { SimpleTensor<float> src_tmp = convert_from_asymmetric(src); - SimpleTensor<float> dst_tmp = pooling_layer_internal<float>(src_tmp, info, indices); + SimpleTensor<float> dst_tmp = pooling_layer_internal<float>(src_tmp, info, indices, data_layout); SimpleTensor<uint8_t> dst = convert_to_asymmetric<uint8_t>(dst_tmp, output_qinfo); return dst; } template <> -SimpleTensor<int8_t> pooling_layer<int8_t>(const SimpleTensor<int8_t> &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices) +SimpleTensor<int8_t> pooling_layer<int8_t>(const SimpleTensor<int8_t> &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices, DataLayout data_layout) { SimpleTensor<float> src_tmp = convert_from_asymmetric(src); - SimpleTensor<float> dst_tmp = pooling_layer_internal<float>(src_tmp, info, indices); + SimpleTensor<float> dst_tmp = pooling_layer_internal<float>(src_tmp, info, indices, data_layout); SimpleTensor<int8_t> dst = convert_to_asymmetric<int8_t>(dst_tmp, output_qinfo); return dst; } template <> -SimpleTensor<half> pooling_layer(const SimpleTensor<half> &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices) +SimpleTensor<half> pooling_layer(const SimpleTensor<half> &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices, DataLayout data_layout) { ARM_COMPUTE_UNUSED(output_qinfo); if(src.data_type() == DataType::F16 && info.fp_mixed_precision) { - return pooling_layer_internal<half, float>(src, info, indices); + return pooling_layer_internal<half, float>(src, info, indices, data_layout); } return pooling_layer_internal<half>(src, info, indices); } -template SimpleTensor<float> pooling_layer(const SimpleTensor<float> &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices); +template SimpleTensor<float> pooling_layer(const SimpleTensor<float> &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices, DataLayout data_layout); + } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/PoolingLayer.h b/tests/validation/reference/PoolingLayer.h index 3ca7f28d5a..346f1c0c9f 100644 --- a/tests/validation/reference/PoolingLayer.h +++ b/tests/validation/reference/PoolingLayer.h @@ -36,9 +36,12 @@ namespace validation namespace reference { template <typename T, typename ACC_T = T, typename std::enable_if<is_floating_point<T>::value, int>::type = 0> -SimpleTensor<T> pooling_layer_internal(const SimpleTensor<T> &src, const PoolingLayerInfo &info, SimpleTensor<uint32_t> *indices); +SimpleTensor<T> pooling_layer_internal(const SimpleTensor<T> &src, const PoolingLayerInfo &info, SimpleTensor<uint32_t> *indices, DataLayout data_layout = DataLayout::NCHW); + template <typename T> -SimpleTensor<T> pooling_layer(const SimpleTensor<T> &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices); +SimpleTensor<T> pooling_layer(const SimpleTensor<T> &src, const PoolingLayerInfo &info, const QuantizationInfo &output_qinfo, SimpleTensor<uint32_t> *indices, + DataLayout data_layout = DataLayout::NCHW); + } // namespace reference } // namespace validation } // namespace test |