1 /*
2 * Copyright (c) 2018-2020 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/CL/CLTensor.h"
26 #include "arm_compute/runtime/CL/CLTensorAllocator.h"
27 #include "arm_compute/runtime/CL/functions/CLYOLOLayer.h"
28 #include "tests/CL/CLAccessor.h"
29 #include "tests/PaddingCalculator.h"
30 #include "tests/datasets/ActivationFunctionsDataset.h"
31 #include "tests/datasets/ShapeDatasets.h"
32 #include "tests/framework/Asserts.h"
33 #include "tests/framework/Macros.h"
34 #include "tests/framework/datasets/Datasets.h"
35 #include "tests/validation/Validation.h"
36 #include "tests/validation/fixtures/YOLOLayerFixture.h"
37
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 namespace
45 {
46 constexpr AbsoluteTolerance<float> tolerance_f32(1e-6f);
47 constexpr RelativeTolerance<float> tolerance_f16(0.01f);
48
49 /** Floating point data sets. */
50 const auto YOLODataset = combine(combine(combine(combine(framework::dataset::make("InPlace", { false, true }), framework::dataset::make("ActivationFunction",
51 ActivationLayerInfo::ActivationFunction::LOGISTIC)),
52 framework::dataset::make("AlphaBeta", { 0.5f, 1.f })),
53 framework::dataset::make("Classes", 40)),
54 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }));
55 } // namespace
56
57 TEST_SUITE(CL)
TEST_SUITE(YOLOLayer)58 TEST_SUITE(YOLOLayer)
59
60 // *INDENT-OFF*
61 // clang-format off
62 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
63 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::U8), // Wrong input data type
64 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32), // Invalid activation info
65 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32), // Wrong output data type
66 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32), // wrong number of classes
67 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32), // Mismatching shapes
68 TensorInfo(TensorShape(17U, 16U, 6U), 1, DataType::F32), // Shrink window
69 TensorInfo(TensorShape(17U, 16U, 7U), 1, DataType::F32), // Channels not multiple of (num_classes + 5)
70 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32), // Valid
71 }),
72 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32),
73 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32),
74 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::U16),
75 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32),
76 TensorInfo(TensorShape(16U, 11U, 6U), 1, DataType::F32),
77 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32),
78 TensorInfo(TensorShape(16U, 16U, 7U), 1, DataType::F32),
79 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32),
80 })),
81 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC),
82 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
83 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC),
84 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC),
85 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC),
86 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC),
87 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC),
88 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC),
89 })),
90 framework::dataset::make("Numclasses", { 1, 1, 1, 0, 1, 1, 1, 1
91 })),
92 framework::dataset::make("Expected", { false, false, false, false, false, false, false, true})),
93 input_info, output_info, act_info, num_classes, expected)
94 {
95 ARM_COMPUTE_EXPECT(bool(CLYOLOLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), act_info, num_classes)) == expected, framework::LogLevel::ERRORS);
96 }
97 // clang-format on
98 // *INDENT-ON*
99
100 template <typename T>
101 using CLYOLOLayerFixture = YOLOValidationFixture<CLTensor, CLAccessor, CLYOLOLayer, T>;
102
103 TEST_SUITE(Float)
TEST_SUITE(FP32)104 TEST_SUITE(FP32)
105 FIXTURE_DATA_TEST_CASE(RunSmall, CLYOLOLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallYOLOShapes(), YOLODataset), framework::dataset::make("DataType",
106 DataType::F32)))
107 {
108 // Validate output
109 validate(CLAccessor(_target), _reference, tolerance_f32);
110 }
111
112 FIXTURE_DATA_TEST_CASE(RunLarge, CLYOLOLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeYOLOShapes(), YOLODataset), framework::dataset::make("DataType",
113 DataType::F32)))
114 {
115 // Validate output
116 validate(CLAccessor(_target), _reference, tolerance_f32);
117 }
118 TEST_SUITE_END() // FP32
119
TEST_SUITE(FP16)120 TEST_SUITE(FP16)
121 FIXTURE_DATA_TEST_CASE(RunSmall, CLYOLOLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallYOLOShapes(), YOLODataset), framework::dataset::make("DataType",
122 DataType::F16)))
123 {
124 // Validate output
125 validate(CLAccessor(_target), _reference, tolerance_f16);
126 }
127 FIXTURE_DATA_TEST_CASE(RunLarge, CLYOLOLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeYOLOShapes(), YOLODataset), framework::dataset::make("DataType",
128 DataType::F16)))
129 {
130 // Validate output
131 validate(CLAccessor(_target), _reference, tolerance_f16);
132 }
133 TEST_SUITE_END() // FP16
134 TEST_SUITE_END() // Float
135
136 TEST_SUITE_END() // YOLOLayer
137 TEST_SUITE_END() // CL
138 } // namespace validation
139 } // namespace test
140 } // namespace arm_compute
141