blob: d8e6e542460d4850fd51fd4a3e2a30d8fc8d6b7e [file] [log] [blame]
Giorgio Arena73023022018-09-04 14:55:55 +01001/*
2 * Copyright (c) 2018 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
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46/** Define tolerance of the yolo layer.
47 *
48 * @param[in] activation The activation function used.
49 * @param[in] data_type Data type.
50 *
51 * @return Tolerance depending on the activation function.
52 */
53AbsoluteTolerance<float> tolerance(ActivationLayerInfo::ActivationFunction activation, DataType data_type)
54{
55 constexpr float epsilon = 1e-6f;
56
57 switch(activation)
58 {
59 case ActivationLayerInfo::ActivationFunction::LINEAR:
60 return AbsoluteTolerance<float>(data_type == DataType::F16 ? 0.2f : epsilon);
61 case ActivationLayerInfo::ActivationFunction::SQUARE:
62 return AbsoluteTolerance<float>(data_type == DataType::F16 ? 0.1f : epsilon);
63 case ActivationLayerInfo::ActivationFunction::LOGISTIC:
64 return AbsoluteTolerance<float>(data_type == DataType::F16 ? 0.001f : epsilon);
65 case ActivationLayerInfo::ActivationFunction::LEAKY_RELU:
66 return AbsoluteTolerance<float>(data_type == DataType::F16 ? 0.00001f : epsilon);
67 case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
68 case ActivationLayerInfo::ActivationFunction::SQRT:
69 return AbsoluteTolerance<float>(data_type == DataType::F16 ? 0.01f : 0.00001f);
70 case ActivationLayerInfo::ActivationFunction::TANH:
71 return AbsoluteTolerance<float>(data_type == DataType::F16 ? 0.001f : 0.00001f);
72 default:
73 return AbsoluteTolerance<float>(epsilon);
74 }
75}
76
77/** Floating point data sets. */
78const auto YOLODataset = combine(combine(combine(combine(framework::dataset::make("InPlace", { false, true }), datasets::ActivationFunctions()),
79 framework::dataset::make("AlphaBeta", { 0.5f, 1.f })),
80 framework::dataset::make("Classes", 40)),
81 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }));
82} // namespace
83
84TEST_SUITE(CL)
85TEST_SUITE(YOLOLayer)
86
87template <typename T>
88using CLYOLOLayerFixture = YOLOValidationFixture<CLTensor, CLAccessor, CLYOLOLayer, T>;
89
90TEST_SUITE(Float)
91TEST_SUITE(FP32)
92FIXTURE_DATA_TEST_CASE(RunSmall, CLYOLOLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallYOLOShapes(), YOLODataset), framework::dataset::make("DataType",
93 DataType::F32)))
94{
95 // Validate output
96 validate(CLAccessor(_target), _reference, tolerance(_function, _data_type));
97}
98
99FIXTURE_DATA_TEST_CASE(RunLarge, CLYOLOLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeYOLOShapes(), YOLODataset), framework::dataset::make("DataType",
100 DataType::F32)))
101{
102 // Validate output
103 validate(CLAccessor(_target), _reference, tolerance(_function, _data_type));
104}
105TEST_SUITE_END() // FP32
106
107TEST_SUITE(FP16)
108FIXTURE_DATA_TEST_CASE(RunSmall, CLYOLOLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallYOLOShapes(), YOLODataset), framework::dataset::make("DataType",
109 DataType::F16)))
110{
111 // Validate output
112 validate(CLAccessor(_target), _reference, tolerance(_function, _data_type));
113}
114FIXTURE_DATA_TEST_CASE(RunLarge, CLYOLOLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeYOLOShapes(), YOLODataset), framework::dataset::make("DataType",
115 DataType::F16)))
116{
117 // Validate output
118 validate(CLAccessor(_target), _reference, tolerance(_function, _data_type));
119}
120TEST_SUITE_END() // FP16
121TEST_SUITE_END() // Float
122
123TEST_SUITE_END() // YOLOLayer
124TEST_SUITE_END() // CL
125} // namespace validation
126} // namespace test
127} // namespace arm_compute