blob: 0edbc4e11f909905de31d21450327abfc23011a6 [file] [log] [blame]
Michalis Spyroua6825a42018-09-13 12:24:03 +01001/*
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +00002 * Copyright (c) 2018-2019 ARM Limited.
Michalis Spyroua6825a42018-09-13 12:24:03 +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/NEON/functions/NEYOLOLayer.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
28#include "tests/NEON/Accessor.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/** Tolerance */
47constexpr AbsoluteTolerance<float> tolerance_f32(1e-6f);
48#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Michele Di Giorgio1c948d42018-11-20 16:03:01 +000049constexpr RelativeTolerance<float> tolerance_f16(0.01f);
Michalis Spyroua6825a42018-09-13 12:24:03 +010050#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
51
52/** Floating point data sets. */
53const auto YOLODataset = combine(combine(combine(combine(framework::dataset::make("InPlace", { false, true }), framework::dataset::make("ActivationFunction",
54 ActivationLayerInfo::ActivationFunction::LOGISTIC)),
55 framework::dataset::make("AlphaBeta", { 0.5f, 1.f })),
56 framework::dataset::make("Classes", 40)),
57 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }));
58} // namespace
59
60TEST_SUITE(NEON)
61TEST_SUITE(YOLOLayer)
62
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000063// *INDENT-OFF*
64// clang-format off
65DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
66 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::U8), // Wrong input data type
67 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32), // Invalid activation info
68 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32), // Wrong output data type
69 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32), // wrong number of classes
70 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32), // Mismatching shapes
71 TensorInfo(TensorShape(17U, 16U, 6U), 1, DataType::F32), // shrink window
72 TensorInfo(TensorShape(17U, 16U, 7U), 1, DataType::F32), // channels not multiple of (num_classes + 5)
73 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32), // Valid
74 }),
75 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32),
76 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32),
77 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::U16),
78 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32),
79 TensorInfo(TensorShape(16U, 11U, 6U), 1, DataType::F32),
80 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32),
81 TensorInfo(TensorShape(16U, 16U, 7U), 1, DataType::F32),
82 TensorInfo(TensorShape(16U, 16U, 6U), 1, DataType::F32),
83 })),
84 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC),
85 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
86 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC),
87 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC),
88 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC),
89 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC),
90 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC),
91 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC),
92 })),
93 framework::dataset::make("Numclasses", { 1, 1, 1, 0, 1, 1, 1, 1
94 })),
95 framework::dataset::make("Expected", { false, false, false, false, false, false, false, true})),
96 input_info, output_info, act_info, num_classes, expected)
97{
98 ARM_COMPUTE_EXPECT(bool(NEYOLOLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), act_info, num_classes)) == expected, framework::LogLevel::ERRORS);
99}
100// clang-format on
101// *INDENT-ON*
102
Michalis Spyroua6825a42018-09-13 12:24:03 +0100103template <typename T>
104using NEYOLOLayerFixture = YOLOValidationFixture<Tensor, Accessor, NEYOLOLayer, T>;
105
106TEST_SUITE(Float)
107TEST_SUITE(FP32)
108FIXTURE_DATA_TEST_CASE(RunSmall, NEYOLOLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallYOLOShapes(), YOLODataset), framework::dataset::make("DataType",
109 DataType::F32)))
110{
111 // Validate output
112 validate(Accessor(_target), _reference, tolerance_f32);
113}
114
115FIXTURE_DATA_TEST_CASE(RunLarge, NEYOLOLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeYOLOShapes(), YOLODataset), framework::dataset::make("DataType",
116 DataType::F32)))
117{
118 // Validate output
119 validate(Accessor(_target), _reference, tolerance_f32);
120}
121TEST_SUITE_END() // FP32
122
123#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
124TEST_SUITE(FP16)
125FIXTURE_DATA_TEST_CASE(RunSmall, NEYOLOLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallYOLOShapes(), YOLODataset), framework::dataset::make("DataType",
126 DataType::F16)))
127{
128 // Validate output
129 validate(Accessor(_target), _reference, tolerance_f16);
130}
131FIXTURE_DATA_TEST_CASE(RunLarge, NEYOLOLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeYOLOShapes(), YOLODataset), framework::dataset::make("DataType",
132 DataType::F16)))
133{
134 // Validate output
135 validate(Accessor(_target), _reference, tolerance_f16);
136}
137TEST_SUITE_END() // FP16
138#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
139TEST_SUITE_END() // Float
140
141TEST_SUITE_END() // YOLOLayer
142TEST_SUITE_END() // NEON
143} // namespace validation
144} // namespace test
145} // namespace arm_compute