Sanghoon Lee | f47bfb9 | 2018-01-23 15:16:47 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017-2018 ARM Limited. |
| 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/NELocallyConnectedLayer.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/LocallyConnectedDataset.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/LocallyConnectedFixture.h" |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | namespace |
| 44 | { |
| 45 | constexpr RelativeTolerance<float> tolerance_f32(0.0001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */ |
| 46 | } // namespace |
| 47 | |
| 48 | TEST_SUITE(NEON) |
| 49 | TEST_SUITE(LocallyConnected) |
| 50 | |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 51 | // *INDENT-OFF* |
| 52 | // clang-format off |
| 53 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 54 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32), // Mismatching data type input/weights |
| 55 | TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32), // Mismatching data type input/bias |
| 56 | TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32), // Mismatching data type input/output |
| 57 | TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32), // Mismatching shape input/weights |
| 58 | TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32), // Mismatching shape input/bias |
| 59 | TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32), // Mismatching shape input/output |
| 60 | TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32), // Asymmetric padding |
| 61 | TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32) |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 62 | }), |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 63 | framework::dataset::make("WeightsInfo",{ TensorInfo(TensorShape(3U, 3U, 5U, 21U, 275U), 1, DataType::F16), |
| 64 | TensorInfo(TensorShape(3U, 3U, 5U, 21U, 275U), 1, DataType::F32), |
| 65 | TensorInfo(TensorShape(3U, 3U, 5U, 21U, 275U), 1, DataType::F32), |
| 66 | TensorInfo(TensorShape(3U, 3U, 5U, 21U, 274U), 1, DataType::F32), |
| 67 | TensorInfo(TensorShape(3U, 3U, 5U, 21U, 275U), 1, DataType::F32), |
| 68 | TensorInfo(TensorShape(3U, 3U, 5U, 21U, 275U), 1, DataType::F32), |
| 69 | TensorInfo(TensorShape(3U, 3U, 5U, 21U, 275U), 1, DataType::F32), |
| 70 | TensorInfo(TensorShape(3U, 3U, 5U, 21U, 275U), 1, DataType::F32) |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 71 | })), |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 72 | framework::dataset::make("BiasInfo", { TensorInfo(TensorShape(21U, 275U), 1, DataType::F32), |
| 73 | TensorInfo(TensorShape(21U, 275U), 1, DataType::F16), |
| 74 | TensorInfo(TensorShape(21U, 275U), 1, DataType::F32), |
| 75 | TensorInfo(TensorShape(21U, 275U), 1, DataType::F32), |
| 76 | TensorInfo(TensorShape(21U, 274U), 1, DataType::F32), |
| 77 | TensorInfo(TensorShape(21U, 275U), 1, DataType::F32), |
| 78 | TensorInfo(TensorShape(21U, 275U), 1, DataType::F32), |
| 79 | TensorInfo(TensorShape(21U, 275U), 1, DataType::F32) |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 80 | })), |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 81 | framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32), |
| 82 | TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32), |
| 83 | TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F16), |
| 84 | TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32), |
| 85 | TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32), |
| 86 | TensorInfo(TensorShape(11U, 25U, 22U), 1, DataType::F32), |
| 87 | TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32), |
| 88 | TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32) |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 89 | })), |
| 90 | framework::dataset::make("PadStride", { PadStrideInfo(2, 1, 0, 0), |
| 91 | PadStrideInfo(2, 1, 0, 0), |
| 92 | PadStrideInfo(2, 1, 0, 0), |
| 93 | PadStrideInfo(2, 1, 0, 0), |
| 94 | PadStrideInfo(2, 1, 0, 0), |
| 95 | PadStrideInfo(2, 1, 0, 0), |
| 96 | PadStrideInfo(2, 1, 1, 0, 0, 0, DimensionRoundingType::FLOOR), |
| 97 | PadStrideInfo(2, 1, 0, 0) |
| 98 | })), |
| 99 | framework::dataset::make("Expected", { false, false, false, false, false, false, false, true })), |
| 100 | input_info, weights_info, bias_info, output_info, conv_info, expected) |
| 101 | { |
| 102 | bool is_valid = bool(NELocallyConnectedLayer::validate(&input_info.clone()->set_is_resizable(false), |
| 103 | &weights_info.clone()->set_is_resizable(false), |
| 104 | &bias_info.clone()->set_is_resizable(false), |
| 105 | &output_info.clone()->set_is_resizable(false), |
| 106 | conv_info)); |
| 107 | ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS); |
| 108 | } |
| 109 | // clang-format on |
| 110 | // *INDENT-ON* |
| 111 | |
Sanghoon Lee | f47bfb9 | 2018-01-23 15:16:47 +0000 | [diff] [blame] | 112 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallLocallyConnectedDataset(), datasets::LargeLocallyConnectedDataset()), |
| 113 | framework::dataset::make("DataType", DataType::F32)), |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 114 | src_shape, weights_shape, bias_shape, dst_shape, info, dilation, data_type) |
Sanghoon Lee | f47bfb9 | 2018-01-23 15:16:47 +0000 | [diff] [blame] | 115 | { |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 116 | ARM_COMPUTE_UNUSED(dilation); |
| 117 | |
Sanghoon Lee | f47bfb9 | 2018-01-23 15:16:47 +0000 | [diff] [blame] | 118 | // Create tensors |
| 119 | Tensor src = create_tensor<Tensor>(src_shape, data_type); |
| 120 | Tensor weights = create_tensor<Tensor>(weights_shape, data_type); |
| 121 | Tensor bias = create_tensor<Tensor>(bias_shape, data_type); |
| 122 | Tensor dst = create_tensor<Tensor>(dst_shape, data_type); |
| 123 | |
| 124 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 125 | ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 126 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 127 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 128 | |
| 129 | // Create and configure function. |
| 130 | NELocallyConnectedLayer lc; |
| 131 | lc.configure(&src, &weights, &bias, &dst, info); |
| 132 | |
| 133 | // Validate valid region |
| 134 | const ValidRegion dst_valid_region = shape_to_valid_region(dst_shape); |
| 135 | validate(dst.info()->valid_region(), dst_valid_region); |
| 136 | } |
| 137 | |
| 138 | template <typename T> |
| 139 | using NELocallyConnectedFixture = LocallyConnectedValidationFixture<Tensor, Accessor, NELocallyConnectedLayer, T>; |
| 140 | FIXTURE_DATA_TEST_CASE(RunSmall, NELocallyConnectedFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallLocallyConnectedDataset(), |
| 141 | framework::dataset::make("DataType", |
| 142 | DataType::F32))) |
| 143 | { |
| 144 | // Validate output |
| 145 | validate(Accessor(_target), _reference, tolerance_f32); |
| 146 | } |
| 147 | |
Michalis Spyrou | dc200dc | 2019-09-25 18:13:19 +0100 | [diff] [blame] | 148 | FIXTURE_DATA_TEST_CASE(RunLarge, NELocallyConnectedFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeLocallyConnectedDataset(), |
Sanghoon Lee | f47bfb9 | 2018-01-23 15:16:47 +0000 | [diff] [blame] | 149 | framework::dataset::make("DataType", |
| 150 | DataType::F32))) |
| 151 | { |
| 152 | // Validate output |
| 153 | validate(Accessor(_target), _reference, tolerance_f32); |
| 154 | } |
| 155 | TEST_SUITE_END() |
| 156 | TEST_SUITE_END() |
| 157 | } // namespace validation |
| 158 | } // namespace test |
| 159 | } // namespace arm_compute |