John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2020 Arm Limited. |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [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/graph.h" |
| 25 | |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 26 | #include "tests/NEON/Accessor.h" |
| 27 | #include "tests/validation/Validation.h" |
| 28 | #include "tests/validation/reference/ConvolutionLayer.h" |
| 29 | #include "tests/validation/reference/Permute.h" |
| 30 | |
| 31 | #include "utils/CommonGraphOptions.h" |
| 32 | #include "utils/GraphUtils.h" |
| 33 | #include "utils/Utils.h" |
| 34 | |
| 35 | #include "ValidateExample.h" |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 36 | #include "graph_validate_utils.h" |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 37 | |
| 38 | #include <utility> |
| 39 | |
| 40 | using namespace arm_compute::utils; |
| 41 | using namespace arm_compute::graph::frontend; |
| 42 | using namespace arm_compute::graph_utils; |
| 43 | using namespace arm_compute::graph; |
| 44 | using namespace arm_compute; |
| 45 | using namespace arm_compute::test; |
| 46 | using namespace arm_compute::test::validation; |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 47 | |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 48 | namespace |
| 49 | { |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 50 | /** Convolution command line options used to configure the graph examples |
| 51 | * |
| 52 | * (Similar to common options) |
| 53 | * The options in this object get populated when "parse()" is called on the parser used to construct it. |
| 54 | * The expected workflow is: |
| 55 | * |
| 56 | * CommandLineParser parser; |
| 57 | * CommonOptions options( parser ); |
| 58 | * parser.parse(argc, argv); |
| 59 | */ |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 60 | class ConvolutionOptions final : public CommonGraphValidateOptions |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 61 | { |
| 62 | public: |
| 63 | explicit ConvolutionOptions(CommandLineParser &parser) noexcept |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 64 | : CommonGraphValidateOptions(parser), |
| 65 | width(parser.add_option<SimpleOption<int>>("width", 9)), |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 66 | height(parser.add_option<SimpleOption<int>>("height", 9)), |
| 67 | channels(parser.add_option<SimpleOption<int>>("channels", 1)), |
| 68 | batch(parser.add_option<SimpleOption<int>>("batch", 1)), |
| 69 | weights_width(parser.add_option<SimpleOption<int>>("weights_width", 3)), |
| 70 | weights_height(parser.add_option<SimpleOption<int>>("weights_height", 3)), |
| 71 | OFM(parser.add_option<SimpleOption<int>>("OFM", 1)), |
| 72 | padding_top(parser.add_option<SimpleOption<int>>("padding_top", 0)), |
| 73 | padding_left(parser.add_option<SimpleOption<int>>("padding_left", 0)), |
| 74 | padding_bottom(parser.add_option<SimpleOption<int>>("padding_bottom", 0)), |
| 75 | padding_right(parser.add_option<SimpleOption<int>>("padding_right", 0)), |
| 76 | stride_x(parser.add_option<SimpleOption<int>>("stride_x", 1)), |
| 77 | stride_y(parser.add_option<SimpleOption<int>>("stride_y", 1)), |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 78 | padding_mode(), |
| 79 | conv_mode(), |
| 80 | data_layout(), |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 81 | scale(parser.add_option<SimpleOption<float>>("scale", 1.0f)), |
| 82 | offset(parser.add_option<SimpleOption<int>>("offset", 0)), |
| 83 | weights_scale(parser.add_option<SimpleOption<float>>("weights_scale", 1.0f)), |
| 84 | weights_offset(parser.add_option<SimpleOption<int>>("weights_offset", 0)), |
| 85 | output_scale(parser.add_option<SimpleOption<float>>("output_scale", 1.0f)), |
| 86 | output_offset(parser.add_option<SimpleOption<int>>("output_offset", 0)), |
| 87 | input_range_low(parser.add_option<SimpleOption<uint64_t>>("input_range_low")), |
| 88 | input_range_high(parser.add_option<SimpleOption<uint64_t>>("input_range_high")), |
| 89 | weights_range_low(parser.add_option<SimpleOption<uint64_t>>("weights_range_low")), |
| 90 | weights_range_high(parser.add_option<SimpleOption<uint64_t>>("weights_range_high")), |
| 91 | input_npy(parser.add_option<SimpleOption<std::string>>("input_image")), |
| 92 | output_npy(parser.add_option<SimpleOption<std::string>>("reference_image")), |
| 93 | weights_npy(parser.add_option<SimpleOption<std::string>>("weights_npy")), |
| 94 | bias_npy(parser.add_option<SimpleOption<std::string>>("bias_image")) |
| 95 | { |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 96 | const std::set<ConvolutionPaddingMode> available_padding_modes |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 97 | { |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 98 | ConvolutionPaddingMode::Valid, |
| 99 | ConvolutionPaddingMode::Same |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | const std::set<arm_compute::graph::ConvolutionMethod> supported_convolution_methods |
| 103 | { |
| 104 | arm_compute::graph::ConvolutionMethod::Default, |
| 105 | arm_compute::graph::ConvolutionMethod::GEMM, |
| 106 | arm_compute::graph::ConvolutionMethod::Winograd, |
| 107 | arm_compute::graph::ConvolutionMethod::Direct |
| 108 | }; |
| 109 | |
| 110 | const std::set<DataLayout> supported_data_layouts |
| 111 | { |
| 112 | DataLayout::NHWC, |
| 113 | DataLayout::NCHW, |
| 114 | }; |
| 115 | |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 116 | padding_mode = parser.add_option<EnumOption<ConvolutionPaddingMode>>("padding_mode", available_padding_modes, ConvolutionPaddingMode::Valid); |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 117 | conv_mode = parser.add_option<EnumOption<arm_compute::graph::ConvolutionMethod>>("convolution_method", supported_convolution_methods, arm_compute::graph::ConvolutionMethod::Default); |
| 118 | data_layout = parser.add_option<EnumOption<DataLayout>>("layout", supported_data_layouts, DataLayout::NHWC); |
| 119 | |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 120 | padding_mode->set_help("Set padding mode"); |
| 121 | help->set_help("Show this help message"); |
| 122 | width->set_help("Set Input dimension width"); |
| 123 | height->set_help("Set Input dimension height"); |
| 124 | channels->set_help("Set Input dimension channels"); |
| 125 | batch->set_help("Set Input dimension batch"); |
| 126 | weights_width->set_help("Set weights_dimensions width"); |
| 127 | weights_height->set_help("Set weights_dimensions height"); |
| 128 | OFM->set_help("Set OFM"); |
| 129 | padding_top->set_help("Set padding top"); |
| 130 | padding_bottom->set_help("Set padding bottom"); |
| 131 | padding_left->set_help("Set padding left"); |
| 132 | padding_right->set_help("Set padding right"); |
| 133 | stride_x->set_help("Set padding stride x"); |
| 134 | stride_y->set_help("Set padding stride y"); |
| 135 | conv_mode->set_help("Set convolution method"); |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 136 | scale->set_help("Quantization scale from QASYMM8"); |
| 137 | offset->set_help("Quantization offset from QASYMM8"); |
| 138 | weights_scale->set_help("Quantization scale from QASYMM8"); |
| 139 | weights_offset->set_help("Quantization offset from QASYMM8"); |
| 140 | output_scale->set_help("Quantization scale from QASYMM8"); |
| 141 | output_offset->set_help("Quantization offset from QASYMM8"); |
| 142 | input_npy->set_help("Use input .npy instead"); |
| 143 | output_npy->set_help("Use .npy as a reference"); |
| 144 | input_range_low->set_help("Lower bound for input randomization range"); |
| 145 | input_range_high->set_help("Lower bound for input randomization range"); |
| 146 | weights_range_low->set_help("Lower bound for input randomization range"); |
| 147 | weights_range_high->set_help("Lower bound for input randomization range"); |
| 148 | } |
| 149 | |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 150 | /** Fill out the supplied parameters with user supplied parameters |
| 151 | * |
| 152 | * @param[out] os Output stream. |
| 153 | * @param[in] common_params Example parameters to output |
| 154 | * |
| 155 | * @return None. |
| 156 | */ |
| 157 | void consume_parameters(ExampleParams &common_params) |
| 158 | { |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 159 | common_params.input.width = width->value(); |
| 160 | common_params.input.height = height->value(); |
| 161 | common_params.input.fm = channels->value(); |
| 162 | common_params.input.batch = batch->value(); |
| 163 | common_params.input.quant_info = QuantizationInfo(scale->value(), offset->value()); |
| 164 | common_params.input.npy = input_npy->value(); |
| 165 | common_params.input.range_low = input_range_low->value(); |
| 166 | common_params.input.range_high = input_range_high->value(); |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 167 | |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 168 | common_params.weights.width = weights_width->value(); |
| 169 | common_params.weights.height = weights_height->value(); |
| 170 | common_params.weights.fm = OFM->value(); |
| 171 | common_params.weights.npy = weights_npy->value(); |
| 172 | common_params.weights.quant_info = QuantizationInfo(weights_scale->value(), weights_offset->value()); |
| 173 | common_params.weights.range_low = weights_range_low->value(); |
| 174 | common_params.weights.range_high = weights_range_high->value(); |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 175 | |
| 176 | common_params.bias.npy = bias_npy->value(); |
| 177 | |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 178 | common_params.output.quant_info = QuantizationInfo(output_scale->value(), output_offset->value()); |
| 179 | common_params.output.npy = output_npy->value(); |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 180 | |
| 181 | common_params.convolution.padding_mode = padding_mode->value(); |
| 182 | common_params.convolution.padding_top = padding_top->value(); |
| 183 | common_params.convolution.padding_bottom = padding_bottom->value(); |
| 184 | common_params.convolution.padding_left = padding_left->value(); |
| 185 | common_params.convolution.padding_right = padding_right->value(); |
| 186 | common_params.convolution.padding_stride_x = stride_x->value(); |
| 187 | common_params.convolution.padding_stride_y = stride_y->value(); |
| 188 | |
| 189 | common_params.data_type = data_type->value(); |
| 190 | common_params.data_layout = data_layout->value(); |
| 191 | common_params.convolution_method = conv_mode->value(); |
| 192 | } |
| 193 | |
| 194 | void print_parameters(::std::ostream &os, const ExampleParams &common_params) override |
| 195 | { |
| 196 | os << "Threads : " << common_params.common_params.threads << std::endl; |
| 197 | os << "Target : " << common_params.common_params.target << std::endl; |
| 198 | os << "Data type : " << common_params.data_type << std::endl; |
| 199 | os << "Input dimensions(X,Y, Channels, Batch) : (" << common_params.input.width << "," << common_params.input.height << "," << common_params.input.fm << "," << common_params.input.batch << ")" |
| 200 | << std::endl; |
| 201 | os << "Weight dimensions(X,Y, Channels(same as input), OFM) : (" << common_params.weights.width << "," << common_params.weights.height << "," << common_params.input.fm << "," << |
| 202 | common_params.weights.fm << ")" << std::endl; |
| 203 | os << "Padding(top, bottom, left, right) (stride x, stride y) : (" << common_params.convolution.padding_top << "," << common_params.convolution.padding_bottom << "," << |
| 204 | common_params.convolution.padding_left << "," << common_params.convolution.padding_right << ") (" << common_params.convolution.padding_stride_x << "," << common_params.convolution.padding_stride_y << |
| 205 | ")" << std::endl; |
| 206 | os << "Padding Mode: " << common_params.convolution.padding_mode << std::endl; |
| 207 | os << "Convolution Method: " << common_params.convolution_method << std::endl; |
| 208 | } |
| 209 | |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 210 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 211 | ConvolutionOptions(const ConvolutionOptions &) = delete; |
| 212 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 213 | ConvolutionOptions &operator=(const ConvolutionOptions &) = delete; |
| 214 | /** Allow instances of this class to be moved */ |
| 215 | ConvolutionOptions(ConvolutionOptions &&) noexcept(true) = default; |
| 216 | /** Allow instances of this class to be moved */ |
| 217 | ConvolutionOptions &operator=(ConvolutionOptions &&) noexcept(true) = default; |
| 218 | /** Default destructor */ |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 219 | ~ConvolutionOptions() override = default; |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 220 | |
Michalis Spyrou | bcfd09a | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 221 | private: |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 222 | SimpleOption<int> *width; /**< Input width */ |
| 223 | SimpleOption<int> *height; /**< Input height */ |
| 224 | SimpleOption<int> *channels; /**< Input channels */ |
| 225 | SimpleOption<int> *batch; /**< Input batch */ |
| 226 | SimpleOption<int> *weights_width; /**< weights width */ |
| 227 | SimpleOption<int> *weights_height; /**< weights height */ |
| 228 | SimpleOption<int> *OFM; /**< Output Feature Map */ |
| 229 | SimpleOption<int> *padding_top; /**< Padding top */ |
| 230 | SimpleOption<int> *padding_left; /**< Padding left */ |
| 231 | SimpleOption<int> *padding_bottom; /**< Padding bottom */ |
| 232 | SimpleOption<int> *padding_right; /**< Padding right */ |
| 233 | SimpleOption<int> *stride_x; /**< Padding stride x */ |
| 234 | SimpleOption<int> *stride_y; /**< Padding stride y */ |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 235 | EnumOption<ConvolutionPaddingMode> *padding_mode; /**< Padding mode */ |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 236 | EnumOption<arm_compute::graph::ConvolutionMethod> *conv_mode; /**< Convolution method */ |
| 237 | EnumOption<arm_compute::DataLayout> *data_layout; /**< Graph data layout */ |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 238 | SimpleOption<float> *scale; /**< Input Quantization scale from QASYMM8 */ |
| 239 | SimpleOption<int> *offset; /**< Input Quantization offset from QASYMM8 */ |
| 240 | SimpleOption<float> *weights_scale; /**< Weights Quantization scale from QASYMM8 */ |
| 241 | SimpleOption<int> *weights_offset; /**< Weights Quantization offset from QASYMM8 */ |
| 242 | SimpleOption<float> *output_scale; /**< Output Quantization scale from QASYMM8 */ |
| 243 | SimpleOption<int> *output_offset; /**< Output Quantization offset from QASYMM8 */ |
| 244 | SimpleOption<uint64_t> *input_range_low; /**< Lower bound for input randomization range */ |
| 245 | SimpleOption<uint64_t> *input_range_high; /**< Upper bound for input randomization range */ |
| 246 | SimpleOption<uint64_t> *weights_range_low; /**< Lower bound for weights randomization range */ |
| 247 | SimpleOption<uint64_t> *weights_range_high; /**< Upper bound for weights randomization range */ |
| 248 | |
| 249 | SimpleOption<std::string> *input_npy; /**< Use input .npy image */ |
| 250 | SimpleOption<std::string> *output_npy; /**< Use output .npy image to verify*/ |
| 251 | SimpleOption<std::string> *weights_npy; /**< Use weights .npy image */ |
| 252 | SimpleOption<std::string> *bias_npy; /**< Use bias .npy image */ |
| 253 | }; |
| 254 | |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 255 | /** ConvolutionLayer Graph example validation accessor class */ |
| 256 | template <typename D> |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 257 | class ConvolutionVerifyAccessor final : public VerifyAccessor<D> |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 258 | { |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 259 | using BaseClassType = VerifyAccessor<D>; |
| 260 | using BaseClassType::BaseClassType; |
| 261 | using BaseClassType::_params; |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 262 | using TBias = typename std::conditional<std::is_same<typename std::decay<D>::type, uint8_t>::value, int32_t, D>::type; |
| 263 | |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 264 | SimpleTensor<D> reference(SimpleTensor<D> &src, SimpleTensor<D> &weights, SimpleTensor<TBias> &bias, const TensorShape &output_shape) override |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 265 | { |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 266 | // Calculate padding information |
| 267 | const PadStrideInfo padding_info = calculate_convolution_padding(_params); |
| 268 | |
| 269 | //Calculate reference |
| 270 | return reference::convolution_layer<D>(src, weights, bias, output_shape, padding_info, Size2D(1, 1), |
| 271 | 1, _params.output.quant_info); |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 272 | } |
| 273 | |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 274 | float relative_tolerance() override |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 275 | { |
| 276 | const std::map<arm_compute::graph::Target, const std::map<DataType, float>> relative_tolerance |
| 277 | { |
| 278 | { |
| 279 | arm_compute::graph::Target::CL, |
| 280 | { { DataType::F16, 0.2f }, |
| 281 | { DataType::F32, 0.5f }, |
| 282 | { DataType::QASYMM8, 1.0f } |
| 283 | } |
| 284 | }, |
| 285 | { |
| 286 | arm_compute::graph::Target::NEON, |
| 287 | { { DataType::F16, 0.2f }, |
| 288 | { DataType::F32, 0.01f }, |
| 289 | { DataType::QASYMM8, 0.0f } |
| 290 | } |
| 291 | } |
| 292 | }; |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 293 | |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 294 | if(_params.convolution_method == arm_compute::graph::ConvolutionMethod::Winograd |
| 295 | && _params.data_type == DataType::F32 |
| 296 | && _params.common_params.target == arm_compute::graph::Target::NEON) |
| 297 | { |
| 298 | return 0.05f; |
| 299 | } |
| 300 | else |
| 301 | { |
| 302 | return relative_tolerance.at(_params.common_params.target).at(_params.data_type); |
| 303 | } |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 304 | } |
| 305 | |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 306 | float absolute_tolerance() override |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 307 | { |
| 308 | const std::map<Target, const std::map<DataType, float>> absolute_tolerance |
| 309 | { |
| 310 | { |
| 311 | Target::CL, |
| 312 | { { DataType::F16, 0.0f }, |
| 313 | { DataType::F32, 0.0001f }, |
| 314 | { DataType::QASYMM8, 0.0f } |
| 315 | } |
| 316 | }, |
| 317 | { |
| 318 | Target::NEON, |
| 319 | { { DataType::F16, 0.2f }, |
| 320 | { DataType::F32, 0.002f }, |
| 321 | { DataType::QASYMM8, 0.0f } |
| 322 | } |
| 323 | } |
| 324 | }; |
| 325 | |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 326 | return absolute_tolerance.at(_params.common_params.target).at(_params.data_type); |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 327 | } |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 328 | |
| 329 | float tolerance_number() override |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 330 | { |
| 331 | const std::map<Target, const std::map<DataType, float>> absolute_tolerance |
| 332 | { |
| 333 | { |
| 334 | Target::CL, |
| 335 | { { DataType::F16, 0.07f }, |
| 336 | { DataType::F32, 0.07f }, |
| 337 | { DataType::QASYMM8, 0.0f } |
| 338 | } |
| 339 | }, |
| 340 | { |
| 341 | Target::NEON, |
| 342 | { { DataType::F16, 0.07f }, |
| 343 | { DataType::F32, 0.0f }, |
| 344 | { DataType::QASYMM8, 0.0f } |
| 345 | } |
| 346 | } |
| 347 | }; |
| 348 | |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 349 | return absolute_tolerance.at(_params.common_params.target).at(_params.data_type); |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 350 | } |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 351 | }; |
| 352 | |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 353 | } // namespace |
| 354 | |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 355 | class GraphConvolutionValidateExample final : public GraphValidateExample<ConvolutionLayer, ConvolutionOptions, ConvolutionVerifyAccessor> |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 356 | { |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 357 | using GraphValidateExample::graph; |
| 358 | |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 359 | public: |
| 360 | GraphConvolutionValidateExample() |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 361 | : GraphValidateExample("Convolution Graph example") |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 362 | { |
| 363 | } |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 364 | |
| 365 | ConvolutionLayer GraphFunctionLayer(ExampleParams ¶ms) override |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 366 | { |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 367 | const PixelValue lower = PixelValue(params.input.range_low, params.data_type, params.input.quant_info); |
| 368 | const PixelValue upper = PixelValue(params.input.range_high, params.data_type, params.input.quant_info); |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 369 | |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 370 | const PixelValue weights_lower = PixelValue(params.weights.range_low, params.data_type, params.weights.quant_info); |
| 371 | const PixelValue weights_upper = PixelValue(params.weights.range_high, params.data_type, params.weights.quant_info); |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 372 | |
| 373 | // Calculate padding information |
| 374 | const PadStrideInfo padding_info = calculate_convolution_padding(params); |
| 375 | |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 376 | return ConvolutionLayer(params.weights.width, params.weights.height, params.weights.fm, |
| 377 | get_accessor(params.weights, weights_lower, weights_upper, 1), |
| 378 | get_accessor(params.bias, lower, upper, 2), |
| 379 | padding_info, 1, params.weights.quant_info, params.output.quant_info); |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 380 | } |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 381 | }; |
| 382 | |
| 383 | /** Main program for Graph Convolution test |
| 384 | * |
| 385 | * @param[in] argc Number of arguments |
| 386 | * @param[in] argv Arguments ( Input dimensions [width, height, channels, batch] |
| 387 | * Weights dimensions [width, height, OFM] |
| 388 | * Padding [top,bottom,left,right, Stride x, Stride y, mode [Valid / Same / Manual] ) |
| 389 | * Convolution Method[ Auto/GEMM/Winograd/Direct] |
| 390 | * Verification[tolerance_number,absolute_tolerance,relative_tolerance] ) |
| 391 | * |
| 392 | */ |
| 393 | int main(int argc, char **argv) |
| 394 | { |
| 395 | return arm_compute::utils::run_example<GraphConvolutionValidateExample>(argc, argv); |
| 396 | } |