blob: f1fae3d5ccff9f8c958c396b470734fa5982eeb4 [file] [log] [blame]
George Wort894066d2019-02-15 15:12:52 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 Arm Limited.
George Wort894066d2019-02-15 15:12:52 +00003 *
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/CLCropResize.h"
George Wort894066d2019-02-15 15:12:52 +000028#include "tests/CL/CLAccessor.h"
29#include "tests/datasets/CropResizeDataset.h"
30#include "tests/framework/Asserts.h"
31#include "tests/framework/Macros.h"
32#include "tests/framework/datasets/Datasets.h"
33#include "tests/validation/Validation.h"
34#include "tests/validation/fixtures/CropResizeFixture.h"
35
36namespace arm_compute
37{
38namespace test
39{
40namespace validation
41{
42TEST_SUITE(CL)
43TEST_SUITE(CropResize)
44
45RelativeTolerance<float> tolerance_fp32(0.001f);
46
47template <typename T>
48using CLCropResizeFixture = CropResizeFixture<CLTensor, CLAccessor, CLCropResize, T>;
49
50// *INDENT-OFF*
51// clang-format off
52DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
53 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(15U, 30U, 40U, 10U), 1, DataType::S32),
George Wort894066d2019-02-15 15:12:52 +000054 TensorInfo(TensorShape(15U, 30U, 40U, 10U), 1, DataType::S32), // Invalid box_ind shape.
55 TensorInfo(TensorShape(15U, 30U, 40U, 10U), 1, DataType::S32), // Invalid output shape.
56 TensorInfo(TensorShape(15U, 30U, 40U, 10U), 1, DataType::S32), // Invalid output data type.
57 TensorInfo(TensorShape(15U, 30U, 40U, 10U), 1, DataType::S32), // Invalid output shape.
58 TensorInfo(TensorShape(15U, 30U, 40U, 10U), 1, DataType::S32), // Invalid boxes shape.
59 }),
60 framework::dataset::make("BoxesInfo",{ TensorInfo(TensorShape(4, 20), 1, DataType::F32),
61 TensorInfo(TensorShape(4, 20), 1, DataType::F32),
62 TensorInfo(TensorShape(4, 20), 1, DataType::F32),
63 TensorInfo(TensorShape(4, 20), 1, DataType::F32),
64 TensorInfo(TensorShape(4, 20), 1, DataType::F32),
George Wort894066d2019-02-15 15:12:52 +000065 TensorInfo(TensorShape(3, 20), 1, DataType::F32),
66 })),
67 framework::dataset::make("BoxIndInfo",{ TensorInfo(TensorShape(20), 1, DataType::S32),
George Wort894066d2019-02-15 15:12:52 +000068 TensorInfo(TensorShape(10), 1, DataType::S32),
69 TensorInfo(TensorShape(20), 1, DataType::S32),
70 TensorInfo(TensorShape(20), 1, DataType::S32),
71 TensorInfo(TensorShape(20), 1, DataType::S32),
72 TensorInfo(TensorShape(20), 1, DataType::S32),
73 })),
74 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(15U, 5, 5, 20U), 1, DataType::F32),
75 TensorInfo(TensorShape(15U, 5, 5, 20U), 1, DataType::F32),
George Wort894066d2019-02-15 15:12:52 +000076 TensorInfo(TensorShape(15U, 5, 5, 10U), 1, DataType::F32),
77 TensorInfo(TensorShape(15U, 5, 5, 20U), 1, DataType::S32),
78 TensorInfo(TensorShape(5U, 5, 5, 20U), 1, DataType::F32),
79 TensorInfo(TensorShape(15U, 5, 5, 20U), 1, DataType::F32),
80 })),
Michele Di Giorgio7d6b5772020-06-01 13:39:52 +010081 framework::dataset::make("Expected", { true, false, false, false, false, false})),
George Wort894066d2019-02-15 15:12:52 +000082 input, boxes, box_ind, output, expected)
83{
84 ARM_COMPUTE_EXPECT(bool(CLCropResize::validate(&input.clone()->set_data_layout(DataLayout::NHWC).set_is_resizable(false),
85 &boxes.clone()->set_is_resizable(false),
86 &box_ind.clone()->set_is_resizable(false),
87 &output.clone()->set_data_layout(DataLayout::NHWC).set_is_resizable(false),
88 Coordinates2D{ 5, 5 }, InterpolationPolicy::BILINEAR, 100)) == expected, framework::LogLevel::ERRORS);
89}
90// clang-format on
91// *INDENT-ON*
92
93TEST_SUITE(Float)
94#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
95TEST_SUITE(F16)
96FIXTURE_DATA_TEST_CASE(RunSmall,
97 CLCropResizeFixture<half>,
98 framework::DatasetMode::PRECOMMIT,
99 combine(datasets::SmallCropResizeDataset(),
100 combine(framework::dataset::make("IsOutOfBounds", { true, false }),
101 framework::dataset::make("DataType", DataType::F16))))
102{
103 // Validate output
104 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
105}
106TEST_SUITE_END() // F16
107#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
108
109TEST_SUITE(F32)
110FIXTURE_DATA_TEST_CASE(RunSmall,
111 CLCropResizeFixture<float>,
112 framework::DatasetMode::PRECOMMIT,
113 combine(datasets::SmallCropResizeDataset(),
114 combine(framework::dataset::make("IsOutOfBounds", { true, false }),
115 framework::dataset::make("DataType", DataType::F32))))
116{
117 // Validate output
118 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
119}
120TEST_SUITE_END() // F32
121TEST_SUITE_END() // Float
122
Michele Di Giorgio7d6b5772020-06-01 13:39:52 +0100123TEST_SUITE(U8)
124FIXTURE_DATA_TEST_CASE(RunSmall,
125 CLCropResizeFixture<uint8_t>,
126 framework::DatasetMode::PRECOMMIT,
127 combine(datasets::SmallCropResizeDataset(),
128 combine(framework::dataset::make("IsOutOfBounds", { true, false }),
129 framework::dataset::make("DataType", DataType::U8))))
130{
131 // Validate output
132 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
133}
134TEST_SUITE_END() // U8
135
George Wort894066d2019-02-15 15:12:52 +0000136TEST_SUITE(U16)
137FIXTURE_DATA_TEST_CASE(RunSmall,
138 CLCropResizeFixture<uint16_t>,
139 framework::DatasetMode::PRECOMMIT,
140 combine(datasets::SmallCropResizeDataset(),
141 combine(framework::dataset::make("IsOutOfBounds", { true, false }),
142 framework::dataset::make("DataType", DataType::U16))))
143{
144 // Validate output
145 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
146}
147TEST_SUITE_END() // U16
148
149TEST_SUITE(S16)
150FIXTURE_DATA_TEST_CASE(RunSmall,
151 CLCropResizeFixture<int16_t>,
152 framework::DatasetMode::PRECOMMIT,
153 combine(datasets::SmallCropResizeDataset(),
154 combine(framework::dataset::make("IsOutOfBounds", { true, false }),
155 framework::dataset::make("DataType", DataType::S16))))
156{
157 // Validate output
158 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
159}
160TEST_SUITE_END() // S16
161
162TEST_SUITE(U32)
163FIXTURE_DATA_TEST_CASE(RunSmall,
164 CLCropResizeFixture<uint32_t>,
165 framework::DatasetMode::PRECOMMIT,
166 combine(datasets::SmallCropResizeDataset(),
167 combine(framework::dataset::make("IsOutOfBounds", { true, false }),
168 framework::dataset::make("DataType", DataType::U32))))
169{
170 // Validate output
171 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
172}
173TEST_SUITE_END() // U32
174
175TEST_SUITE(S32)
176FIXTURE_DATA_TEST_CASE(RunSmall,
177 CLCropResizeFixture<int32_t>,
178 framework::DatasetMode::PRECOMMIT,
179 combine(datasets::SmallCropResizeDataset(),
180 combine(framework::dataset::make("IsOutOfBounds", { true, false }),
181 framework::dataset::make("DataType", DataType::S32))))
182{
183 // Validate output
184 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
185}
186TEST_SUITE_END() // S32
187
188TEST_SUITE_END() // CropResize
189TEST_SUITE_END() // CL
190} // namespace validation
191} // namespace test
192} // namespace arm_compute