From 2d008a476f5f09f63574990a93e8bf606ae5629e Mon Sep 17 00:00:00 2001 From: John Richardson Date: Thu, 22 Mar 2018 13:48:41 +0000 Subject: COMPMID-586: Port LaplacianPyramid to new validation Change-Id: Ic746d5f297eb354e63cefa8c682b03fc339be81d Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/128409 Reviewed-by: Pablo Tello Tested-by: Jenkins Reviewed-by: John Richardson Reviewed-by: Anthony Barbier --- tests/Utils.h | 32 +++++ tests/validation/CL/LaplacianPyramid.cpp | 143 +++++++++++++++++++ tests/validation/NEON/LaplacianPyramid.cpp | 142 +++++++++++++++++++ .../validation/fixtures/LaplacianPyramidFixture.h | 154 +++++++++++++++++++++ tests/validation/reference/LaplacianPyramid.cpp | 70 ++++++++++ tests/validation/reference/LaplacianPyramid.h | 43 ++++++ 6 files changed, 584 insertions(+) create mode 100644 tests/validation/CL/LaplacianPyramid.cpp create mode 100644 tests/validation/NEON/LaplacianPyramid.cpp create mode 100644 tests/validation/fixtures/LaplacianPyramidFixture.h create mode 100644 tests/validation/reference/LaplacianPyramid.cpp create mode 100644 tests/validation/reference/LaplacianPyramid.h diff --git a/tests/Utils.h b/tests/Utils.h index 7d960dd08f..d0eebb1204 100644 --- a/tests/Utils.h +++ b/tests/Utils.h @@ -306,6 +306,38 @@ inline ValidRegion shape_to_valid_region_gaussian_pyramid_half(const TensorShape return valid_region; } +/** Create a valid region for Laplacian Pyramid based on tensor shape and valid region at level "i - 1" and border mode + * + * @note The border size is 2 in case of Laplacian Pyramid + * + * @param[in] a_shape Shape used at level "i - 1" of Laplacian Pyramid + * @param[in] a_valid_region Valid region used at level "i - 1" of Laplacian Pyramid + * @param[in] border_undefined (Optional) Boolean indicating if the border mode is undefined. + * + * return The valid region for the level "i" of Laplacian Pyramid + */ +inline ValidRegion shape_to_valid_region_laplacian_pyramid(const TensorShape &a_shape, const ValidRegion &a_valid_region, bool border_undefined = false) +{ + ValidRegion valid_region = shape_to_valid_region_gaussian_pyramid_half(a_shape, a_valid_region, border_undefined); + + if(border_undefined) + { + const BorderSize gaussian5x5_border(2); + + auto border_left = static_cast(gaussian5x5_border.left); + auto border_right = static_cast(gaussian5x5_border.right); + auto border_top = static_cast(gaussian5x5_border.top); + auto border_bottom = static_cast(gaussian5x5_border.bottom); + + valid_region.anchor.set(0, valid_region.anchor[0] + border_left); + valid_region.anchor.set(1, valid_region.anchor[1] + border_top); + valid_region.shape.set(0, std::max(0, static_cast(valid_region.shape[0]) - border_right - border_left)); + valid_region.shape.set(1, std::max(0, static_cast(valid_region.shape[1]) - border_top - border_bottom)); + } + + return valid_region; +} + /** Write the value after casting the pointer according to @p data_type. * * @warning The type of the value must match the specified data type. diff --git a/tests/validation/CL/LaplacianPyramid.cpp b/tests/validation/CL/LaplacianPyramid.cpp new file mode 100644 index 0000000000..960dceef05 --- /dev/null +++ b/tests/validation/CL/LaplacianPyramid.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2018 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/CL/CLPyramid.h" +#include "arm_compute/runtime/CL/CLTensor.h" +#include "arm_compute/runtime/CL/CLTensorAllocator.h" +#include "arm_compute/runtime/CL/functions/CLLaplacianPyramid.h" +#include "tests/CL/CLAccessor.h" +#include "tests/datasets/BorderModeDataset.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/LaplacianPyramidFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace +{ +const auto small_laplacian_pyramid_levels = framework::dataset::make("NumLevels", 2, 3); +const auto large_laplacian_pyramid_levels = framework::dataset::make("NumLevels", 2, 5); + +const auto formats = combine(framework::dataset::make("FormatIn", Format::U8), framework::dataset::make("FormatOut", Format::S16)); + +template +inline void validate_laplacian_pyramid(const CLPyramid &target, const std::vector> &reference, BorderMode border_mode) +{ + CLTensor *level_image = target.get_pyramid_level(0); + ValidRegion valid_region = shape_to_valid_region(reference[0].shape(), border_mode == BorderMode::UNDEFINED, BorderSize(2)); + + // Validate lowest level + validate(CLAccessor(*level_image), reference[0], valid_region); + + // Validate remaining levels + for(size_t lev = 1; lev < target.info()->num_levels(); lev++) + { + level_image = target.get_pyramid_level(lev); + CLTensor *prev_level_image = target.get_pyramid_level(lev - 1); + + valid_region = shape_to_valid_region_laplacian_pyramid(prev_level_image->info()->tensor_shape(), + prev_level_image->info()->valid_region(), + border_mode == BorderMode::UNDEFINED); + + // Validate level + validate(CLAccessor(*level_image), reference[lev], valid_region); + } +} +} // namespace + +TEST_SUITE(CL) +TEST_SUITE(LaplacianPyramid) + +// *INDENT-OFF* +// clang-format off +DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine( + concat(datasets::Medium2DShapes(), datasets::Large2DShapes()), + datasets::BorderModes()), + large_laplacian_pyramid_levels), + shape, border_mode, num_levels) +{ + // Create pyramid info + PyramidInfo pyramid_info(num_levels, SCALE_PYRAMID_HALF, shape, Format::S16); + CLPyramid dst_pyramid{}; + dst_pyramid.init(pyramid_info); + + // Create Tensors + CLTensor src = create_tensor(shape, Format::U8); + + // The first two dimensions of the output tensor must match the first two + // dimensions of the tensor in the last level of the pyramid + TensorShape dst_shape(shape); + dst_shape.set(0, dst_pyramid.get_pyramid_level(num_levels - 1)->info()->dimension(0)); + dst_shape.set(1, dst_pyramid.get_pyramid_level(num_levels - 1)->info()->dimension(1)); + CLTensor dst = create_tensor(dst_shape, Format::S16); + + // Create and configure function + CLLaplacianPyramid laplacian_pyramid; + laplacian_pyramid.configure(&src, &dst_pyramid, &dst, border_mode, 0); + + ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + for(size_t level = 0; level < pyramid_info.num_levels(); ++level) + { + ARM_COMPUTE_EXPECT(dst_pyramid.get_pyramid_level(level)->info()->is_resizable(), framework::LogLevel::ERRORS); + } +} + +using CLLaplacianPyramidFixture = LaplacianPyramidValidationFixture; + +FIXTURE_DATA_TEST_CASE(RunSmall, CLLaplacianPyramidFixture, framework::DatasetMode::PRECOMMIT, + combine(combine(combine( + datasets::Medium2DShapes(), + datasets::BorderModes()), + small_laplacian_pyramid_levels), + formats)) +{ + validate_laplacian_pyramid(_target, _reference, _border_mode); +} + +FIXTURE_DATA_TEST_CASE(RunLarge, CLLaplacianPyramidFixture, framework::DatasetMode::NIGHTLY, + combine(combine(combine( + datasets::Large2DShapes(), + datasets::BorderModes()), + large_laplacian_pyramid_levels), + formats)) +{ + validate_laplacian_pyramid(_target, _reference, _border_mode); +} +// clang-format on +// *INDENT-ON* + +TEST_SUITE_END() +TEST_SUITE_END() +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/NEON/LaplacianPyramid.cpp b/tests/validation/NEON/LaplacianPyramid.cpp new file mode 100644 index 0000000000..456ae75494 --- /dev/null +++ b/tests/validation/NEON/LaplacianPyramid.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2018 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/NEON/functions/NELaplacianPyramid.h" +#include "arm_compute/runtime/Tensor.h" +#include "arm_compute/runtime/TensorAllocator.h" +#include "tests/NEON/Accessor.h" +#include "tests/datasets/BorderModeDataset.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/LaplacianPyramidFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace +{ +const auto small_laplacian_pyramid_levels = framework::dataset::make("NumLevels", 2, 3); +const auto large_laplacian_pyramid_levels = framework::dataset::make("NumLevels", 2, 5); + +const auto formats = combine(framework::dataset::make("FormatIn", Format::U8), framework::dataset::make("FormatOut", Format::S16)); + +template +inline void validate_laplacian_pyramid(const Pyramid &target, const std::vector> &reference, BorderMode border_mode) +{ + Tensor *level_image = target.get_pyramid_level(0); + ValidRegion valid_region = shape_to_valid_region(reference[0].shape(), border_mode == BorderMode::UNDEFINED, BorderSize(2)); + + // Validate lowest level + validate(Accessor(*level_image), reference[0], valid_region); + + // Validate remaining levels + for(size_t lev = 1; lev < target.info()->num_levels(); lev++) + { + level_image = target.get_pyramid_level(lev); + Tensor *prev_level_image = target.get_pyramid_level(lev - 1); + + valid_region = shape_to_valid_region_laplacian_pyramid(prev_level_image->info()->tensor_shape(), + prev_level_image->info()->valid_region(), + border_mode == BorderMode::UNDEFINED); + + // Validate level + validate(Accessor(*level_image), reference[lev], valid_region); + } +} +} // namespace + +TEST_SUITE(NEON) +TEST_SUITE(LaplacianPyramid) + +// *INDENT-OFF* +// clang-format off +DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine( + concat(datasets::Medium2DShapes(), datasets::Large2DShapes()), + datasets::BorderModes()), + large_laplacian_pyramid_levels), + shape, border_mode, num_levels) +{ + // Create pyramid info + PyramidInfo pyramid_info(num_levels, SCALE_PYRAMID_HALF, shape, Format::S16); + Pyramid dst_pyramid{}; + dst_pyramid.init(pyramid_info); + + // Create Tensors + Tensor src = create_tensor(shape, Format::U8); + + // The first two dimensions of the output tensor must match the first two + // dimensions of the tensor in the last level of the pyramid + TensorShape dst_shape(shape); + dst_shape.set(0, dst_pyramid.get_pyramid_level(num_levels - 1)->info()->dimension(0)); + dst_shape.set(1, dst_pyramid.get_pyramid_level(num_levels - 1)->info()->dimension(1)); + Tensor dst = create_tensor(dst_shape, Format::S16); + + // Create and configure function + NELaplacianPyramid laplacian_pyramid; + laplacian_pyramid.configure(&src, &dst_pyramid, &dst, border_mode, 0); + + ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + for(size_t level = 0; level < pyramid_info.num_levels(); ++level) + { + ARM_COMPUTE_EXPECT(dst_pyramid.get_pyramid_level(level)->info()->is_resizable(), framework::LogLevel::ERRORS); + } +} + +using NELaplacianPyramidFixture = LaplacianPyramidValidationFixture; + +FIXTURE_DATA_TEST_CASE(RunSmall, NELaplacianPyramidFixture, framework::DatasetMode::PRECOMMIT, + combine(combine(combine( + datasets::Medium2DShapes(), + datasets::BorderModes()), + small_laplacian_pyramid_levels), + formats)) +{ + validate_laplacian_pyramid(_target, _reference, _border_mode); +} + +FIXTURE_DATA_TEST_CASE(RunLarge, NELaplacianPyramidFixture, framework::DatasetMode::NIGHTLY, + combine(combine(combine( + datasets::Large2DShapes(), + datasets::BorderModes()), + large_laplacian_pyramid_levels), + formats)) +{ + validate_laplacian_pyramid(_target, _reference, _border_mode); +} +// clang-format on +// *INDENT-ON* + +TEST_SUITE_END() +TEST_SUITE_END() +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/fixtures/LaplacianPyramidFixture.h b/tests/validation/fixtures/LaplacianPyramidFixture.h new file mode 100644 index 0000000000..6344272640 --- /dev/null +++ b/tests/validation/fixtures/LaplacianPyramidFixture.h @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2018 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_LAPLACIAN_PYRAMID_FIXTURE +#define ARM_COMPUTE_TEST_LAPLACIAN_PYRAMID_FIXTURE + +#include "arm_compute/core/IPyramid.h" +#include "arm_compute/core/PyramidInfo.h" +#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/reference/LaplacianPyramid.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +template +class LaplacianPyramidValidationFixture : public framework::Fixture +{ +public: + template + void setup(TensorShape input_shape, BorderMode border_mode, size_t num_levels, Format format_in, Format format_out) + { + std::mt19937 generator(library->seed()); + std::uniform_int_distribution distribution_u8(0, 255); + const T constant_border_value = distribution_u8(generator); + + _pyramid_levels = num_levels; + _border_mode = border_mode; + + _target = compute_target(input_shape, border_mode, constant_border_value, format_in, format_out); + _reference = compute_reference(input_shape, border_mode, constant_border_value, format_in, format_out); + } + +protected: + template + void fill(V &&tensor) + { + library->fill_tensor_uniform(tensor, 0); + } + + PyramidType compute_target(const TensorShape &input_shape, BorderMode border_mode, T constant_border_value, + Format format_in, Format format_out) + { + // Create pyramid + PyramidType pyramid{}; + + // Create Pyramid Info + PyramidInfo pyramid_info(_pyramid_levels, SCALE_PYRAMID_HALF, input_shape, format_out); + + // Use conservative padding strategy to fit all subsequent kernels + pyramid.init_auto_padding(pyramid_info); + + // Create tensors + TensorType src = create_tensor(input_shape, format_in); + + // The first two dimensions of the output tensor must match the first + // two dimensions of the tensor in the last level of the pyramid + TensorShape dst_shape(input_shape); + dst_shape.set(0, pyramid.get_pyramid_level(_pyramid_levels - 1)->info()->dimension(0)); + dst_shape.set(1, pyramid.get_pyramid_level(_pyramid_levels - 1)->info()->dimension(1)); + + // The lowest resolution tensor necessary to reconstruct the input + // tensor from the pyramid. + _dst_target = create_tensor(dst_shape, format_out); + + // Create and configure function + FunctionType laplacian_pyramid; + laplacian_pyramid.configure(&src, &pyramid, &_dst_target, border_mode, constant_border_value); + + ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(_dst_target.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Allocate tensors + src.allocator()->allocate(); + _dst_target.allocator()->allocate(); + + ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!_dst_target.info()->is_resizable(), framework::LogLevel::ERRORS); + + pyramid.allocate(); + + for(size_t i = 0; i < pyramid_info.num_levels(); ++i) + { + ARM_COMPUTE_EXPECT(!pyramid.get_pyramid_level(i)->info()->is_resizable(), framework::LogLevel::ERRORS); + } + + // Fill tensors + fill(AccessorType(src)); + + // Compute function + laplacian_pyramid.run(); + + return pyramid; + } + + std::vector> compute_reference(const TensorShape &shape, BorderMode border_mode, T constant_border_value, + Format format_in, Format format_out) + { + // Create reference + SimpleTensor src{ shape, format_in }; + + // The first two dimensions of the output tensor must match the first + // two dimensions of the tensor in the last level of the pyramid + TensorShape dst_shape(shape); + dst_shape.set(0, static_cast(shape[0] + 1) / static_cast(std::pow(2, _pyramid_levels - 1))); + dst_shape.set(1, static_cast(shape[1] + 1) / static_cast(std::pow(2, _pyramid_levels - 1))); + + _dst_reference = SimpleTensor(dst_shape, format_out); + + // Fill reference + fill(src); + + return reference::laplacian_pyramid(src, _dst_reference, _pyramid_levels, border_mode, constant_border_value); + } + + size_t _pyramid_levels{}; + BorderMode _border_mode{}; + SimpleTensor _dst_reference{}; + TensorType _dst_target{}; + PyramidType _target{}; + std::vector> _reference{}; +}; +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_LAPLACIAN_PYRAMID_FIXTURE */ diff --git a/tests/validation/reference/LaplacianPyramid.cpp b/tests/validation/reference/LaplacianPyramid.cpp new file mode 100644 index 0000000000..566847453b --- /dev/null +++ b/tests/validation/reference/LaplacianPyramid.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2018 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 "LaplacianPyramid.h" + +#include "tests/validation/reference/ArithmeticSubtraction.h" +#include "tests/validation/reference/DepthConvertLayer.h" +#include "tests/validation/reference/Gaussian5x5.h" +#include "tests/validation/reference/GaussianPyramidHalf.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +std::vector> laplacian_pyramid(const SimpleTensor &src, SimpleTensor &dst, size_t num_levels, BorderMode border_mode, uint8_t constant_border_value) +{ + std::vector> pyramid_conv; + std::vector> pyramid_dst; + + // First, a Gaussian pyramid with SCALE_PYRAMID_HALF is created + std::vector> gaussian_level_pyramid = reference::gaussian_pyramid_half(src, border_mode, constant_border_value, num_levels); + + // For each level i, the corresponding image Ii is blurred with Gaussian 5x5 + // filter, and the difference between the two images is the corresponding + // level Li of the Laplacian pyramid + for(size_t i = 0; i < num_levels; ++i) + { + const SimpleTensor level_filtered = reference::gaussian5x5(gaussian_level_pyramid[i], border_mode, constant_border_value); + pyramid_conv.push_back(level_filtered); + + const SimpleTensor level_sub = reference::arithmetic_subtraction(gaussian_level_pyramid[i], level_filtered, dst.data_type(), ConvertPolicy::WRAP); + pyramid_dst.push_back(level_sub); + } + + // Return the lowest resolution image and the pyramid + dst = depth_convert(pyramid_conv[num_levels - 1], DataType::S16, ConvertPolicy::WRAP, 0); + + return pyramid_dst; +} + +template std::vector> laplacian_pyramid(const SimpleTensor &src, SimpleTensor &dst, size_t num_levels, BorderMode border_mode, uint8_t constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/LaplacianPyramid.h b/tests/validation/reference/LaplacianPyramid.h new file mode 100644 index 0000000000..aa76f56968 --- /dev/null +++ b/tests/validation/reference/LaplacianPyramid.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018 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_LAPLACIAN_PYRAMID_H__ +#define __ARM_COMPUTE_TEST_LAPLACIAN_PYRAMID_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +std::vector> laplacian_pyramid(const SimpleTensor &src, SimpleTensor &dst, size_t num_levels, BorderMode border_mode, uint8_t constant_border_value); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_LAPLACIAN_PYRAMID_H__ */ -- cgit v1.2.1