blob: 9dc86c5d3993089604e7db8ab90d5a7480187088 [file] [log] [blame]
Pablo Tellof5f34bb2017-08-22 13:34:13 +01001/*
Georgios Pinitasced7a8d2018-02-01 16:31:33 +00002 * Copyright (c) 2017-2018 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 */
47
Georgios Pinitasced7a8d2018-02-01 16:31:33 +000048const auto data4x4 = datasets::SmallDeconvolutionShapes() * framework::dataset::make("StrideX", 1, 4) * framework::dataset::make("StrideY", 1, 4) * framework::dataset::make("PadX", 0, 3)
49 * framework::dataset::make("PadY", 0, 3) * framework::dataset::make("ax", 0) * framework::dataset::make("ay", 0) * framework::dataset::make("NumKernels", { 1, 3 });
50
Michalis Spyrou780db4e2017-11-23 09:49:51 +000051const auto data3x3 = datasets::SmallDeconvolutionShapes() * framework::dataset::make("StrideX", 1, 4) * framework::dataset::make("StrideY", 1, 4) * framework::dataset::make("PadX", 0, 2)
52 * framework::dataset::make("PadY", 0, 2) * framework::dataset::make("ax", 0) * framework::dataset::make("ay", 0) * framework::dataset::make("NumKernels", { 1, 3 });
Pablo Tellof5f34bb2017-08-22 13:34:13 +010053
Michalis Spyrou064add62018-11-01 18:14:27 +000054const auto data3x3_precommit = datasets::SmallDeconvolutionShapes() * framework::dataset::make("StrideX", 1, 2) * framework::dataset::make("StrideY", 1, 2) * framework::dataset::make("PadX", 0, 2)
55 * framework::dataset::make("PadY", 0, 2) * framework::dataset::make("ax", 0) * framework::dataset::make("ay", 0) * framework::dataset::make("NumKernels", { 3 });
56
Michalis Spyrou780db4e2017-11-23 09:49:51 +000057const auto data1x1 = datasets::SmallDeconvolutionShapes() * framework::dataset::make("StrideX", 1, 4) * framework::dataset::make("StrideY", 1, 4) * framework::dataset::make("PadX", 0, 1)
58 * framework::dataset::make("PadY", 0, 1) * framework::dataset::make("ax", 0) * framework::dataset::make("ay", 0) * framework::dataset::make("NumKernels", { 1, 3 });
Pablo Tellof5f34bb2017-08-22 13:34:13 +010059
Michele Di Giorgioed5a4922018-09-13 16:22:01 +010060const auto data_layouts_dataset = framework::dataset::make("DataLayout", { DataLayout::NCHW });
Pablo Tellof5f34bb2017-08-22 13:34:13 +010061} // namespace
62
63TEST_SUITE(NEON)
64TEST_SUITE(DeconvolutionLayer)
65
Alex Gilday27c08ab2018-02-22 11:36:16 +000066DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, (combine(datasets::SmallDeconvolutionShapes(), framework::dataset::make("DataType", DataType::F32))),
67 input_shape, data_type)
68{
69 // Create shapes
70 const unsigned int kernel_size_x = 3;
71 const unsigned int kernel_size_y = 3;
72 const unsigned int num_kernels = 1;
73 const TensorShape weights_shape(kernel_size_x, kernel_size_y, input_shape.z(), num_kernels);
74 const TensorShape bias_shape(num_kernels);
Michalis Spyrouafbc5ff2018-10-03 14:18:19 +010075 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 +010076 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 +000077
78 // Create tensors
79 Tensor src = create_tensor<Tensor>(input_shape, data_type, 1);
80 Tensor weights = create_tensor<Tensor>(weights_shape, data_type, 1);
81 Tensor bias = create_tensor<Tensor>(bias_shape, data_type, 1);
82 Tensor dst = create_tensor<Tensor>(output_shape, data_type, 1);
83
84 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
85 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
86 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
87 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
88
89 // Create and configure function
90 NEDeconvolutionLayer deconv;
91 deconv.configure(&src, &weights, &bias, &dst, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), 0, 0);
92
93 // Validate valid region
94 const ValidRegion src_valid_region = shape_to_valid_region(input_shape);
95 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
96 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
97 const ValidRegion dst_valid_region = shape_to_valid_region(output_shape);
98
99 validate(src.info()->valid_region(), src_valid_region);
100 validate(weights.info()->valid_region(), weights_valid_region);
101 validate(bias.info()->valid_region(), bias_valid_region);
102 validate(dst.info()->valid_region(), dst_valid_region);
103}
104
105// *INDENT-OFF*
106// clang-format off
107DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(zip(
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100108 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data type
109 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid weights shape
110 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16), // Non supported data type
111 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid bias shape
112 TensorInfo(TensorShape(13U, 11U, 4U, 3U), 1, DataType::F32), // Window shrink
113 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32),
Alex Gilday27c08ab2018-02-22 11:36:16 +0000114 }),
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100115 framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::F16),
116 TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32),
117 TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::F16),
118 TensorInfo(TensorShape(3U, 2U, 2U, 2U), 1, DataType::F32),
119 TensorInfo(TensorShape(3U, 3U, 4U), 1, DataType::F32),
120 TensorInfo(TensorShape(1U, 1U, 2U, 4U), 1, DataType::F32),
Alex Gilday27c08ab2018-02-22 11:36:16 +0000121 })),
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100122 framework::dataset::make("BiasInfo", { TensorInfo(TensorShape(1U), 1, DataType::F16),
123 TensorInfo(TensorShape(1U), 1, DataType::F32),
124 TensorInfo(TensorShape(1U), 1, DataType::F32),
125 TensorInfo(TensorShape(25U, 11U), 1, DataType::F32),
126 TensorInfo(TensorShape(1U), 1, DataType::F32),
127 TensorInfo(TensorShape(4U), 1, DataType::F32),
Alex Gilday27c08ab2018-02-22 11:36:16 +0000128 })),
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100129 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16),
130 TensorInfo(TensorShape(25U, 10U, 2U), 1, DataType::F32),
131 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32),
132 TensorInfo(TensorShape(13U, 13U, 2U), 1, DataType::F32),
133 TensorInfo(TensorShape(11U, 9U, 1U, 3U), 1, DataType::F32),
134 TensorInfo(TensorShape(32U, 16U, 4U), 1, DataType::F32),
Alex Gilday27c08ab2018-02-22 11:36:16 +0000135 })),
136 framework::dataset::make("PadStrideInfo", { PadStrideInfo(1, 1, 0, 0),
137 PadStrideInfo(1, 1, 0, 0),
138 PadStrideInfo(1, 1, 0, 0),
139 PadStrideInfo(1, 1, 0, 0),
140 PadStrideInfo(1, 1, 1, 1),
141 PadStrideInfo(1, 1, 0, 0),
142 })),
143 framework::dataset::make("ax", { 1U,
144 1U,
145 1U,
146 1U,
147 0U,
148 0U,
149 })),
150 framework::dataset::make("ay", { 1U,
151 1U,
152 1U,
153 1U,
154 0U,
155 0U,
156 })),
157 framework::dataset::make("Expected", { false, false, false, false, false, true })),
158 input_info, weights_info, bias_info, output_info, pad_info, ax, ay, expected)
159{
160 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));
161 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
162}
163// clang-format on
164// *INDENT-ON*
165
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100166template <typename T>
Georgios Pinitasced7a8d2018-02-01 16:31:33 +0000167using NEDeconvolutionLayerFixture4x4 = DeconvolutionValidationFixture<Tensor, Accessor, NEDeconvolutionLayer, T, 4, 4>;
168
169template <typename T>
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100170using NEDeconvolutionLayerFixture3x3 = DeconvolutionValidationFixture<Tensor, Accessor, NEDeconvolutionLayer, T, 3, 3>;
171
172template <typename T>
173using NEDeconvolutionLayerFixture1x1 = DeconvolutionValidationFixture<Tensor, Accessor, NEDeconvolutionLayer, T, 1, 1>;
174
175TEST_SUITE(Float)
176
177TEST_SUITE(FP32)
Georgios Pinitasced7a8d2018-02-01 16:31:33 +0000178TEST_SUITE(W4x4)
179
Michalis Spyrou064add62018-11-01 18:14:27 +0000180FIXTURE_DATA_TEST_CASE(Run, NEDeconvolutionLayerFixture4x4<float>, framework::DatasetMode::NIGHTLY, combine(combine(data4x4, framework::dataset::make("DataType", DataType::F32)),
181 data_layouts_dataset))
Georgios Pinitasced7a8d2018-02-01 16:31:33 +0000182{
183 // Validate output
184 validate(Accessor(_target), _reference, tolerance_fp32);
185}
Michalis Spyrou064add62018-11-01 18:14:27 +0000186TEST_SUITE_END() // W4x4
Georgios Pinitasced7a8d2018-02-01 16:31:33 +0000187
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100188TEST_SUITE(W3x3)
189
Michalis Spyrou064add62018-11-01 18:14:27 +0000190FIXTURE_DATA_TEST_CASE(RunSmall, NEDeconvolutionLayerFixture3x3<float>, framework::DatasetMode::PRECOMMIT, combine(combine(data3x3_precommit, framework::dataset::make("DataType", DataType::F32)),
191 data_layouts_dataset))
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100192{
193 // Validate output
194 validate(Accessor(_target), _reference, tolerance_fp32);
195}
Michalis Spyrou064add62018-11-01 18:14:27 +0000196FIXTURE_DATA_TEST_CASE(RunLarge, NEDeconvolutionLayerFixture3x3<float>, framework::DatasetMode::NIGHTLY, combine(combine(data3x3, framework::dataset::make("DataType", DataType::F32)),
197 data_layouts_dataset))
198{
199 // Validate output
200 validate(Accessor(_target), _reference, tolerance_fp32);
201}
202TEST_SUITE_END() // W3x3
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100203
204TEST_SUITE(W1x1)
Michalis Spyrou064add62018-11-01 18:14:27 +0000205FIXTURE_DATA_TEST_CASE(Run, NEDeconvolutionLayerFixture1x1<float>, framework::DatasetMode::NIGHTLY, combine(combine(data1x1, framework::dataset::make("DataType", DataType::F32)),
206 data_layouts_dataset))
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100207{
208 // Validate output
209 validate(Accessor(_target), _reference, tolerance_fp32);
210}
Michalis Spyrou064add62018-11-01 18:14:27 +0000211TEST_SUITE_END() // W1x1
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100212
Michalis Spyrou064add62018-11-01 18:14:27 +0000213TEST_SUITE_END() // FP32
214TEST_SUITE_END() // Float
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100215
Michalis Spyrou064add62018-11-01 18:14:27 +0000216TEST_SUITE_END() // DeconvolutionLayer
217TEST_SUITE_END() // NEON
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100218} // namespace validation
219} // namespace test
220} // namespace arm_compute