blob: fa8d3cbad6411d7615b654994dcbe98201147099 [file] [log] [blame]
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +01001/*
2 * Copyright (c) 2017 ARM Limited.
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/NEHarrisCorners.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
28#include "tests/NEON/Accessor.h"
29#include "tests/NEON/ArrayAccessor.h"
30#include "tests/PaddingCalculator.h"
31#include "tests/datasets/BorderModeDataset.h"
32#include "tests/datasets/ShapeDatasets.h"
33#include "tests/framework/Asserts.h"
34#include "tests/framework/Macros.h"
35#include "tests/framework/datasets/Datasets.h"
36#include "tests/validation/Validation.h"
37#include "tests/validation/fixtures/HarrisCornersFixture.h"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45namespace
46{
Georgios Pinitas5962f132017-12-11 16:59:29 +000047/* Allowed percentage of keypoints missing for target */
48float allowed_missing_percentage = 10.f;
49/* Allowed percentage of keypoints mismatching between target and reference */
50float allowed_mismatch_percentage = 10.f;
51
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +010052const auto use_fp16 = framework::dataset::make("UseFP16",
53{
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000054#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +010055 true,
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000056#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +010057 false
58});
59
60const auto data = combine(framework::dataset::make("GradientSize", { 3, 5, 7 }), combine(framework::dataset::make("BlockSize", { 3, 5, 7 }), combine(datasets::BorderModes(), use_fp16)));
61} // namespace
62
63TEST_SUITE(NEON)
64TEST_SUITE(HarrisCorners)
65
66DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), data), framework::dataset::make("Format", Format::U8)), shape,
67 gradient_size, block_size, border_mode, use_fp16, format)
68{
69 std::mt19937 gen(library->seed());
70 std::uniform_real_distribution<float> real_dist(0.f, 0.01f);
71
72 const float threshold = real_dist(gen);
73 const float sensitivity = real_dist(gen);
74
75 constexpr float max_euclidean_distance = 30.f;
76 real_dist = std::uniform_real_distribution<float>(0.f, max_euclidean_distance);
77 const float min_dist = real_dist(gen);
78
79 // Generate a random constant value
80 std::uniform_int_distribution<uint8_t> int_dist(0, 255);
81 const uint8_t constant_border_value = int_dist(gen);
82
83 // Create tensors
84 Tensor src = create_tensor<Tensor>(shape, data_type_from_format(format));
85 src.info()->set_format(format);
86 KeyPointArray corners;
87
88 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
89
90 // Create harris corners configure function
91 NEHarrisCorners harris_corners;
92 harris_corners.configure(&src, threshold, min_dist, sensitivity, gradient_size, block_size, &corners, border_mode, constant_border_value, use_fp16);
93
94 // Validate padding
95 PaddingCalculator calculator(shape.x(), 8);
96
97 calculator.set_border_mode(border_mode);
98 calculator.set_border_size(gradient_size / 2);
99 calculator.set_access_offset(-gradient_size / 2);
100 calculator.set_accessed_elements(16);
101
102 const PaddingSize padding = calculator.required_padding();
103
104 validate(src.info()->padding(), padding);
105}
106
107template <typename T>
108using NEHarrisCornersFixture = HarrisCornersValidationFixture<Tensor, Accessor, KeyPointArray, NEHarrisCorners, T>;
109
110FIXTURE_DATA_TEST_CASE(RunSmall, NEHarrisCornersFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::Small2DShapes(), data), framework::dataset::make("Format", Format::U8)))
111{
112 // Validate output
113 ArrayAccessor<KeyPoint> array(_target);
Georgios Pinitas5962f132017-12-11 16:59:29 +0000114 validate_keypoints(array.buffer(),
115 array.buffer() + array.num_values(),
116 _reference.begin(),
117 _reference.end(),
118 RelativeTolerance<float>(0.0001f),
119 allowed_missing_percentage,
120 allowed_mismatch_percentage);
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +0100121}
122
123FIXTURE_DATA_TEST_CASE(RunLarge, NEHarrisCornersFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::Large2DShapes(), data), framework::dataset::make("Format", Format::U8)))
124{
125 // Validate output
126 ArrayAccessor<KeyPoint> array(_target);
Georgios Pinitas5962f132017-12-11 16:59:29 +0000127 validate_keypoints(array.buffer(),
128 array.buffer() + array.num_values(),
129 _reference.begin(),
130 _reference.end(),
131 RelativeTolerance<float>(0.0001f),
132 allowed_missing_percentage,
133 allowed_mismatch_percentage);
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +0100134}
135
136TEST_SUITE_END()
137TEST_SUITE_END()
138} // namespace validation
139} // namespace test
140} // namespace arm_compute