1 /*
2 * Copyright (c) 2018-2021 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/runtime/CL/CLScheduler.h"
25 #include "arm_compute/runtime/CL/functions/CLBoundingBoxTransform.h"
26 #include "tests/CL/CLAccessor.h"
27 #include "tests/Globals.h"
28 #include "tests/framework/Macros.h"
29 #include "tests/framework/datasets/Datasets.h"
30 #include "tests/validation/Validation.h"
31 #include "tests/validation/fixtures/BoundingBoxTransformFixture.h"
32 #include "utils/TypePrinter.h"
33
34 namespace arm_compute
35 {
36 namespace test
37 {
38 namespace validation
39 {
40 namespace
41 {
42 RelativeTolerance<float> relative_tolerance_f32(0.01f);
43 AbsoluteTolerance<float> absolute_tolerance_f32(0.001f);
44
45 RelativeTolerance<half> relative_tolerance_f16(half(0.2));
46 AbsoluteTolerance<float> absolute_tolerance_f16(half(0.02f));
47
48 constexpr AbsoluteTolerance<uint16_t> tolerance_qasymm16(1);
49
50 // *INDENT-OFF*
51 // clang-format off
52 const auto BboxInfoDataset = framework::dataset::make("BboxInfo", { BoundingBoxTransformInfo(20U, 20U, 2U, true),
53 BoundingBoxTransformInfo(128U, 128U, 4U, true),
54 BoundingBoxTransformInfo(800U, 600U, 1U, false),
55 BoundingBoxTransformInfo(800U, 600U, 2U, true, { { 1.0, 0.5, 1.5, 2.0 } }),
56 BoundingBoxTransformInfo(800U, 600U, 4U, false, { { 1.0, 0.5, 1.5, 2.0 } }),
57 BoundingBoxTransformInfo(800U, 600U, 4U, false, { { 1.0, 0.5, 1.5, 2.0 } }, true)
58 });
59
60 const auto DeltaDataset = framework::dataset::make("DeltasShape", { TensorShape(36U, 1U),
61 TensorShape(36U, 2U),
62 TensorShape(36U, 2U),
63 TensorShape(40U, 1U),
64 TensorShape(40U, 20U),
65 TensorShape(40U, 100U),
66 TensorShape(40U, 200U)
67 });
68 // clang-format on
69 // *INDENT-ON*
70 } // namespace
71
72 TEST_SUITE(CL)
TEST_SUITE(BBoxTransform)73 TEST_SUITE(BBoxTransform)
74
75 // *INDENT-OFF*
76 // clang-format off
77 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
78 framework::dataset::make("BoxesInfo", { TensorInfo(TensorShape(4U, 128U), 1, DataType::F32),
79 TensorInfo(TensorShape(5U, 128U), 1, DataType::F32), // Wrong number of box fields
80 TensorInfo(TensorShape(4U, 128U), 1, DataType::F16), // Wrong data type
81 TensorInfo(TensorShape(4U, 128U), 1, DataType::F32), // Wrong number of classes
82 TensorInfo(TensorShape(4U, 128U), 1, DataType::F32), // Deltas and predicted boxes have different dimensions
83 TensorInfo(TensorShape(4U, 128U), 1, DataType::F32)}), // Scaling is zero
84 framework::dataset::make("PredBoxesInfo",{ TensorInfo(TensorShape(128U, 128U), 1, DataType::F32),
85 TensorInfo(TensorShape(128U, 128U), 1, DataType::F32),
86 TensorInfo(TensorShape(127U, 128U), 1, DataType::F32),
87 TensorInfo(TensorShape(128U, 100U), 1, DataType::F32),
88 TensorInfo(TensorShape(128U, 100U), 1, DataType::F32),
89 TensorInfo(TensorShape(128U, 128U), 1, DataType::F32)})),
90 framework::dataset::make("DeltasInfo", { TensorInfo(TensorShape(128U, 128U), 1, DataType::F32),
91 TensorInfo(TensorShape(128U, 128U), 1, DataType::F32),
92 TensorInfo(TensorShape(127U, 128U), 1, DataType::F32),
93 TensorInfo(TensorShape(128U, 100U), 1, DataType::F32),
94 TensorInfo(TensorShape(128U, 128U), 1, DataType::F32),
95 TensorInfo(TensorShape(128U, 128U), 1, DataType::F32)})),
96 framework::dataset::make("BoundingBoxTransofmInfo", { BoundingBoxTransformInfo(800.f, 600.f, 1.f),
97 BoundingBoxTransformInfo(800.f, 600.f, 1.f),
98 BoundingBoxTransformInfo(800.f, 600.f, 1.f),
99 BoundingBoxTransformInfo(800.f, 600.f, 1.f),
100 BoundingBoxTransformInfo(800.f, 600.f, 0.f)})),
101 framework::dataset::make("Expected", { true, false, false, false, false, false})),
102 boxes_info, pred_boxes_info, deltas_info, bbox_info, expected)
103 {
104 ARM_COMPUTE_EXPECT(bool(CLBoundingBoxTransform::validate(&boxes_info.clone()->set_is_resizable(true), &pred_boxes_info.clone()->set_is_resizable(true), &deltas_info.clone()->set_is_resizable(true), bbox_info)) == expected, framework::LogLevel::ERRORS);
105 }
106 // clang-format on
107 // *INDENT-ON*
108
109 template <typename T>
110 using CLBoundingBoxTransformFixture = BoundingBoxTransformFixture<CLTensor, CLAccessor, CLBoundingBoxTransform, T>;
111
112 TEST_SUITE(Float)
TEST_SUITE(FP32)113 TEST_SUITE(FP32)
114 FIXTURE_DATA_TEST_CASE(BoundingBox, CLBoundingBoxTransformFixture<float>, framework::DatasetMode::ALL,
115 combine(combine(DeltaDataset, BboxInfoDataset), framework::dataset::make("DataType", { DataType::F32 })))
116 {
117 // Validate output
118 validate(CLAccessor(_target), _reference, relative_tolerance_f32, 0.f, absolute_tolerance_f32);
119 }
120 TEST_SUITE_END() // FP32
121
TEST_SUITE(FP16)122 TEST_SUITE(FP16)
123 FIXTURE_DATA_TEST_CASE(BoundingBox, CLBoundingBoxTransformFixture<half>, framework::DatasetMode::ALL,
124 combine(combine(DeltaDataset, BboxInfoDataset), framework::dataset::make("DataType", { DataType::F16 })))
125 {
126 // Validate output
127 validate(CLAccessor(_target), _reference, relative_tolerance_f16, 0.03f, absolute_tolerance_f16);
128 }
129 TEST_SUITE_END() // FP16
130 TEST_SUITE_END() // Float
131
132 template <typename T>
133 using CLBoundingBoxTransformQuantizedFixture = BoundingBoxTransformQuantizedFixture<CLTensor, CLAccessor, CLBoundingBoxTransform, T>;
134
135 TEST_SUITE(Quantized)
TEST_SUITE(QASYMM16)136 TEST_SUITE(QASYMM16)
137 FIXTURE_DATA_TEST_CASE(BoundingBox, CLBoundingBoxTransformQuantizedFixture<uint16_t>, framework::DatasetMode::ALL,
138 combine(combine(combine(DeltaDataset, BboxInfoDataset), framework::dataset::make("DataType", { DataType::QASYMM16 })),
139 framework::dataset::make("DeltasQuantInfo", { QuantizationInfo(1.f / 255.f, 127) })))
140 {
141 // Validate output
142 validate(CLAccessor(_target), _reference, tolerance_qasymm16);
143 }
144 TEST_SUITE_END() // QASYMM16
145 TEST_SUITE_END() // Quantized
146
147 TEST_SUITE_END() // BBoxTransform
148 TEST_SUITE_END() // CL
149 } // namespace validation
150 } // namespace test
151 } // namespace arm_compute
152