blob: fc37c02279c39e0b5e6cda412f503b55c775d72f [file] [log] [blame]
Pablo Tellof5f34bb2017-08-22 13:34:13 +01001/*
Michalis Spyrou5ce99a22019-01-25 14:17:49 +00002 * Copyright (c) 2017-2019 ARM Limited.
Pablo Tellof5f34bb2017-08-22 13:34:13 +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"
Michele Di Giorgioed5a4922018-09-13 16:22:01 +010025#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Pablo Tellof5f34bb2017-08-22 13:34:13 +010026#include "arm_compute/runtime/NEON/functions/NEDeconvolutionLayer.h"
27#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
29#include "tests/NEON/Accessor.h"
30#include "tests/PaddingCalculator.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/DeconvolutionLayerFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46constexpr AbsoluteTolerance<float> tolerance_fp32(0.001f); /**< Tolerance for floating point tests */
Usama Arif2899e002019-04-16 14:32:25 +010047constexpr AbsoluteTolerance<float> tolerance_qasymm8(0.0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
48constexpr float tolerance_num = 0.07f; /**< Tolerance number */
Pablo Tellof5f34bb2017-08-22 13:34:13 +010049
Georgios Pinitasced7a8d2018-02-01 16:31:33 +000050const auto data4x4 = datasets::SmallDeconvolutionShapes() * framework::dataset::make("StrideX", 1, 4) * framework::dataset::make("StrideY", 1, 4) * framework::dataset::make("PadX", 0, 3)
giuros01a69a88b2019-01-31 16:29:19 +000051 * framework::dataset::make("PadY", 0, 3) * framework::dataset::make("NumKernels", { 3 });
Georgios Pinitasced7a8d2018-02-01 16:31:33 +000052
Michalis Spyrou780db4e2017-11-23 09:49:51 +000053const auto data3x3 = datasets::SmallDeconvolutionShapes() * framework::dataset::make("StrideX", 1, 4) * framework::dataset::make("StrideY", 1, 4) * framework::dataset::make("PadX", 0, 2)
giuros01a69a88b2019-01-31 16:29:19 +000054 * framework::dataset::make("PadY", 0, 2) * framework::dataset::make("NumKernels", { 3 });
Pablo Tellof5f34bb2017-08-22 13:34:13 +010055
Michalis Spyrou064add62018-11-01 18:14:27 +000056const auto data3x3_precommit = datasets::SmallDeconvolutionShapes() * framework::dataset::make("StrideX", 1, 2) * framework::dataset::make("StrideY", 1, 2) * framework::dataset::make("PadX", 0, 2)
giuros01a69a88b2019-01-31 16:29:19 +000057 * framework::dataset::make("PadY", 0, 2) * framework::dataset::make("NumKernels", { 3 });
Michalis Spyrou064add62018-11-01 18:14:27 +000058
Michalis Spyrou780db4e2017-11-23 09:49:51 +000059const auto data1x1 = datasets::SmallDeconvolutionShapes() * framework::dataset::make("StrideX", 1, 4) * framework::dataset::make("StrideY", 1, 4) * framework::dataset::make("PadX", 0, 1)
giuros01a69a88b2019-01-31 16:29:19 +000060 * framework::dataset::make("PadY", 0, 1) * framework::dataset::make("NumKernels", { 3 });
Pablo Tellof5f34bb2017-08-22 13:34:13 +010061
Michele Di Giorgioed5a4922018-09-13 16:22:01 +010062const auto data_layouts_dataset = framework::dataset::make("DataLayout", { DataLayout::NCHW });
Pablo Tellof5f34bb2017-08-22 13:34:13 +010063} // namespace
64
65TEST_SUITE(NEON)
66TEST_SUITE(DeconvolutionLayer)
67
Alex Gilday27c08ab2018-02-22 11:36:16 +000068DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, (combine(datasets::SmallDeconvolutionShapes(), framework::dataset::make("DataType", DataType::F32))),
69 input_shape, data_type)
70{
71 // Create shapes
72 const unsigned int kernel_size_x = 3;
73 const unsigned int kernel_size_y = 3;
74 const unsigned int num_kernels = 1;
75 const TensorShape weights_shape(kernel_size_x, kernel_size_y, input_shape.z(), num_kernels);
76 const TensorShape bias_shape(num_kernels);
Michalis Spyrouafbc5ff2018-10-03 14:18:19 +010077 auto out_dim = deconvolution_output_dimensions(input_shape.x(), input_shape.y(), kernel_size_x, kernel_size_y, 1, 1, 1, 1);
Michele Di Giorgioed5a4922018-09-13 16:22:01 +010078 TensorShape output_shape = compute_deconvolution_output_shape(out_dim, TensorInfo(input_shape, 1, data_type), TensorInfo(weights_shape, 1, data_type));
Alex Gilday27c08ab2018-02-22 11:36:16 +000079
80 // Create tensors
81 Tensor src = create_tensor<Tensor>(input_shape, data_type, 1);
82 Tensor weights = create_tensor<Tensor>(weights_shape, data_type, 1);
83 Tensor bias = create_tensor<Tensor>(bias_shape, data_type, 1);
84 Tensor dst = create_tensor<Tensor>(output_shape, data_type, 1);
85
86 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
87 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
88 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
89 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
90
91 // Create and configure function
92 NEDeconvolutionLayer deconv;
93 deconv.configure(&src, &weights, &bias, &dst, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), 0, 0);
94
95 // Validate valid region
96 const ValidRegion src_valid_region = shape_to_valid_region(input_shape);
97 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
98 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
99 const ValidRegion dst_valid_region = shape_to_valid_region(output_shape);
100
101 validate(src.info()->valid_region(), src_valid_region);
102 validate(weights.info()->valid_region(), weights_valid_region);
103 validate(bias.info()->valid_region(), bias_valid_region);
104 validate(dst.info()->valid_region(), dst_valid_region);
105}
106
107// *INDENT-OFF*
108// clang-format off
109DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(zip(
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100110 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data type
111 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid weights shape
112 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16), // Non supported data type
113 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid bias shape
114 TensorInfo(TensorShape(13U, 11U, 4U, 3U), 1, DataType::F32), // Window shrink
115 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32),
Alex Gilday27c08ab2018-02-22 11:36:16 +0000116 }),
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100117 framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::F16),
118 TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32),
119 TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::F16),
120 TensorInfo(TensorShape(3U, 2U, 2U, 2U), 1, DataType::F32),
121 TensorInfo(TensorShape(3U, 3U, 4U), 1, DataType::F32),
122 TensorInfo(TensorShape(1U, 1U, 2U, 4U), 1, DataType::F32),
Alex Gilday27c08ab2018-02-22 11:36:16 +0000123 })),
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100124 framework::dataset::make("BiasInfo", { TensorInfo(TensorShape(1U), 1, DataType::F16),
125 TensorInfo(TensorShape(1U), 1, DataType::F32),
126 TensorInfo(TensorShape(1U), 1, DataType::F32),
127 TensorInfo(TensorShape(25U, 11U), 1, DataType::F32),
128 TensorInfo(TensorShape(1U), 1, DataType::F32),
129 TensorInfo(TensorShape(4U), 1, DataType::F32),
Alex Gilday27c08ab2018-02-22 11:36:16 +0000130 })),
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100131 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16),
132 TensorInfo(TensorShape(25U, 10U, 2U), 1, DataType::F32),
133 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32),
134 TensorInfo(TensorShape(13U, 13U, 2U), 1, DataType::F32),
135 TensorInfo(TensorShape(11U, 9U, 1U, 3U), 1, DataType::F32),
136 TensorInfo(TensorShape(32U, 16U, 4U), 1, DataType::F32),
Alex Gilday27c08ab2018-02-22 11:36:16 +0000137 })),
138 framework::dataset::make("PadStrideInfo", { PadStrideInfo(1, 1, 0, 0),
139 PadStrideInfo(1, 1, 0, 0),
140 PadStrideInfo(1, 1, 0, 0),
141 PadStrideInfo(1, 1, 0, 0),
142 PadStrideInfo(1, 1, 1, 1),
143 PadStrideInfo(1, 1, 0, 0),
144 })),
145 framework::dataset::make("ax", { 1U,
146 1U,
147 1U,
148 1U,
149 0U,
150 0U,
151 })),
152 framework::dataset::make("ay", { 1U,
153 1U,
154 1U,
155 1U,
156 0U,
157 0U,
158 })),
159 framework::dataset::make("Expected", { false, false, false, false, false, true })),
160 input_info, weights_info, bias_info, output_info, pad_info, ax, ay, expected)
161{
162 bool is_valid = bool(NEDeconvolutionLayer::validate(&input_info.clone()->set_is_resizable(false), &weights_info.clone()->set_is_resizable(false), &bias_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), pad_info, ax, ay));
163 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
164}
165// clang-format on
166// *INDENT-ON*
167
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100168template <typename T>
Georgios Pinitasced7a8d2018-02-01 16:31:33 +0000169using NEDeconvolutionLayerFixture4x4 = DeconvolutionValidationFixture<Tensor, Accessor, NEDeconvolutionLayer, T, 4, 4>;
170
171template <typename T>
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100172using NEDeconvolutionLayerFixture3x3 = DeconvolutionValidationFixture<Tensor, Accessor, NEDeconvolutionLayer, T, 3, 3>;
173
174template <typename T>
175using NEDeconvolutionLayerFixture1x1 = DeconvolutionValidationFixture<Tensor, Accessor, NEDeconvolutionLayer, T, 1, 1>;
176
177TEST_SUITE(Float)
178
179TEST_SUITE(FP32)
Georgios Pinitasced7a8d2018-02-01 16:31:33 +0000180TEST_SUITE(W4x4)
181
Michalis Spyrou064add62018-11-01 18:14:27 +0000182FIXTURE_DATA_TEST_CASE(Run, NEDeconvolutionLayerFixture4x4<float>, framework::DatasetMode::NIGHTLY, combine(combine(data4x4, framework::dataset::make("DataType", DataType::F32)),
183 data_layouts_dataset))
Georgios Pinitasced7a8d2018-02-01 16:31:33 +0000184{
185 // Validate output
186 validate(Accessor(_target), _reference, tolerance_fp32);
187}
Michalis Spyrou064add62018-11-01 18:14:27 +0000188TEST_SUITE_END() // W4x4
Georgios Pinitasced7a8d2018-02-01 16:31:33 +0000189
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100190TEST_SUITE(W3x3)
191
Michalis Spyrou064add62018-11-01 18:14:27 +0000192FIXTURE_DATA_TEST_CASE(RunSmall, NEDeconvolutionLayerFixture3x3<float>, framework::DatasetMode::PRECOMMIT, combine(combine(data3x3_precommit, framework::dataset::make("DataType", DataType::F32)),
193 data_layouts_dataset))
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100194{
195 // Validate output
196 validate(Accessor(_target), _reference, tolerance_fp32);
197}
Michalis Spyrou064add62018-11-01 18:14:27 +0000198FIXTURE_DATA_TEST_CASE(RunLarge, NEDeconvolutionLayerFixture3x3<float>, framework::DatasetMode::NIGHTLY, combine(combine(data3x3, framework::dataset::make("DataType", DataType::F32)),
199 data_layouts_dataset))
200{
201 // Validate output
202 validate(Accessor(_target), _reference, tolerance_fp32);
203}
204TEST_SUITE_END() // W3x3
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100205
206TEST_SUITE(W1x1)
Michalis Spyrou064add62018-11-01 18:14:27 +0000207FIXTURE_DATA_TEST_CASE(Run, NEDeconvolutionLayerFixture1x1<float>, framework::DatasetMode::NIGHTLY, combine(combine(data1x1, framework::dataset::make("DataType", DataType::F32)),
208 data_layouts_dataset))
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100209{
210 // Validate output
211 validate(Accessor(_target), _reference, tolerance_fp32);
212}
Michalis Spyrou064add62018-11-01 18:14:27 +0000213TEST_SUITE_END() // W1x1
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100214
Michalis Spyrou064add62018-11-01 18:14:27 +0000215TEST_SUITE_END() // FP32
216TEST_SUITE_END() // Float
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100217
Usama Arif2899e002019-04-16 14:32:25 +0100218template <typename T>
219using NEDeconvolutionLayerQuantizedFixture4x4 = DeconvolutionValidationQuantizedFixture<Tensor, Accessor, NEDeconvolutionLayer, T, 4, 4>;
220
221template <typename T>
222using NEDeconvolutionLayerQuantizedFixture3x3 = DeconvolutionValidationQuantizedFixture<Tensor, Accessor, NEDeconvolutionLayer, T, 3, 3>;
223
224template <typename T>
225using NEDeconvolutionLayerQuantizedFixture1x1 = DeconvolutionValidationQuantizedFixture<Tensor, Accessor, NEDeconvolutionLayer, T, 1, 1>;
226
227TEST_SUITE(Quantized)
228TEST_SUITE(QASYMM8)
229
230TEST_SUITE(W4x4)
231FIXTURE_DATA_TEST_CASE(Run, NEDeconvolutionLayerQuantizedFixture4x4<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(data4x4, framework::dataset::make("DataType",
232 DataType::QASYMM8)),
233 data_layouts_dataset),
234 framework::dataset::make("QuantizationInfo", QuantizationInfo(2.f / 255.f, 0))))
235{
236 // Validate output
237 validate(Accessor(_target), _reference, tolerance_qasymm8, tolerance_num);
238}
239TEST_SUITE_END() // W4x4
240
241TEST_SUITE(W3x3)
242FIXTURE_DATA_TEST_CASE(RunSmall, NEDeconvolutionLayerQuantizedFixture3x3<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(data3x3_precommit, framework::dataset::make("DataType",
243 DataType::QASYMM8)),
244 data_layouts_dataset),
245 framework::dataset::make("QuantizationInfo", QuantizationInfo(2.f / 255.f, 0))))
246{
247 // Validate output
248 validate(Accessor(_target), _reference, tolerance_qasymm8, tolerance_num);
249}
250FIXTURE_DATA_TEST_CASE(RunLarge, NEDeconvolutionLayerQuantizedFixture3x3<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(data3x3, framework::dataset::make("DataType",
251 DataType::QASYMM8)),
252 data_layouts_dataset),
253 framework::dataset::make("QuantizationInfo", QuantizationInfo(2.f / 255.f, 0))))
254{
255 // Validate output
256 validate(Accessor(_target), _reference, tolerance_qasymm8, tolerance_num);
257}
258TEST_SUITE_END() // W3x3
259
260TEST_SUITE(W1x1)
261FIXTURE_DATA_TEST_CASE(Run, NEDeconvolutionLayerQuantizedFixture1x1<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(data1x1, framework::dataset::make("DataType",
262 DataType::QASYMM8)),
263 data_layouts_dataset),
264 framework::dataset::make("QuantizationInfo", QuantizationInfo(2.f / 255.f, 0))))
265{
266 // Validate output
267 validate(Accessor(_target), _reference, tolerance_qasymm8, tolerance_num);
268}
269TEST_SUITE_END() // W1x1
270
271TEST_SUITE_END() // QASYMM8
272TEST_SUITE_END() // Quantized
273
Michalis Spyrou064add62018-11-01 18:14:27 +0000274TEST_SUITE_END() // DeconvolutionLayer
275TEST_SUITE_END() // NEON
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100276} // namespace validation
277} // namespace test
278} // namespace arm_compute