Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 Arm Limited. |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [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/CL/CLArray.h" |
| 26 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 27 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 28 | #include "arm_compute/runtime/CL/functions/CLHarrisCorners.h" |
| 29 | #include "tests/CL/CLAccessor.h" |
| 30 | #include "tests/CL/CLArrayAccessor.h" |
| 31 | #include "tests/PaddingCalculator.h" |
| 32 | #include "tests/datasets/BorderModeDataset.h" |
Alex Gilday | 345ab18 | 2018-01-09 11:40:19 +0000 | [diff] [blame] | 33 | #include "tests/datasets/ImageFileDatasets.h" |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 34 | #include "tests/datasets/ShapeDatasets.h" |
| 35 | #include "tests/framework/Asserts.h" |
| 36 | #include "tests/framework/Macros.h" |
| 37 | #include "tests/framework/datasets/Datasets.h" |
| 38 | #include "tests/validation/Validation.h" |
| 39 | #include "tests/validation/fixtures/HarrisCornersFixture.h" |
| 40 | |
| 41 | namespace arm_compute |
| 42 | { |
| 43 | namespace test |
| 44 | { |
| 45 | namespace validation |
| 46 | { |
| 47 | namespace |
| 48 | { |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 49 | const auto data_nightly = combine(framework::dataset::make("GradientSize", { 3, 5, 7 }), combine(framework::dataset::make("BlockSize", { 3, 5, 7 }), datasets::BorderModes())); |
| 50 | const auto data_precommit = combine(framework::dataset::make("GradientSize", { 3 }), combine(framework::dataset::make("BlockSize", { 3 }), datasets::BorderModes())); |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 51 | } // namespace |
| 52 | |
| 53 | TEST_SUITE(CL) |
| 54 | TEST_SUITE(HarrisCorners) |
| 55 | |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 56 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(datasets::Small2DShapes(), data_nightly), framework::dataset::make("Format", Format::U8)), shape, |
Georgios Pinitas | 09d3451 | 2018-08-30 16:02:11 +0100 | [diff] [blame] | 57 | gradient_size, block_size, border_mode, format) |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 58 | { |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 59 | std::mt19937 gen(library->seed()); |
| 60 | std::uniform_real_distribution<float> real_dist(0.f, 0.01f); |
| 61 | |
| 62 | const float threshold = real_dist(gen); |
| 63 | const float sensitivity = real_dist(gen); |
| 64 | |
| 65 | constexpr float max_euclidean_distance = 30.f; |
| 66 | real_dist = std::uniform_real_distribution<float>(0.f, max_euclidean_distance); |
| 67 | const float min_dist = real_dist(gen); |
| 68 | |
| 69 | // Generate a random constant value |
| 70 | std::uniform_int_distribution<uint8_t> int_dist(0, 255); |
| 71 | const uint8_t constant_border_value = int_dist(gen); |
| 72 | |
| 73 | // Create tensors |
| 74 | CLTensor src = create_tensor<CLTensor>(shape, data_type_from_format(format)); |
| 75 | src.info()->set_format(format); |
| 76 | CLKeyPointArray corners; |
| 77 | |
| 78 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 79 | |
| 80 | // Create harris corners configure function |
| 81 | CLHarrisCorners harris_corners; |
| 82 | harris_corners.configure(&src, threshold, min_dist, sensitivity, gradient_size, block_size, &corners, border_mode, constant_border_value); |
| 83 | |
| 84 | // Validate padding |
| 85 | PaddingCalculator calculator(shape.x(), 8); |
| 86 | |
| 87 | calculator.set_border_mode(border_mode); |
| 88 | calculator.set_border_size(gradient_size / 2); |
| 89 | calculator.set_access_offset(-gradient_size / 2); |
| 90 | calculator.set_accessed_elements(16); |
| 91 | |
| 92 | const PaddingSize padding = calculator.required_padding(); |
| 93 | |
| 94 | validate(src.info()->padding(), padding); |
| 95 | } |
| 96 | |
| 97 | template <typename T> |
| 98 | using CLHarrisCornersFixture = HarrisCornersValidationFixture<CLTensor, CLAccessor, CLKeyPointArray, CLHarrisCorners, T>; |
| 99 | |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 100 | FIXTURE_DATA_TEST_CASE(RunSmall, CLHarrisCornersFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallImageFiles(), data_precommit), framework::dataset::make("Format", |
Alex Gilday | 345ab18 | 2018-01-09 11:40:19 +0000 | [diff] [blame] | 101 | Format::U8))) |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 102 | { |
| 103 | // Validate output |
| 104 | CLArrayAccessor<KeyPoint> array(_target); |
| 105 | validate_keypoints(array.buffer(), array.buffer() + array.num_values(), _reference.begin(), _reference.end(), RelativeTolerance<float>(0.0001f)); |
| 106 | } |
| 107 | |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 108 | FIXTURE_DATA_TEST_CASE(RunLarge, CLHarrisCornersFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeImageFiles(), data_nightly), framework::dataset::make("Format", |
| 109 | Format::U8))) |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 110 | { |
| 111 | // Validate output |
| 112 | CLArrayAccessor<KeyPoint> array(_target); |
| 113 | validate_keypoints(array.buffer(), array.buffer() + array.num_values(), _reference.begin(), _reference.end(), RelativeTolerance<float>(0.0001f)); |
| 114 | } |
| 115 | |
| 116 | TEST_SUITE_END() |
| 117 | TEST_SUITE_END() |
| 118 | } // namespace validation |
| 119 | } // namespace test |
| 120 | } // namespace arm_compute |