Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | ced7a8d | 2018-02-01 16:31:33 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 3 | * |
| 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/NEDeconvolutionLayer.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/ShapeDatasets.h" |
| 31 | #include "tests/framework/Asserts.h" |
| 32 | #include "tests/framework/Macros.h" |
| 33 | #include "tests/framework/datasets/Datasets.h" |
| 34 | #include "tests/validation/Validation.h" |
| 35 | #include "tests/validation/fixtures/DeconvolutionLayerFixture.h" |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | namespace |
| 44 | { |
| 45 | constexpr AbsoluteTolerance<float> tolerance_fp32(0.001f); /**< Tolerance for floating point tests */ |
| 46 | |
Georgios Pinitas | ced7a8d | 2018-02-01 16:31:33 +0000 | [diff] [blame] | 47 | const auto data4x4 = datasets::SmallDeconvolutionShapes() * framework::dataset::make("StrideX", 1, 4) * framework::dataset::make("StrideY", 1, 4) * framework::dataset::make("PadX", 0, 3) |
| 48 | * framework::dataset::make("PadY", 0, 3) * framework::dataset::make("ax", 0) * framework::dataset::make("ay", 0) * framework::dataset::make("NumKernels", { 1, 3 }); |
| 49 | |
Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [diff] [blame] | 50 | const auto data3x3 = datasets::SmallDeconvolutionShapes() * framework::dataset::make("StrideX", 1, 4) * framework::dataset::make("StrideY", 1, 4) * framework::dataset::make("PadX", 0, 2) |
| 51 | * framework::dataset::make("PadY", 0, 2) * framework::dataset::make("ax", 0) * framework::dataset::make("ay", 0) * framework::dataset::make("NumKernels", { 1, 3 }); |
Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 52 | |
Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [diff] [blame] | 53 | const auto data1x1 = datasets::SmallDeconvolutionShapes() * framework::dataset::make("StrideX", 1, 4) * framework::dataset::make("StrideY", 1, 4) * framework::dataset::make("PadX", 0, 1) |
| 54 | * framework::dataset::make("PadY", 0, 1) * framework::dataset::make("ax", 0) * framework::dataset::make("ay", 0) * framework::dataset::make("NumKernels", { 1, 3 }); |
Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 55 | |
| 56 | } // namespace |
| 57 | |
| 58 | TEST_SUITE(NEON) |
| 59 | TEST_SUITE(DeconvolutionLayer) |
| 60 | |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 61 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, (combine(datasets::SmallDeconvolutionShapes(), framework::dataset::make("DataType", DataType::F32))), |
| 62 | input_shape, data_type) |
| 63 | { |
| 64 | // Create shapes |
| 65 | const unsigned int kernel_size_x = 3; |
| 66 | const unsigned int kernel_size_y = 3; |
| 67 | const unsigned int num_kernels = 1; |
| 68 | const TensorShape weights_shape(kernel_size_x, kernel_size_y, input_shape.z(), num_kernels); |
| 69 | const TensorShape bias_shape(num_kernels); |
| 70 | auto out_dim = deconvolution_output_dimensions(input_shape.x(), input_shape.y(), kernel_size_x, kernel_size_y, 1, 1, 0, 0, 1, 1); |
| 71 | TensorShape output_shape = deconvolution_output_shape(out_dim, input_shape, weights_shape); |
| 72 | |
| 73 | // Create tensors |
| 74 | Tensor src = create_tensor<Tensor>(input_shape, data_type, 1); |
| 75 | Tensor weights = create_tensor<Tensor>(weights_shape, data_type, 1); |
| 76 | Tensor bias = create_tensor<Tensor>(bias_shape, data_type, 1); |
| 77 | Tensor dst = create_tensor<Tensor>(output_shape, data_type, 1); |
| 78 | |
| 79 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 80 | ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 81 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 82 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 83 | |
| 84 | // Create and configure function |
| 85 | NEDeconvolutionLayer deconv; |
| 86 | deconv.configure(&src, &weights, &bias, &dst, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), 0, 0); |
| 87 | |
| 88 | // Validate valid region |
| 89 | const ValidRegion src_valid_region = shape_to_valid_region(input_shape); |
| 90 | const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape); |
| 91 | const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape); |
| 92 | const ValidRegion dst_valid_region = shape_to_valid_region(output_shape); |
| 93 | |
| 94 | validate(src.info()->valid_region(), src_valid_region); |
| 95 | validate(weights.info()->valid_region(), weights_valid_region); |
| 96 | validate(bias.info()->valid_region(), bias_valid_region); |
| 97 | validate(dst.info()->valid_region(), dst_valid_region); |
| 98 | } |
| 99 | |
| 100 | // *INDENT-OFF* |
| 101 | // clang-format off |
| 102 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(zip( |
| 103 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Mismatching data type |
| 104 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid weights shape |
Vidhya Sudhan Loganathan | 0fc2545 | 2018-06-18 14:40:56 +0100 | [diff] [blame] | 105 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16, 4), // Non supported data type |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 106 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 11), // Invalid bias shape |
| 107 | TensorInfo(TensorShape(13U, 11U, 4U, 3U), 1, DataType::F32, 0), // Window shrink |
| 108 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32, 0), |
| 109 | }), |
| 110 | framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::F16, 0), |
| 111 | TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, 0), |
Vidhya Sudhan Loganathan | 0fc2545 | 2018-06-18 14:40:56 +0100 | [diff] [blame] | 112 | TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::F16, 5), |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 113 | TensorInfo(TensorShape(3U, 2U, 2U, 2U), 1, DataType::F32, 11), |
| 114 | TensorInfo(TensorShape(3U, 3U, 4U), 1, DataType::F32, 0), |
| 115 | TensorInfo(TensorShape(1U, 1U, 2U, 4U), 1, DataType::F32, 0), |
| 116 | })), |
| 117 | framework::dataset::make("BiasInfo", { TensorInfo(TensorShape(1U), 1, DataType::F16, 0), |
| 118 | TensorInfo(TensorShape(1U), 1, DataType::F32, 0), |
| 119 | TensorInfo(TensorShape(1U), 1, DataType::F32, 5), |
| 120 | TensorInfo(TensorShape(25U, 11U), 1, DataType::F32, 11), |
| 121 | TensorInfo(TensorShape(1U), 1, DataType::F32, 0), |
| 122 | TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
| 123 | })), |
| 124 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16, 0), |
| 125 | TensorInfo(TensorShape(25U, 10U, 2U), 1, DataType::F32, 0), |
| 126 | TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32, 5), |
| 127 | TensorInfo(TensorShape(13U, 13U, 2U), 1, DataType::F32, 0), |
| 128 | TensorInfo(TensorShape(11U, 9U, 1U, 3U), 1, DataType::F32, 0), |
| 129 | TensorInfo(TensorShape(32U, 16U, 4U), 1, DataType::F32, 0), |
| 130 | })), |
| 131 | framework::dataset::make("PadStrideInfo", { PadStrideInfo(1, 1, 0, 0), |
| 132 | PadStrideInfo(1, 1, 0, 0), |
| 133 | PadStrideInfo(1, 1, 0, 0), |
| 134 | PadStrideInfo(1, 1, 0, 0), |
| 135 | PadStrideInfo(1, 1, 1, 1), |
| 136 | PadStrideInfo(1, 1, 0, 0), |
| 137 | })), |
| 138 | framework::dataset::make("ax", { 1U, |
| 139 | 1U, |
| 140 | 1U, |
| 141 | 1U, |
| 142 | 0U, |
| 143 | 0U, |
| 144 | })), |
| 145 | framework::dataset::make("ay", { 1U, |
| 146 | 1U, |
| 147 | 1U, |
| 148 | 1U, |
| 149 | 0U, |
| 150 | 0U, |
| 151 | })), |
| 152 | framework::dataset::make("Expected", { false, false, false, false, false, true })), |
| 153 | input_info, weights_info, bias_info, output_info, pad_info, ax, ay, expected) |
| 154 | { |
| 155 | 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)); |
| 156 | ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS); |
| 157 | } |
| 158 | // clang-format on |
| 159 | // *INDENT-ON* |
| 160 | |
Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 161 | template <typename T> |
Georgios Pinitas | ced7a8d | 2018-02-01 16:31:33 +0000 | [diff] [blame] | 162 | using NEDeconvolutionLayerFixture4x4 = DeconvolutionValidationFixture<Tensor, Accessor, NEDeconvolutionLayer, T, 4, 4>; |
| 163 | |
| 164 | template <typename T> |
Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 165 | using NEDeconvolutionLayerFixture3x3 = DeconvolutionValidationFixture<Tensor, Accessor, NEDeconvolutionLayer, T, 3, 3>; |
| 166 | |
| 167 | template <typename T> |
| 168 | using NEDeconvolutionLayerFixture1x1 = DeconvolutionValidationFixture<Tensor, Accessor, NEDeconvolutionLayer, T, 1, 1>; |
| 169 | |
| 170 | TEST_SUITE(Float) |
| 171 | |
| 172 | TEST_SUITE(FP32) |
Georgios Pinitas | ced7a8d | 2018-02-01 16:31:33 +0000 | [diff] [blame] | 173 | TEST_SUITE(W4x4) |
| 174 | |
| 175 | FIXTURE_DATA_TEST_CASE(Run, NEDeconvolutionLayerFixture4x4<float>, framework::DatasetMode::ALL, combine(data4x4, framework::dataset::make("DataType", DataType::F32))) |
| 176 | { |
| 177 | // Validate output |
| 178 | validate(Accessor(_target), _reference, tolerance_fp32); |
| 179 | } |
| 180 | TEST_SUITE_END() |
| 181 | |
Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 182 | TEST_SUITE(W3x3) |
| 183 | |
| 184 | FIXTURE_DATA_TEST_CASE(Run, NEDeconvolutionLayerFixture3x3<float>, framework::DatasetMode::ALL, combine(data3x3, framework::dataset::make("DataType", DataType::F32))) |
| 185 | { |
| 186 | // Validate output |
| 187 | validate(Accessor(_target), _reference, tolerance_fp32); |
| 188 | } |
| 189 | TEST_SUITE_END() |
| 190 | |
| 191 | TEST_SUITE(W1x1) |
| 192 | FIXTURE_DATA_TEST_CASE(Run, NEDeconvolutionLayerFixture1x1<float>, framework::DatasetMode::ALL, combine(data1x1, framework::dataset::make("DataType", DataType::F32))) |
| 193 | { |
| 194 | // Validate output |
| 195 | validate(Accessor(_target), _reference, tolerance_fp32); |
| 196 | } |
| 197 | TEST_SUITE_END() |
| 198 | |
| 199 | TEST_SUITE_END() |
| 200 | TEST_SUITE_END() |
| 201 | |
| 202 | TEST_SUITE_END() |
| 203 | TEST_SUITE_END() |
| 204 | } // namespace validation |
| 205 | } // namespace test |
| 206 | } // namespace arm_compute |