diff options
author | zhenglin <zhenglin.li@arm.com> | 2017-12-12 15:56:09 +0800 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:42:33 +0000 |
commit | 0fb6cf5b6f41a3734ab439f970ba94b96be06c5d (patch) | |
tree | 8d91c456f9134516554adbb4ce2431416b7ec5d5 /tests/validation | |
parent | d598bfd26935fb6cefdf904182760e2acd1cf647 (diff) | |
download | ComputeLibrary-0fb6cf5b6f41a3734ab439f970ba94b96be06c5d.tar.gz |
APPBROWSER-340: Implement NormalizePlanarYUV operator
Change-Id: I943fe27ed83e6c499d8f9919c7083f39f6f25acc
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/113211
Tested-by: Jenkins <bsgcomp@arm.com>
Reviewed-by: Stephen Li <stephen.li@arm.com>
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'tests/validation')
-rw-r--r-- | tests/validation/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp | 88 | ||||
-rwxr-xr-x[-rw-r--r--] | tests/validation/Helpers.h | 14 | ||||
-rw-r--r-- | tests/validation/fixtures/NormalizePlanarYUVLayerFixture.h | 140 | ||||
-rw-r--r-- | tests/validation/reference/NormalizePlanarYUVLayer.cpp | 69 | ||||
-rw-r--r-- | tests/validation/reference/NormalizePlanarYUVLayer.h | 44 |
5 files changed, 355 insertions, 0 deletions
diff --git a/tests/validation/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp b/tests/validation/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp new file mode 100644 index 0000000000..e06b19cfea --- /dev/null +++ b/tests/validation/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "arm_compute/core/Types.h" +#include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" +#include "arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h" +#include "arm_compute/runtime/GLES_COMPUTE/functions/GCNormalizePlanarYUVLayer.h" +#include "tests/GLES_COMPUTE/GCAccessor.h" +#include "tests/PaddingCalculator.h" +#include "tests/datasets/RandomNormalizePlanarYUVLayerDataset.h" +#include "tests/datasets/ShapeDatasets.h" +#include "tests/framework/Asserts.h" +#include "tests/framework/Macros.h" +#include "tests/framework/datasets/Datasets.h" +#include "tests/validation/Validation.h" +#include "tests/validation/fixtures/NormalizePlanarYUVLayerFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace +{ +constexpr AbsoluteTolerance<float> tolerance_f16(0.5f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F16 */ +} // namespace + +TEST_SUITE(GC) +TEST_SUITE(NormalizePlanarYUVLayer) + +template <typename T> +using GCNormalizePlanarYUVLayerFixture = NormalizePlanarYUVLayerValidationFixture<GCTensor, GCAccessor, GCNormalizePlanarYUVLayer, T>; + +DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::RandomNormalizePlanarYUVLayerDataset(), framework::dataset::make("DataType", { DataType::F16 })), + shape0, shape1, dt) +{ + // Create tensors + GCTensor src = create_tensor<GCTensor>(shape0, dt, 1); + GCTensor dst = create_tensor<GCTensor>(shape0, dt, 1); + GCTensor mean = create_tensor<GCTensor>(shape1, dt, 1); + GCTensor sd = create_tensor<GCTensor>(shape1, dt, 1); + + // Create and Configure function + GCNormalizePlanarYUVLayer norm; + norm.configure(&src, &dst, &mean, &sd); + + // Validate valid region + const ValidRegion valid_region = shape_to_valid_region(shape0); + validate(dst.info()->valid_region(), valid_region); +} + +TEST_SUITE(Float) +TEST_SUITE(FP16) +FIXTURE_DATA_TEST_CASE(Random, GCNormalizePlanarYUVLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(datasets::RandomNormalizePlanarYUVLayerDataset(), + framework::dataset::make("DataType", DataType::F16))) +{ + // Validate output + validate(GCAccessor(_target), _reference, tolerance_f16, 0); +} +TEST_SUITE_END() +TEST_SUITE_END() + +TEST_SUITE_END() +TEST_SUITE_END() +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/Helpers.h b/tests/validation/Helpers.h index ab7dbd8a41..ba45968392 100644..100755 --- a/tests/validation/Helpers.h +++ b/tests/validation/Helpers.h @@ -202,6 +202,20 @@ std::pair<T, T> get_batchnormalization_layer_test_bounds(int fixed_point_positio return bounds; } +/** Helper function to get the testing range for NormalizePlanarYUV layer. + * + * @return A pair containing the lower upper testing bounds. + */ +template <typename T> +std::pair<T, T> get_normalize_planar_yuv_layer_test_bounds() +{ + std::pair<T, T> bounds; + + bounds = std::make_pair(-1.f, 1.f); + + return bounds; +} + /** Convert quantized simple tensor into float using tensor quantization information. * * @param[in] src Quantized tensor. diff --git a/tests/validation/fixtures/NormalizePlanarYUVLayerFixture.h b/tests/validation/fixtures/NormalizePlanarYUVLayerFixture.h new file mode 100644 index 0000000000..ae5c53a053 --- /dev/null +++ b/tests/validation/fixtures/NormalizePlanarYUVLayerFixture.h @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_FIXTURE +#define ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_FIXTURE + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "tests/AssetsLibrary.h" +#include "tests/Globals.h" +#include "tests/IAccessor.h" +#include "tests/framework/Asserts.h" +#include "tests/framework/Fixture.h" +#include "tests/validation/Helpers.h" +#include "tests/validation/reference/NormalizePlanarYUVLayer.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +template <typename TensorType, typename AccessorType, typename FunctionType, typename T> +class NormalizePlanarYUVLayerValidationFixedPointFixture : public framework::Fixture +{ +public: + template <typename...> + void setup(TensorShape shape0, TensorShape shape1, DataType dt) + { + _data_type = dt; + _target = compute_target(shape0, shape1, dt); + _reference = compute_reference(shape0, shape1, dt); + } + +protected: + template <typename U> + void fill(U &&src_tensor, U &&mean_tensor, U &&sd_tensor) + { + if(is_data_type_float(_data_type)) + { + float min_bound = 0.f; + float max_bound = 0.f; + std::tie(min_bound, max_bound) = get_normalize_planar_yuv_layer_test_bounds<T>(); + std::uniform_real_distribution<> distribution(min_bound, max_bound); + std::uniform_real_distribution<> distribution_sd(0, max_bound); + library->fill(src_tensor, distribution, 0); + library->fill(mean_tensor, distribution, 1); + library->fill(sd_tensor, distribution_sd, 2); + } + } + + TensorType compute_target(const TensorShape &shape0, const TensorShape &shape1, DataType dt) + { + // Create tensors + TensorType src = create_tensor<TensorType>(shape0, dt, 1); + TensorType dst = create_tensor<TensorType>(shape0, dt, 1); + TensorType mean = create_tensor<TensorType>(shape1, dt, 1); + TensorType sd = create_tensor<TensorType>(shape1, dt, 1); + + // Create and configure function + FunctionType norm; + norm.configure(&src, &dst, &mean, &sd); + + ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(mean.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(sd.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Allocate tensors + src.allocator()->allocate(); + dst.allocator()->allocate(); + mean.allocator()->allocate(); + sd.allocator()->allocate(); + + ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!mean.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!sd.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Fill tensors + fill(AccessorType(src), AccessorType(mean), AccessorType(sd)); + + // Compute function + norm.run(); + + return dst; + } + + SimpleTensor<T> compute_reference(const TensorShape &shape0, const TensorShape &shape1, DataType dt) + { + // Create reference + SimpleTensor<T> ref_src{ shape0, dt, 1 }; + SimpleTensor<T> ref_mean{ shape1, dt, 1 }; + SimpleTensor<T> ref_sd{ shape1, dt, 1 }; + + // Fill reference + fill(ref_src, ref_mean, ref_sd); + + return reference::normalize_planar_yuv_layer(ref_src, ref_mean, ref_sd); + } + + TensorType _target{}; + SimpleTensor<T> _reference{}; + DataType _data_type{}; +}; + +template <typename TensorType, typename AccessorType, typename FunctionType, typename T> +class NormalizePlanarYUVLayerValidationFixture : public NormalizePlanarYUVLayerValidationFixedPointFixture<TensorType, AccessorType, FunctionType, T> +{ +public: + template <typename...> + void setup(TensorShape shape0, TensorShape shape1, DataType dt) + { + NormalizePlanarYUVLayerValidationFixedPointFixture<TensorType, AccessorType, FunctionType, T>::setup(shape0, shape1, dt); + } +}; +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_FIXTURE */ diff --git a/tests/validation/reference/NormalizePlanarYUVLayer.cpp b/tests/validation/reference/NormalizePlanarYUVLayer.cpp new file mode 100644 index 0000000000..2442943bb4 --- /dev/null +++ b/tests/validation/reference/NormalizePlanarYUVLayer.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "NormalizePlanarYUVLayer.h" + +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +// NormalizePlanarYUV Layer for floating point type +template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type *> +SimpleTensor<T> normalize_planar_yuv_layer(const SimpleTensor<T> &src, const SimpleTensor<T> &mean, const SimpleTensor<T> &sd) +{ + SimpleTensor<T> result(src.shape(), src.data_type()); + + const auto cols = static_cast<int>(src.shape()[0]); + const auto rows = static_cast<int>(src.shape()[1]); + const auto depth = static_cast<int>(src.shape()[2]); + const int upper_dims = src.shape().total_size() / (cols * rows * depth); + + for(int r = 0; r < upper_dims; ++r) + { + for(int i = 0; i < depth; ++i) + { + for(int k = 0; k < rows; ++k) + { + for(int l = 0; l < cols; ++l) + { + const int pos = l + k * cols + i * rows * cols + r * cols * rows * depth; + result[pos] = (src[pos] - mean[i]) / sd[i]; + } + } + } + } + return result; +} + +template SimpleTensor<half> normalize_planar_yuv_layer(const SimpleTensor<half> &src, const SimpleTensor<half> &mean, const SimpleTensor<half> &sd); + +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/NormalizePlanarYUVLayer.h b/tests/validation/reference/NormalizePlanarYUVLayer.h new file mode 100644 index 0000000000..c8740a383b --- /dev/null +++ b/tests/validation/reference/NormalizePlanarYUVLayer.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef __ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_H__ +#define __ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type * = nullptr> +SimpleTensor<T> normalize_planar_yuv_layer(const SimpleTensor<T> &src, const SimpleTensor<T> &mean, const SimpleTensor<T> &sd); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_H__ */ |