Gian Marco | 37908d9 | 2017-11-07 14:38:22 +0000 | [diff] [blame] | 1 | /* |
Anthony Barbier | 77e4a2d | 2018-02-14 11:34:16 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Gian Marco | 37908d9 | 2017-11-07 14:38:22 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #include "arm_compute/core/Types.h" |
| 25 | #include "arm_compute/runtime/NEON/functions/NEGaussianPyramid.h" |
| 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
| 28 | #include "tests/NEON/Accessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
| 30 | #include "tests/datasets/BorderModeDataset.h" |
| 31 | #include "tests/datasets/ShapeDatasets.h" |
| 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Macros.h" |
| 34 | #include "tests/framework/datasets/Datasets.h" |
Gian Marco | 37908d9 | 2017-11-07 14:38:22 +0000 | [diff] [blame] | 35 | #include "tests/validation/Validation.h" |
| 36 | #include "tests/validation/fixtures/GaussianPyramidHalfFixture.h" |
Georgios Pinitas | 5a7e776 | 2017-12-01 16:27:29 +0000 | [diff] [blame] | 37 | #include "tests/validation/reference/Utils.h" |
Gian Marco | 37908d9 | 2017-11-07 14:38:22 +0000 | [diff] [blame] | 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | namespace |
| 46 | { |
| 47 | constexpr AbsoluteTolerance<float> tolerance_fp32(1.0f); /**< Tolerance value for comparing reference's output against implementation's output */ |
| 48 | |
| 49 | const auto small_gaussian_pyramid_levels = combine(datasets::Medium2DShapes(), datasets::BorderModes()) * framework::dataset::make("numlevels", 2, 3); |
| 50 | const auto large_gaussian_pyramid_levels = combine(datasets::Large2DShapes(), datasets::BorderModes()) * framework::dataset::make("numlevels", 2, 5); |
| 51 | |
| 52 | template <typename T, typename U> |
Anthony Barbier | 77e4a2d | 2018-02-14 11:34:16 +0000 | [diff] [blame] | 53 | inline void validate_gaussian_pyramid(const Pyramid &target, const std::vector<SimpleTensor<T>> &reference, BorderMode border_mode, U tolerance, float tolerance_number = 0.0f) |
Gian Marco | 37908d9 | 2017-11-07 14:38:22 +0000 | [diff] [blame] | 54 | { |
| 55 | ValidRegion prev_valid_region = shape_to_valid_region(reference[0].shape()); |
| 56 | |
| 57 | for(size_t i = 1; i < reference.size(); ++i) |
| 58 | { |
| 59 | const ValidRegion valid_region = shape_to_valid_region_gaussian_pyramid_half(reference[i - 1].shape(), prev_valid_region, (border_mode == BorderMode::UNDEFINED)); |
| 60 | |
| 61 | // Validate outputs |
Anthony Barbier | 77e4a2d | 2018-02-14 11:34:16 +0000 | [diff] [blame] | 62 | validate(Accessor(*(target.get_pyramid_level(i))), reference[i], valid_region, tolerance, tolerance_number); |
Gian Marco | 37908d9 | 2017-11-07 14:38:22 +0000 | [diff] [blame] | 63 | |
| 64 | // Keep the valid region for the next level |
| 65 | prev_valid_region = valid_region; |
| 66 | } |
| 67 | } |
| 68 | } // namespace |
| 69 | |
| 70 | TEST_SUITE(NEON) |
| 71 | TEST_SUITE(GaussianPyramid) |
| 72 | TEST_SUITE(Half) |
| 73 | |
| 74 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, large_gaussian_pyramid_levels, |
| 75 | shape, border_mode, num_levels) |
| 76 | { |
| 77 | Tensor src = create_tensor<Tensor>(shape, DataType::U8); |
| 78 | |
| 79 | // Create pyramid |
| 80 | PyramidInfo pyramid_info(num_levels, SCALE_PYRAMID_HALF, shape, Format::U8); |
| 81 | Pyramid dst; |
| 82 | dst.init(pyramid_info); |
| 83 | |
| 84 | NEGaussianPyramidHalf gaussian_pyramid_half; |
| 85 | gaussian_pyramid_half.configure(&src, &dst, border_mode, 0); |
| 86 | |
| 87 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 88 | |
| 89 | for(size_t level = 0; level < pyramid_info.num_levels(); ++level) |
| 90 | { |
| 91 | ARM_COMPUTE_EXPECT(dst.get_pyramid_level(level)->info()->is_resizable(), framework::LogLevel::ERRORS); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | template <typename T> |
| 96 | using NEGaussianPyramidHalfFixture = GaussianPyramidHalfValidationFixture<Tensor, Accessor, NEGaussianPyramidHalf, T, Pyramid>; |
| 97 | |
| 98 | FIXTURE_DATA_TEST_CASE(RunSmallGaussianPyramidHalf, NEGaussianPyramidHalfFixture<uint8_t>, framework::DatasetMode::ALL, small_gaussian_pyramid_levels) |
| 99 | { |
| 100 | validate_gaussian_pyramid(_target, _reference, _border_mode, tolerance_fp32); |
| 101 | } |
| 102 | |
| 103 | FIXTURE_DATA_TEST_CASE(RunLargeGaussianPyramidHalf, NEGaussianPyramidHalfFixture<uint8_t>, framework::DatasetMode::NIGHTLY, large_gaussian_pyramid_levels) |
| 104 | { |
Anthony Barbier | 77e4a2d | 2018-02-14 11:34:16 +0000 | [diff] [blame] | 105 | validate_gaussian_pyramid(_target, _reference, _border_mode, tolerance_fp32, 0.01f /* FIXME COMPMID-850: Increase tolerance while waiting for bug fix*/); |
Gian Marco | 37908d9 | 2017-11-07 14:38:22 +0000 | [diff] [blame] | 106 | } |
| 107 | TEST_SUITE_END() |
| 108 | TEST_SUITE_END() |
| 109 | TEST_SUITE_END() |
| 110 | } // namespace validation |
| 111 | } // namespace test |
| 112 | } // namespace arm_compute |