Compute Library
 20.11
DilatedConvolutionLayer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020 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"
29 #include "tests/NEON/Accessor.h"
31 #include "tests/datasets/DilatedConvolutionLayerDataset.h"
33 #include "tests/framework/Macros.h"
36 #include "tests/validation/fixtures/ConvolutionLayerFixture.h"
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 namespace
45 {
46 const AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
47 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
48 const AbsoluteTolerance<float> abs_tolerance_f16(0.3f); /**< Absolute tolerance value for comparing reference's output against implementation's output for DataType::F16 */
49 const RelativeTolerance<half_float::half> rel_tolerance_f16(half_float::half(0.2f)); /**< Relative tolerance value for comparing reference's output against implementation's output for DataType::F16 */
50 constexpr float tolerance_num_f16 = 0.07f; /**< Tolerance number for FP16 */
51 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
52 constexpr AbsoluteTolerance<float> tolerance_qasymm8(0.0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
53 
54 /** CNN data types */
55 const auto CNNDataTypes = framework::dataset::make("DataType",
56 {
57 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
59 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
62 });
63 } // namespace
64 
65 TEST_SUITE(NEON)
66 TEST_SUITE(DilatedConvolutionLayer)
67 
68 // *INDENT-OFF*
69 // clang-format off
70 DATA_TEST_CASE(ValidateConvolutionMethod, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
71  framework::dataset::make("InputInfo", { TensorInfo(TensorShape(8U, 8U, 2U), 1, DataType::F32),
72  TensorInfo(TensorShape(23U, 27U, 5U, 4U), 1, DataType::F32),
73  TensorInfo(TensorShape(3U, 3U, 2U, 1U), 1, DataType::F32),
74  TensorInfo(TensorShape(33U, 27U, 7U, 4U), 1, DataType::F32)
75  }),
76  framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32),
77  TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32),
78  TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32),
79  TensorInfo(TensorShape(5U, 5U, 7U, 16U), 1, DataType::F16)
80  })),
81  framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(6U, 6U, 1U), 1, DataType::F32),
82  TensorInfo(TensorShape(21U, 25U, 21U, 4U), 1, DataType::F32),
83  TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32),
84  TensorInfo(TensorShape(11U, 12U, 16U, 4U), 1, DataType::F32)
85  })),
86  framework::dataset::make("ConvInfo", { PadStrideInfo(1, 1, 0, 0),
87  PadStrideInfo(1, 1, 0, 0),
88  PadStrideInfo(2, 1, 0, 0),
89  PadStrideInfo(3, 2, 1, 0)
90  })),
91  framework::dataset::make("Dilation", { Size2D(1U, 2U),
92  Size2D(2U, 1U),
93  Size2D(2U, 2U),
94  Size2D(3U, 3U)
95  })),
98 {
99  ConvolutionMethod is_valid = NEConvolutionLayer::get_convolution_method(&input_info.clone()->set_is_resizable(false),
100  &weights_info.clone()->set_is_resizable(false),
101  &output_info.clone()->set_is_resizable(false),
102  conv_info, WeightsInfo(), dilation);
104 }
105 // clang-format on
106 // *INDENT-ON*
107 TEST_SUITE_END() // DilatedConvolutionLayer
108 
109 TEST_SUITE(GEMMDilatedConvolutionLayer)
110 
111 template <typename T>
112 using NEGEMMDilatedConvolutionLayerFixture = ConvolutionValidationFixture<Tensor, Accessor, NEConvolutionLayer, T>;
113 
114 TEST_SUITE(Float)
115 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
116 TEST_SUITE(FP16)
117 FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
118  framework::dataset::make("ReshapeWeights", { true })),
120  framework::dataset::make("DataLayout", { DataLayout::NCHW })),
121  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
122 {
123  // Validate output
124  validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16);
125 }
126 FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
127  framework::dataset::make("ReshapeWeights", { true })),
129  framework::dataset::make("DataLayout", { DataLayout::NCHW })),
130  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
131 {
132  // Validate output
133  validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16, abs_tolerance_f16);
134 }
135 TEST_SUITE_END() // FP16
136 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
137 
138 TEST_SUITE(FP32)
139 FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
140  framework::dataset::make("ReshapeWeights", { true })),
143  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
144 {
145  // Validate output
146  validate(Accessor(_target), _reference, tolerance_f32);
147 }
148 FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
149  framework::dataset::make("ReshapeWeights", { true })),
152  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
153 {
154  // Validate output
155  validate(Accessor(_target), _reference, tolerance_f32);
156 }
157 TEST_SUITE_END() // FP32
158 TEST_SUITE_END() // Float
159 
160 template <typename T>
161 using NEGEMMDilatedConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<Tensor, Accessor, NEGEMMConvolutionLayer, T>;
162 
163 TEST_SUITE(Quantized)
164 TEST_SUITE(QASYMM8)
165 FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
166  combine(combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
167  framework::dataset::make("ReshapeWeights", { true })),
169  framework::dataset::make("DataLayout", { DataLayout::NCHW })),
170  framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
171  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
172 {
173  // Validate output
174  validate(Accessor(_target), _reference, tolerance_qasymm8);
175 }
176 FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY,
177  combine(combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
178  framework::dataset::make("ReshapeWeights", { true })),
180  framework::dataset::make("DataLayout", { DataLayout::NCHW })),
181  framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
182  framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
183 {
184  // Validate output
185  validate(Accessor(_target), _reference, tolerance_qasymm8);
186 }
187 TEST_SUITE_END() // QASYMM8
188 TEST_SUITE_END() // Quantized
189 
190 TEST_SUITE_END() // GEMMDilatedConvolutionLayer
191 TEST_SUITE_END() // NEON
192 } // namespace validation
193 } // namespace test
194 } // namespace arm_compute
Shape of a tensor.
Definition: TensorShape.h:39
RelativeTolerance< float > tolerance_f32(0.001f)
F32 Tolerance value for comparing reference's output against implementation's output for floating poi...
constexpr float tolerance_num_f16
F16 Tolerance number.
Definition: cl_gemm.cpp:76
half_float::half half
16-bit floating point type
Definition: Types.h:46
1 channel, 1 F32 per channel
ARM_COMPUTE_EXPECT(has_error==expected, framework::LogLevel::ERRORS)
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
ConvolutionMethod
Available ConvolutionMethod.
Definition: Types.h:138
Activation Layer Information class.
Definition: Types.h:1541
Copyright (c) 2017-2020 Arm Limited.
1 channel, 1 F16 per channel
Quantization information.
DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), }), framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), })), framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::SQRT), })), framework::dataset::make("Expected", { false, true, true, true, false, false, true, true, false })), input_info, output_info, act_info, expected)
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
quantized, asymmetric fixed-point 8-bit number unsigned
TEST_SUITE(U8_to_S8) FIXTURE_DATA_TEST_CASE(RunSmall
validate(CLAccessor(output_state), expected_output)
Num samples, channels, height, width.
FIXTURE_DATA_TEST_CASE(RunSmall, CLAbsLayerFixture< half >, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Definition: AbsLayer.cpp:50
static ConvolutionMethod get_convolution_method(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info=WeightsInfo(), const Size2D &dilation=Size2D(1U, 1U), const ActivationLayerInfo &act_info=ActivationLayerInfo(), bool enable_fast_math=false)
Static function to check if given info will return the convolution called by NEConvolutionLayer.
Num samples, height, width, channels.
Store the tensor's metadata.
Definition: TensorInfo.h:45
zip(zip(framework::dataset::make("Weights", { TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U, 1U), 1, DataType::F32), }), framework::dataset::make("MVBGInfo",{ TensorInfo(TensorShape(2U), 1, DataType::F32), TensorInfo(TensorShape(2U), 1, DataType::F16), TensorInfo(TensorShape(5U), 1, DataType::F32), })), framework::dataset::make("Expected", { true, false, false}))
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65