blob: 070ea8b3ba3b3897fc4cca9f57a9e2ec6e8c5fec [file] [log] [blame]
Pablo Telloed0e35b2019-08-30 14:44:52 +01001/*
2 * Copyright (c) 2019 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
26#include "arm_compute/runtime/NEON/functions/NEBoundingBoxTransform.h"
27#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
29#include "tests/Globals.h"
30#include "tests/NEON/Accessor.h"
31#include "tests/datasets/ShapeDatasets.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/BoundingBoxTransformFixture.h"
36#include "utils/TypePrinter.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46RelativeTolerance<float> relative_tolerance_f32(0.01f);
47AbsoluteTolerance<float> absolute_tolerance_f32(0.001f);
48#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
49RelativeTolerance<half> relative_tolerance_f16(half(0.2));
50AbsoluteTolerance<float> absolute_tolerance_f16(half(0.02f));
51#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
52
53// *INDENT-OFF*
54// clang-format off
55const auto BboxInfoDataset = framework::dataset::make("BboxInfo", { BoundingBoxTransformInfo(20U, 20U, 2U, true),
56 BoundingBoxTransformInfo(128U, 128U, 4U, true),
57 BoundingBoxTransformInfo(800U, 600U, 1U, false),
58 BoundingBoxTransformInfo(800U, 600U, 2U, true, { { 1.0, 0.5, 1.5, 2.0 } }),
59 BoundingBoxTransformInfo(800U, 600U, 4U, false, { { 1.0, 0.5, 1.5, 2.0 } }),
60 BoundingBoxTransformInfo(800U, 600U, 4U, false, { { 1.0, 0.5, 1.5, 2.0 } }, true)
61 });
62
63const auto DeltaDataset = framework::dataset::make("DeltasShape", { TensorShape(36U, 1U),
64 TensorShape(36U, 2U),
65 TensorShape(36U, 2U),
66 TensorShape(40U, 1U),
67 TensorShape(40U, 20U),
68 TensorShape(40U, 100U),
69 TensorShape(40U, 200U)
70 });
71// clang-format on
72// *INDENT-ON*
73} // namespace
74
75TEST_SUITE(NEON)
76TEST_SUITE(BBoxTransform)
77
78// *INDENT-OFF*
79// clang-format off
80DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
81 framework::dataset::make("BoxesInfo", { TensorInfo(TensorShape(4U, 128U), 1, DataType::F32),
82 TensorInfo(TensorShape(5U, 128U), 1, DataType::F32), // Wrong number of box fields
83 TensorInfo(TensorShape(4U, 128U), 1, DataType::F16), // Wrong data type
84 TensorInfo(TensorShape(4U, 128U), 1, DataType::F32), // Wrong number of classes
85 TensorInfo(TensorShape(4U, 128U), 1, DataType::F32), // Deltas and predicted boxes have different dimensions
86 TensorInfo(TensorShape(4U, 128U), 1, DataType::F32)}), // Scaling is zero
87 framework::dataset::make("PredBoxesInfo",{ TensorInfo(TensorShape(128U, 128U), 1, DataType::F32),
88 TensorInfo(TensorShape(128U, 128U), 1, DataType::F32),
89 TensorInfo(TensorShape(127U, 128U), 1, DataType::F32),
90 TensorInfo(TensorShape(128U, 100U), 1, DataType::F32),
91 TensorInfo(TensorShape(128U, 100U), 1, DataType::F32),
92 TensorInfo(TensorShape(128U, 128U), 1, DataType::F32)})),
93 framework::dataset::make("DeltasInfo", { TensorInfo(TensorShape(128U, 128U), 1, DataType::F32),
94 TensorInfo(TensorShape(128U, 128U), 1, DataType::F32),
95 TensorInfo(TensorShape(127U, 128U), 1, DataType::F32),
96 TensorInfo(TensorShape(128U, 100U), 1, DataType::F32),
97 TensorInfo(TensorShape(128U, 128U), 1, DataType::F32),
98 TensorInfo(TensorShape(128U, 128U), 1, DataType::F32)})),
99 framework::dataset::make("BoundingBoxTransofmInfo", { BoundingBoxTransformInfo(800.f, 600.f, 1.f),
100 BoundingBoxTransformInfo(800.f, 600.f, 1.f),
101 BoundingBoxTransformInfo(800.f, 600.f, 1.f),
102 BoundingBoxTransformInfo(800.f, 600.f, 1.f),
103 BoundingBoxTransformInfo(800.f, 600.f, 0.f)})),
104 framework::dataset::make("Expected", { true, false, false, false, false, false})),
105 boxes_info, pred_boxes_info, deltas_info, bbox_info, expected)
106{
107 ARM_COMPUTE_EXPECT(bool(NEBoundingBoxTransform::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);
108}
109// clang-format on
110// *INDENT-ON*
111
112template <typename T>
113using NEBoundingBoxTransformFixture = BoundingBoxTransformFixture<Tensor, Accessor, NEBoundingBoxTransform, T>;
114
115TEST_SUITE(Float)
116TEST_SUITE(FP32)
117FIXTURE_DATA_TEST_CASE(BoundingBox, NEBoundingBoxTransformFixture<float>, framework::DatasetMode::ALL,
118 combine(combine(DeltaDataset, BboxInfoDataset), framework::dataset::make("DataType", { DataType::F32 })))
119{
120 // Validate output
121 validate(Accessor(_target), _reference, relative_tolerance_f32, 0.f, absolute_tolerance_f32);
122}
123TEST_SUITE_END() // FP32
124
125#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
126TEST_SUITE(FP16)
127FIXTURE_DATA_TEST_CASE(BoundingBox, NEBoundingBoxTransformFixture<half>, framework::DatasetMode::ALL,
128 combine(combine(DeltaDataset, BboxInfoDataset), framework::dataset::make("DataType", { DataType::F16 })))
129{
130 // Validate output
131 validate(Accessor(_target), _reference, relative_tolerance_f16, 0.03f, absolute_tolerance_f16);
132}
133TEST_SUITE_END() // FP16
134#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
135
136TEST_SUITE_END() // Float
137
138TEST_SUITE_END() // BBoxTransform
139TEST_SUITE_END() // NEON
140} // namespace validation
141} // namespace test
142} // namespace arm_compute