blob: f28082b74bcb06b994729bf7cff225d7d4067170 [file] [log] [blame]
Giorgio Arena73023022018-09-04 14:55:55 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2019 Arm Limited.
Giorgio Arena73023022018-09-04 14:55:55 +01003 *
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{
Michalis Spyrou80943252019-01-10 17:19:50 +000046constexpr AbsoluteTolerance<float> tolerance_f32(1e-6f);
47constexpr RelativeTolerance<float> tolerance_f16(0.01f);
Giorgio Arena73023022018-09-04 14:55:55 +010048
49/** Floating point data sets. */
Michalis Spyrou80943252019-01-10 17:19:50 +000050const auto YOLODataset = combine(combine(combine(combine(framework::dataset::make("InPlace", { false, true }), framework::dataset::make("ActivationFunction",
51 ActivationLayerInfo::ActivationFunction::LOGISTIC)),
Giorgio Arena73023022018-09-04 14:55:55 +010052 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
57TEST_SUITE(CL)
58TEST_SUITE(YOLOLayer)
59
Michalis Spyrou80943252019-01-10 17:19:50 +000060// *INDENT-OFF*
61// clang-format off
62DATA_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
Giorgio Arena73023022018-09-04 14:55:55 +0100100template <typename T>
101using CLYOLOLayerFixture = YOLOValidationFixture<CLTensor, CLAccessor, CLYOLOLayer, T>;
102
103TEST_SUITE(Float)
104TEST_SUITE(FP32)
105FIXTURE_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
Michalis Spyrou80943252019-01-10 17:19:50 +0000109 validate(CLAccessor(_target), _reference, tolerance_f32);
Giorgio Arena73023022018-09-04 14:55:55 +0100110}
111
112FIXTURE_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
Michalis Spyrou80943252019-01-10 17:19:50 +0000116 validate(CLAccessor(_target), _reference, tolerance_f32);
Giorgio Arena73023022018-09-04 14:55:55 +0100117}
118TEST_SUITE_END() // FP32
119
120TEST_SUITE(FP16)
121FIXTURE_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
Michalis Spyrou80943252019-01-10 17:19:50 +0000125 validate(CLAccessor(_target), _reference, tolerance_f16);
Giorgio Arena73023022018-09-04 14:55:55 +0100126}
127FIXTURE_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
Michalis Spyrou80943252019-01-10 17:19:50 +0000131 validate(CLAccessor(_target), _reference, tolerance_f16);
Giorgio Arena73023022018-09-04 14:55:55 +0100132}
133TEST_SUITE_END() // FP16
134TEST_SUITE_END() // Float
135
136TEST_SUITE_END() // YOLOLayer
137TEST_SUITE_END() // CL
138} // namespace validation
139} // namespace test
140} // namespace arm_compute