blob: b85fe50627fa57149a684fd22bb4bedca571a594 [file] [log] [blame]
Pablo Telloe96e4f02018-12-21 16:47:23 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019 Arm Limited.
Pablo Telloe96e4f02018-12-21 16:47:23 +00003 *
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"
Isabella Gottardi883bad72019-07-15 17:33:07 +010025#include "arm_compute/runtime/CPP/functions/CPPNonMaximumSuppression.h"
Pablo Telloe96e4f02018-12-21 16:47:23 +000026#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/ShapeDatasets.h"
31#include "tests/framework/Asserts.h"
32#include "tests/framework/Macros.h"
33#include "tests/framework/datasets/Datasets.h"
34#include "tests/validation/Validation.h"
35#include "tests/validation/fixtures/NonMaxSuppressionFixture.h"
36
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
Isabella Gottardi883bad72019-07-15 17:33:07 +010045const auto max_output_boxes_dataset = framework::dataset::make("MaxOutputBoxes", 1, 10);
46const auto score_threshold_dataset = framework::dataset::make("ScoreThreshold", { 0.1f, 0.5f, 0.f, 1.f });
47const auto iou_nms_threshold_dataset = framework::dataset::make("NMSThreshold", { 0.1f, 0.5f, 0.f, 1.f });
48const auto NMSParametersSmall = datasets::Small2DNonMaxSuppressionShapes() * max_output_boxes_dataset * score_threshold_dataset * iou_nms_threshold_dataset;
49const auto NMSParametersBig = datasets::Large2DNonMaxSuppressionShapes() * max_output_boxes_dataset * score_threshold_dataset * iou_nms_threshold_dataset;
Pablo Telloe96e4f02018-12-21 16:47:23 +000050
51} // namespace
52
53TEST_SUITE(CPP)
54TEST_SUITE(NMS)
55
56// *INDENT-OFF*
57// clang-format off
58DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(
59 framework::dataset::make("BoundingBox",{
60 TensorInfo(TensorShape(4U, 100U), 1, DataType::F32),
61 TensorInfo(TensorShape(1U, 4U, 2U), 1, DataType::F32), // invalid shape
62 TensorInfo(TensorShape(4U, 2U), 1, DataType::S32), // invalid data type
63 TensorInfo(TensorShape(4U, 3U), 1, DataType::F32),
64 TensorInfo(TensorShape(4U, 66U), 1, DataType::F32),
65 TensorInfo(TensorShape(4U, 100U), 1, DataType::F32),
66 TensorInfo(TensorShape(4U, 100U), 1, DataType::F32),
67 TensorInfo(TensorShape(4U, 100U), 1, DataType::F32),
68 TensorInfo(TensorShape(4U, 100U), 1, DataType::F32),
69 TensorInfo(TensorShape(4U, 100U), 1, DataType::F32),
70 }),
71 framework::dataset::make("Scores", {
72 TensorInfo(TensorShape(100U), 1, DataType::F32),
73 TensorInfo(TensorShape(37U, 2U, 13U, 27U), 1, DataType::F32), // invalid shape
74 TensorInfo(TensorShape(4U), 1, DataType::F32),
75 TensorInfo(TensorShape(3U), 1, DataType::U8), // invalid data type
76 TensorInfo(TensorShape(66U), 1, DataType::F32), // invalid data type
77 TensorInfo(TensorShape(100U), 1, DataType::F32),
78 TensorInfo(TensorShape(100U), 1, DataType::F32),
79 TensorInfo(TensorShape(100U), 1, DataType::F32),
80 TensorInfo(TensorShape(100U), 1, DataType::F32),
81 TensorInfo(TensorShape(100U), 1, DataType::F32),
82 })),
83 framework::dataset::make("Indices", {
84 TensorInfo(TensorShape(100U), 1, DataType::S32),
85 TensorInfo(TensorShape(100U), 1, DataType::S32),
86 TensorInfo(TensorShape(4U), 1, DataType::S32),
87 TensorInfo(TensorShape(3U), 1, DataType::S32),
88 TensorInfo(TensorShape(200U), 1, DataType::S32), // indices bigger than max bbs, OK because max_output is 66
89 TensorInfo(TensorShape(100U), 1, DataType::F32), // invalid data type
90 TensorInfo(TensorShape(100U), 1, DataType::S32),
91 TensorInfo(TensorShape(100U), 1, DataType::S32),
92 TensorInfo(TensorShape(100U), 1, DataType::S32),
93 TensorInfo(TensorShape(100U), 1, DataType::S32),
94
95 })),
96 framework::dataset::make("max_output", {
97 10U, 2U,4U, 3U,66U, 1U,
98 0U, /* invalid, must be greater than 0 */
99 10000U, /* OK, clamped to indices' size */
100 100U,
101 10U,
102 })),
103 framework::dataset::make("score_threshold", {
104 0.1f, 0.4f, 0.2f,0.8f,0.3f, 0.01f, 0.5f, 0.45f,
105 -1.f, /* invalid value, must be in [0,1] */
106 0.5f,
107 })),
108 framework::dataset::make("nms_threshold", {
109 0.3f, 0.7f, 0.1f,0.13f,0.2f, 0.97f, 0.76f, 0.87f, 0.1f,
110 10.f, /* invalid value, must be in [0,1]*/
111 })),
112 framework::dataset::make("Expected", {
113 true, false, false, false, true, false, false,true, false, false
114 })),
115
116 bbox_info, scores_info, indices_info, max_out, score_threshold, nms_threshold, expected)
117{
118 ARM_COMPUTE_EXPECT(bool(CPPNonMaximumSuppression::validate(&bbox_info.clone()->set_is_resizable(false),
119 &scores_info.clone()->set_is_resizable(false),
120 &indices_info.clone()->set_is_resizable(false),
121 max_out,score_threshold,nms_threshold)) == expected, framework::LogLevel::ERRORS);
122}
123// clang-format on
124// *INDENT-ON*
125
126using CPPNonMaxSuppressionFixture = NMSValidationFixture<Tensor, Accessor, CPPNonMaximumSuppression>;
127
128FIXTURE_DATA_TEST_CASE(RunSmall, CPPNonMaxSuppressionFixture, framework::DatasetMode::PRECOMMIT, NMSParametersSmall)
129{
130 // Validate output
131 validate(Accessor(_target), _reference);
132}
133
134FIXTURE_DATA_TEST_CASE(RunLarge, CPPNonMaxSuppressionFixture, framework::DatasetMode::NIGHTLY, NMSParametersBig)
135{
136 // Validate output
137 validate(Accessor(_target), _reference);
138}
139
Pablo Telloe96e4f02018-12-21 16:47:23 +0000140TEST_SUITE_END() // NMS
Isabella Gottardi883bad72019-07-15 17:33:07 +0100141TEST_SUITE_END() // CPP
Pablo Telloe96e4f02018-12-21 16:47:23 +0000142} // namespace validation
143} // namespace test
144} // namespace arm_compute