Compute Library
 21.02
graph_ssd_mobilenet.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2021 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/graph.h"
27 #include "utils/GraphUtils.h"
28 #include "utils/Utils.h"
29 
30 using namespace arm_compute;
31 using namespace arm_compute::utils;
32 using namespace arm_compute::graph::frontend;
33 using namespace arm_compute::graph_utils;
34 
35 /** Example demonstrating how to implement MobileNetSSD's network using the Compute Library's graph API */
36 class GraphSSDMobilenetExample : public Example
37 {
38 public:
39  GraphSSDMobilenetExample()
40  : cmd_parser(), common_opts(cmd_parser), common_params(), graph(0, "MobileNetSSD")
41  {
42  // Add topk option
43  keep_topk_opt = cmd_parser.add_option<SimpleOption<int>>("topk", 100);
44  keep_topk_opt->set_help("Top k detections results per image. Used for data type F32.");
45  // Add output option
46  detection_boxes_opt = cmd_parser.add_option<SimpleOption<std::string>>("detection_boxes_opt", "");
47  detection_boxes_opt->set_help("Filename containing the reference values for the graph output detection_boxes. Used for data type QASYMM8.");
48  detection_classes_opt = cmd_parser.add_option<SimpleOption<std::string>>("detection_classes_opt", "");
49  detection_classes_opt->set_help("Filename containing the reference values for the output detection_classes. Used for data type QASYMM8.");
50  detection_scores_opt = cmd_parser.add_option<SimpleOption<std::string>>("detection_scores_opt", "");
51  detection_scores_opt->set_help("Filename containing the reference values for the output detection_scores. Used for data type QASYMM8.");
52  num_detections_opt = cmd_parser.add_option<SimpleOption<std::string>>("num_detections_opt", "");
53  num_detections_opt->set_help("Filename containing the reference values for the output num_detections. Used with datatype QASYMM8.");
54  }
55  GraphSSDMobilenetExample(const GraphSSDMobilenetExample &) = delete;
56  GraphSSDMobilenetExample &operator=(const GraphSSDMobilenetExample &) = delete;
57  ~GraphSSDMobilenetExample() override = default;
58  bool do_setup(int argc, char **argv) override
59  {
60  // Parse arguments
61  cmd_parser.parse(argc, argv);
62  cmd_parser.validate();
63 
64  // Consume common parameters
65  common_params = consume_common_graph_parameters(common_opts);
66 
67  // Return when help menu is requested
68  if(common_params.help)
69  {
70  cmd_parser.print_help(argv[0]);
71  return false;
72  }
73 
74  // Print parameter values
75  std::cout << common_params << std::endl;
76 
77  // Create input descriptor
78  const TensorShape tensor_shape = permute_shape(TensorShape(300, 300, 3U, 1U), DataLayout::NCHW, common_params.data_layout);
79  TensorDescriptor input_descriptor = TensorDescriptor(tensor_shape, common_params.data_type).set_layout(common_params.data_layout);
80 
81  // Set graph hints
82  graph << common_params.target
83  << common_params.fast_math_hint;
84 
85  // Create core graph
86  if(arm_compute::is_data_type_float(common_params.data_type))
87  {
88  create_graph_float(input_descriptor);
89  }
90  else
91  {
92  create_graph_qasymm(input_descriptor);
93  }
94 
95  // Finalize graph
96  GraphConfig config;
97  config.num_threads = common_params.threads;
98  config.use_tuner = common_params.enable_tuner;
99  config.tuner_file = common_params.tuner_file;
100  config.mlgo_file = common_params.mlgo_file;
101 
102  graph.finalize(common_params.target, config);
103 
104  return true;
105  }
106  void do_run() override
107  {
108  // Run graph
109  graph.run();
110  }
111 
112 private:
113  CommandLineParser cmd_parser;
114  CommonGraphOptions common_opts;
115  SimpleOption<int> *keep_topk_opt{ nullptr };
116  CommonGraphParams common_params;
117  Stream graph;
118 
119  SimpleOption<std::string> *detection_boxes_opt{ nullptr };
120  SimpleOption<std::string> *detection_classes_opt{ nullptr };
121  SimpleOption<std::string> *detection_scores_opt{ nullptr };
122  SimpleOption<std::string> *num_detections_opt{ nullptr };
123 
124  ConcatLayer get_node_A_float(IStream &master_graph, const std::string &data_path, std::string &&param_path,
125  unsigned int conv_filt,
126  PadStrideInfo dwc_pad_stride_info, PadStrideInfo conv_pad_stride_info)
127  {
128  const std::string total_path = param_path + "_";
129  SubStream sg(master_graph);
130 
132  3U, 3U,
133  get_weights_accessor(data_path, total_path + "dw_w.npy"),
134  std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
135  dwc_pad_stride_info)
136  .set_name(param_path + "/dw")
137  << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "dw_bn_mean.npy"),
138  get_weights_accessor(data_path, total_path + "dw_bn_var.npy"),
139  get_weights_accessor(data_path, total_path + "dw_scale_w.npy"),
140  get_weights_accessor(data_path, total_path + "dw_scale_b.npy"), 0.00001f)
141  .set_name(param_path + "/dw/bn")
143 
144  << ConvolutionLayer(
145  1U, 1U, conv_filt,
146  get_weights_accessor(data_path, total_path + "w.npy"),
147  std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
148  conv_pad_stride_info)
149  .set_name(param_path + "/pw")
150  << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "bn_mean.npy"),
151  get_weights_accessor(data_path, total_path + "bn_var.npy"),
152  get_weights_accessor(data_path, total_path + "scale_w.npy"),
153  get_weights_accessor(data_path, total_path + "scale_b.npy"), 0.00001f)
154  .set_name(param_path + "/pw/bn")
156 
157  return ConcatLayer(std::move(sg));
158  }
159 
160  ConcatLayer get_node_B_float(IStream &master_graph, const std::string &data_path, std::string &&param_path,
161  unsigned int conv_filt,
162  PadStrideInfo conv_pad_stride_info_1, PadStrideInfo conv_pad_stride_info_2)
163  {
164  const std::string total_path = param_path + "_";
165  SubStream sg(master_graph);
166 
167  sg << ConvolutionLayer(
168  1, 1, conv_filt / 2,
169  get_weights_accessor(data_path, total_path + "1_w.npy"),
170  std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
171  conv_pad_stride_info_1)
172  .set_name(total_path + "1/conv")
173  << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "1_bn_mean.npy"),
174  get_weights_accessor(data_path, total_path + "1_bn_var.npy"),
175  get_weights_accessor(data_path, total_path + "1_scale_w.npy"),
176  get_weights_accessor(data_path, total_path + "1_scale_b.npy"), 0.00001f)
177  .set_name(total_path + "1/bn")
179 
180  sg << ConvolutionLayer(
181  3, 3, conv_filt,
182  get_weights_accessor(data_path, total_path + "2_w.npy"),
183  std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
184  conv_pad_stride_info_2)
185  .set_name(total_path + "2/conv")
186  << BatchNormalizationLayer(get_weights_accessor(data_path, total_path + "2_bn_mean.npy"),
187  get_weights_accessor(data_path, total_path + "2_bn_var.npy"),
188  get_weights_accessor(data_path, total_path + "2_scale_w.npy"),
189  get_weights_accessor(data_path, total_path + "2_scale_b.npy"), 0.00001f)
190  .set_name(total_path + "2/bn")
192 
193  return ConcatLayer(std::move(sg));
194  }
195 
196  ConcatLayer get_node_C_float(IStream &master_graph, const std::string &data_path, std::string &&param_path,
197  unsigned int conv_filt, PadStrideInfo conv_pad_stride_info)
198  {
199  const std::string total_path = param_path + "_";
200  SubStream sg(master_graph);
201  sg << ConvolutionLayer(
202  1U, 1U, conv_filt,
203  get_weights_accessor(data_path, total_path + "w.npy"),
204  get_weights_accessor(data_path, total_path + "b.npy"),
205  conv_pad_stride_info)
206  .set_name(param_path + "/conv");
207  if(common_params.data_layout == DataLayout::NCHW)
208  {
209  sg << PermuteLayer(PermutationVector(2U, 0U, 1U), DataLayout::NHWC).set_name(param_path + "/perm");
210  }
211  sg << FlattenLayer().set_name(param_path + "/flat");
212 
213  return ConcatLayer(std::move(sg));
214  }
215 
216  void create_graph_float(TensorDescriptor &input_descriptor)
217  {
218  // Create a preprocessor object
219  const std::array<float, 3> mean_rgb{ { 127.5f, 127.5f, 127.5f } };
220  std::unique_ptr<IPreprocessor> preprocessor = std::make_unique<CaffePreproccessor>(mean_rgb, true, 0.007843f);
221 
222  // Get trainable parameters data path
223  std::string data_path = common_params.data_path;
224 
225  // Add model path to data path
226  if(!data_path.empty())
227  {
228  data_path += "/cnn_data/ssd_mobilenet_model/";
229  }
230 
231  graph << InputLayer(input_descriptor,
232  get_input_accessor(common_params, std::move(preprocessor)));
233 
234  SubStream conv_11(graph);
235  conv_11 << ConvolutionLayer(
236  3U, 3U, 32U,
237  get_weights_accessor(data_path, "conv0_w.npy"),
238  std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
239  PadStrideInfo(2, 2, 1, 1))
240  .set_name("conv0");
241  conv_11 << BatchNormalizationLayer(get_weights_accessor(data_path, "conv0_bn_mean.npy"),
242  get_weights_accessor(data_path, "conv0_bn_var.npy"),
243  get_weights_accessor(data_path, "conv0_scale_w.npy"),
244  get_weights_accessor(data_path, "conv0_scale_b.npy"), 0.00001f)
245  .set_name("conv0/bn")
247 
248  conv_11 << get_node_A_float(conv_11, data_path, "conv1", 64, PadStrideInfo(1, 1, 1, 1), PadStrideInfo(1, 1, 0, 0));
249  conv_11 << get_node_A_float(conv_11, data_path, "conv2", 128, PadStrideInfo(2, 2, 1, 1), PadStrideInfo(1, 1, 0, 0));
250  conv_11 << get_node_A_float(conv_11, data_path, "conv3", 128, PadStrideInfo(1, 1, 1, 1), PadStrideInfo(1, 1, 0, 0));
251  conv_11 << get_node_A_float(conv_11, data_path, "conv4", 256, PadStrideInfo(2, 2, 1, 1), PadStrideInfo(1, 1, 0, 0));
252  conv_11 << get_node_A_float(conv_11, data_path, "conv5", 256, PadStrideInfo(1, 1, 1, 1), PadStrideInfo(1, 1, 0, 0));
253  conv_11 << get_node_A_float(conv_11, data_path, "conv6", 512, PadStrideInfo(2, 2, 1, 1), PadStrideInfo(1, 1, 0, 0));
254  conv_11 << get_node_A_float(conv_11, data_path, "conv7", 512, PadStrideInfo(1, 1, 1, 1), PadStrideInfo(1, 1, 0, 0));
255  conv_11 << get_node_A_float(conv_11, data_path, "conv8", 512, PadStrideInfo(1, 1, 1, 1), PadStrideInfo(1, 1, 0, 0));
256  conv_11 << get_node_A_float(conv_11, data_path, "conv9", 512, PadStrideInfo(1, 1, 1, 1), PadStrideInfo(1, 1, 0, 0));
257  conv_11 << get_node_A_float(conv_11, data_path, "conv10", 512, PadStrideInfo(1, 1, 1, 1), PadStrideInfo(1, 1, 0, 0));
258  conv_11 << get_node_A_float(conv_11, data_path, "conv11", 512, PadStrideInfo(1, 1, 1, 1), PadStrideInfo(1, 1, 0, 0));
259 
260  SubStream conv_13(conv_11);
261  conv_13 << get_node_A_float(conv_11, data_path, "conv12", 1024, PadStrideInfo(2, 2, 1, 1), PadStrideInfo(1, 1, 0, 0));
262  conv_13 << get_node_A_float(conv_13, data_path, "conv13", 1024, PadStrideInfo(1, 1, 1, 1), PadStrideInfo(1, 1, 0, 0));
263 
264  SubStream conv_14(conv_13);
265  conv_14 << get_node_B_float(conv_13, data_path, "conv14", 512, PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 2, 1, 1));
266 
267  SubStream conv_15(conv_14);
268  conv_15 << get_node_B_float(conv_14, data_path, "conv15", 256, PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 2, 1, 1));
269 
270  SubStream conv_16(conv_15);
271  conv_16 << get_node_B_float(conv_15, data_path, "conv16", 256, PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 2, 1, 1));
272 
273  SubStream conv_17(conv_16);
274  conv_17 << get_node_B_float(conv_16, data_path, "conv17", 128, PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 2, 1, 1));
275 
276  //mbox_loc
277  SubStream conv_11_mbox_loc(conv_11);
278  conv_11_mbox_loc << get_node_C_float(conv_11, data_path, "conv11_mbox_loc", 12, PadStrideInfo(1, 1, 0, 0));
279 
280  SubStream conv_13_mbox_loc(conv_13);
281  conv_13_mbox_loc << get_node_C_float(conv_13, data_path, "conv13_mbox_loc", 24, PadStrideInfo(1, 1, 0, 0));
282 
283  SubStream conv_14_2_mbox_loc(conv_14);
284  conv_14_2_mbox_loc << get_node_C_float(conv_14, data_path, "conv14_2_mbox_loc", 24, PadStrideInfo(1, 1, 0, 0));
285 
286  SubStream conv_15_2_mbox_loc(conv_15);
287  conv_15_2_mbox_loc << get_node_C_float(conv_15, data_path, "conv15_2_mbox_loc", 24, PadStrideInfo(1, 1, 0, 0));
288 
289  SubStream conv_16_2_mbox_loc(conv_16);
290  conv_16_2_mbox_loc << get_node_C_float(conv_16, data_path, "conv16_2_mbox_loc", 24, PadStrideInfo(1, 1, 0, 0));
291 
292  SubStream conv_17_2_mbox_loc(conv_17);
293  conv_17_2_mbox_loc << get_node_C_float(conv_17, data_path, "conv17_2_mbox_loc", 24, PadStrideInfo(1, 1, 0, 0));
294 
295  SubStream mbox_loc(graph);
296  mbox_loc << ConcatLayer(std::move(conv_11_mbox_loc), std::move(conv_13_mbox_loc), conv_14_2_mbox_loc, std::move(conv_15_2_mbox_loc),
297  std::move(conv_16_2_mbox_loc), std::move(conv_17_2_mbox_loc));
298 
299  //mbox_conf
300  SubStream conv_11_mbox_conf(conv_11);
301  conv_11_mbox_conf << get_node_C_float(conv_11, data_path, "conv11_mbox_conf", 63, PadStrideInfo(1, 1, 0, 0));
302 
303  SubStream conv_13_mbox_conf(conv_13);
304  conv_13_mbox_conf << get_node_C_float(conv_13, data_path, "conv13_mbox_conf", 126, PadStrideInfo(1, 1, 0, 0));
305 
306  SubStream conv_14_2_mbox_conf(conv_14);
307  conv_14_2_mbox_conf << get_node_C_float(conv_14, data_path, "conv14_2_mbox_conf", 126, PadStrideInfo(1, 1, 0, 0));
308 
309  SubStream conv_15_2_mbox_conf(conv_15);
310  conv_15_2_mbox_conf << get_node_C_float(conv_15, data_path, "conv15_2_mbox_conf", 126, PadStrideInfo(1, 1, 0, 0));
311 
312  SubStream conv_16_2_mbox_conf(conv_16);
313  conv_16_2_mbox_conf << get_node_C_float(conv_16, data_path, "conv16_2_mbox_conf", 126, PadStrideInfo(1, 1, 0, 0));
314 
315  SubStream conv_17_2_mbox_conf(conv_17);
316  conv_17_2_mbox_conf << get_node_C_float(conv_17, data_path, "conv17_2_mbox_conf", 126, PadStrideInfo(1, 1, 0, 0));
317 
318  SubStream mbox_conf(graph);
319  mbox_conf << ConcatLayer(std::move(conv_11_mbox_conf), std::move(conv_13_mbox_conf), std::move(conv_14_2_mbox_conf),
320  std::move(conv_15_2_mbox_conf), std::move(conv_16_2_mbox_conf), std::move(conv_17_2_mbox_conf));
321  mbox_conf << ReshapeLayer(TensorShape(21U, 1917U)).set_name("mbox_conf/reshape");
322  mbox_conf << SoftmaxLayer().set_name("mbox_conf/softmax");
323  mbox_conf << FlattenLayer().set_name("mbox_conf/flat");
324 
325  const std::vector<float> priorbox_variances = { 0.1f, 0.1f, 0.2f, 0.2f };
326  const float priorbox_offset = 0.5f;
327  const std::vector<float> priorbox_aspect_ratios = { 2.f, 3.f };
328 
329  //mbox_priorbox branch
330  SubStream conv_11_mbox_priorbox(conv_11);
331 
332  conv_11_mbox_priorbox << PriorBoxLayer(SubStream(graph),
333  PriorBoxLayerInfo({ 60.f }, priorbox_variances, priorbox_offset, true, false, {}, { 2.f }))
334  .set_name("conv11/priorbox");
335 
336  SubStream conv_13_mbox_priorbox(conv_13);
337  conv_13_mbox_priorbox << PriorBoxLayer(SubStream(graph),
338  PriorBoxLayerInfo({ 105.f }, priorbox_variances, priorbox_offset, true, false, { 150.f }, priorbox_aspect_ratios))
339  .set_name("conv13/priorbox");
340 
341  SubStream conv_14_2_mbox_priorbox(conv_14);
342  conv_14_2_mbox_priorbox << PriorBoxLayer(SubStream(graph),
343  PriorBoxLayerInfo({ 150.f }, priorbox_variances, priorbox_offset, true, false, { 195.f }, priorbox_aspect_ratios))
344  .set_name("conv14/priorbox");
345 
346  SubStream conv_15_2_mbox_priorbox(conv_15);
347  conv_15_2_mbox_priorbox << PriorBoxLayer(SubStream(graph),
348  PriorBoxLayerInfo({ 195.f }, priorbox_variances, priorbox_offset, true, false, { 240.f }, priorbox_aspect_ratios))
349  .set_name("conv15/priorbox");
350 
351  SubStream conv_16_2_mbox_priorbox(conv_16);
352  conv_16_2_mbox_priorbox << PriorBoxLayer(SubStream(graph),
353  PriorBoxLayerInfo({ 240.f }, priorbox_variances, priorbox_offset, true, false, { 285.f }, priorbox_aspect_ratios))
354  .set_name("conv16/priorbox");
355 
356  SubStream conv_17_2_mbox_priorbox(conv_17);
357  conv_17_2_mbox_priorbox << PriorBoxLayer(SubStream(graph),
358  PriorBoxLayerInfo({ 285.f }, priorbox_variances, priorbox_offset, true, false, { 300.f }, priorbox_aspect_ratios))
359  .set_name("conv17/priorbox");
360 
361  SubStream mbox_priorbox(graph);
362 
363  mbox_priorbox << ConcatLayer(
366  std::move(conv_11_mbox_priorbox), std::move(conv_13_mbox_priorbox), std::move(conv_14_2_mbox_priorbox),
367  std::move(conv_15_2_mbox_priorbox), std::move(conv_16_2_mbox_priorbox), std::move(conv_17_2_mbox_priorbox));
368 
369  const int num_classes = 21;
370  const bool share_location = true;
372  const int keep_top_k = keep_topk_opt->value();
373  const float nms_threshold = 0.45f;
374  const int label_id_background = 0;
375  const float conf_thrs = 0.25f;
376  const int top_k = 100;
377 
378  SubStream detection_ouput(mbox_loc);
379  detection_ouput << DetectionOutputLayer(std::move(mbox_conf), std::move(mbox_priorbox),
380  DetectionOutputLayerInfo(num_classes, share_location, detection_type, keep_top_k, nms_threshold, top_k, label_id_background, conf_thrs));
381  detection_ouput << OutputLayer(get_detection_output_accessor(common_params, { input_descriptor.shape }));
382  }
383 
384  ConcatLayer get_node_A_qasymm(IStream &master_graph, const std::string &data_path, std::string &&param_path,
385  unsigned int conv_filt,
386  PadStrideInfo dwc_pad_stride_info, PadStrideInfo conv_pad_stride_info,
387  std::pair<QuantizationInfo, QuantizationInfo> depth_quant_info, std::pair<QuantizationInfo, QuantizationInfo> point_quant_info)
388  {
389  const std::string total_path = param_path + "_";
390  SubStream sg(master_graph);
391 
393  3U, 3U,
394  get_weights_accessor(data_path, total_path + "dw_w.npy"),
395  get_weights_accessor(data_path, total_path + "dw_b.npy"),
396  dwc_pad_stride_info, 1, depth_quant_info.first, depth_quant_info.second)
397  .set_name(param_path + "/dw")
399 
400  sg << ConvolutionLayer(
401  1U, 1U, conv_filt,
402  get_weights_accessor(data_path, total_path + "w.npy"),
403  get_weights_accessor(data_path, total_path + "b.npy"),
404  conv_pad_stride_info, 1, point_quant_info.first, point_quant_info.second)
405  .set_name(param_path + "/pw")
407 
408  return ConcatLayer(std::move(sg));
409  }
410 
411  ConcatLayer get_node_B_qasymm(IStream &master_graph, const std::string &data_path, std::string &&param_path,
412  unsigned int conv_filt,
413  PadStrideInfo conv_pad_stride_info_1x1, PadStrideInfo conv_pad_stride_info_3x3,
414  const std::pair<QuantizationInfo, QuantizationInfo> quant_info_1x1, const std::pair<QuantizationInfo, QuantizationInfo> quant_info_3x3)
415  {
416  const std::string total_path = param_path + "_";
417  SubStream sg(master_graph);
418 
419  sg << ConvolutionLayer(
420  1, 1, conv_filt / 2,
421  get_weights_accessor(data_path, total_path + "1x1_w.npy"),
422  get_weights_accessor(data_path, total_path + "1x1_b.npy"),
423  conv_pad_stride_info_1x1, 1, quant_info_1x1.first, quant_info_1x1.second)
424  .set_name(total_path + "1x1/conv")
426 
427  sg << ConvolutionLayer(
428  3, 3, conv_filt,
429  get_weights_accessor(data_path, total_path + "3x3_w.npy"),
430  get_weights_accessor(data_path, total_path + "3x3_b.npy"),
431  conv_pad_stride_info_3x3, 1, quant_info_3x3.first, quant_info_3x3.second)
432  .set_name(total_path + "3x3/conv")
434 
435  return ConcatLayer(std::move(sg));
436  }
437 
438  ConcatLayer get_node_C_qasymm(IStream &master_graph, const std::string &data_path, std::string &&param_path,
439  unsigned int conv_filt, PadStrideInfo conv_pad_stride_info,
440  const std::pair<QuantizationInfo, QuantizationInfo> quant_info, TensorShape reshape_shape)
441  {
442  const std::string total_path = param_path + "_";
443  SubStream sg(master_graph);
444  sg << ConvolutionLayer(
445  1U, 1U, conv_filt,
446  get_weights_accessor(data_path, total_path + "w.npy"),
447  get_weights_accessor(data_path, total_path + "b.npy"),
448  conv_pad_stride_info, 1, quant_info.first, quant_info.second)
449  .set_name(param_path + "/conv");
450  if(common_params.data_layout == DataLayout::NCHW)
451  {
452  sg << PermuteLayer(PermutationVector(2U, 0U, 1U), DataLayout::NHWC);
453  }
454  sg << ReshapeLayer(reshape_shape).set_name(param_path + "/reshape");
455 
456  return ConcatLayer(std::move(sg));
457  }
458 
459  void create_graph_qasymm(TensorDescriptor &input_descriptor)
460  {
461  // Get trainable parameters data path
462  std::string data_path = common_params.data_path;
463 
464  // Add model path to data path
465  if(!data_path.empty())
466  {
467  data_path += "/cnn_data/ssd_mobilenet_qasymm8_model/";
468  }
469 
470  // Quantization info are saved as pair for each (pointwise/depthwise) convolution layer: <weight_quant_info, output_quant_info>
471  const std::vector<std::pair<QuantizationInfo, QuantizationInfo>> conv_quant_info =
472  {
473  { QuantizationInfo(0.03624850884079933f, 163), QuantizationInfo(0.22219789028167725f, 113) }, // conv0
474  { QuantizationInfo(0.0028752065263688564f, 113), QuantizationInfo(0.05433657020330429f, 128) }, // conv13_2_1_1
475  { QuantizationInfo(0.0014862528769299388f, 125), QuantizationInfo(0.05037643015384674f, 131) }, // conv13_2_3_3
476  { QuantizationInfo(0.00233650766313076f, 113), QuantizationInfo(0.04468846693634987f, 126) }, // conv13_3_1_1
477  { QuantizationInfo(0.002501056529581547f, 120), QuantizationInfo(0.06026708707213402f, 111) }, // conv13_3_3_3
478  { QuantizationInfo(0.002896666992455721f, 121), QuantizationInfo(0.037775348871946335f, 117) }, // conv13_4_1_1
479  { QuantizationInfo(0.0023875406477600336f, 122), QuantizationInfo(0.03881589323282242f, 108) }, // conv13_4_3_3
480  { QuantizationInfo(0.0022081052884459496f, 77), QuantizationInfo(0.025450613349676132f, 125) }, // conv13_5_1_1
481  { QuantizationInfo(0.00604657270014286f, 121), QuantizationInfo(0.033533502370119095f, 109) } // conv13_5_3_3
482  };
483 
484  const std::vector<std::pair<QuantizationInfo, QuantizationInfo>> depth_quant_info =
485  {
486  { QuantizationInfo(0.03408717364072f, 131), QuantizationInfo(0.29286590218544006f, 108) }, // dwsc1
487  { QuantizationInfo(0.027518004179000854f, 107), QuantizationInfo(0.20796941220760345, 117) }, // dwsc2
488  { QuantizationInfo(0.052489638328552246f, 85), QuantizationInfo(0.4303881824016571f, 142) }, // dwsc3
489  { QuantizationInfo(0.016570359468460083f, 79), QuantizationInfo(0.10512150079011917f, 116) }, // dwsc4
490  { QuantizationInfo(0.060739465057849884f, 65), QuantizationInfo(0.15331414341926575f, 94) }, // dwsc5
491  { QuantizationInfo(0.01324534136801958f, 124), QuantizationInfo(0.13010895252227783f, 153) }, // dwsc6
492  { QuantizationInfo(0.032326459884643555f, 124), QuantizationInfo(0.11565316468477249, 156) }, // dwsc7
493  { QuantizationInfo(0.029948478564620018f, 155), QuantizationInfo(0.11413891613483429f, 146) }, // dwsc8
494  { QuantizationInfo(0.028054025024175644f, 129), QuantizationInfo(0.1142905130982399f, 140) }, // dwsc9
495  { QuantizationInfo(0.025204822421073914f, 129), QuantizationInfo(0.14668069779872894f, 149) }, // dwsc10
496  { QuantizationInfo(0.019332280382514f, 110), QuantizationInfo(0.1480235457420349f, 91) }, // dwsc11
497  { QuantizationInfo(0.0319712869822979f, 88), QuantizationInfo(0.10424695909023285f, 117) }, // dwsc12
498  { QuantizationInfo(0.04378943517804146f, 164), QuantizationInfo(0.23176774382591248f, 138) } // dwsc13
499  };
500 
501  const std::vector<std::pair<QuantizationInfo, QuantizationInfo>> point_quant_info =
502  {
503  { QuantizationInfo(0.028777318075299263f, 144), QuantizationInfo(0.2663874328136444f, 121) }, // pw1
504  { QuantizationInfo(0.015796702355146408f, 127), QuantizationInfo(0.1739964485168457f, 111) }, // pw2
505  { QuantizationInfo(0.009349990636110306f, 127), QuantizationInfo(0.1805974692106247f, 104) }, // pw3
506  { QuantizationInfo(0.012920888140797615f, 106), QuantizationInfo(0.1205204650759697f, 100) }, // pw4
507  { QuantizationInfo(0.008119508624076843f, 145), QuantizationInfo(0.12272439152002335f, 97) }, // pw5
508  { QuantizationInfo(0.0070041813887655735f, 115), QuantizationInfo(0.0947074219584465f, 101) }, // pw6
509  { QuantizationInfo(0.004827278666198254f, 115), QuantizationInfo(0.0842885747551918f, 110) }, // pw7
510  { QuantizationInfo(0.004755120258778334f, 128), QuantizationInfo(0.08283159881830215f, 116) }, // pw8
511  { QuantizationInfo(0.007527193054556847f, 142), QuantizationInfo(0.12555131316184998f, 137) }, // pw9
512  { QuantizationInfo(0.006050156895071268f, 109), QuantizationInfo(0.10871313512325287f, 124) }, // pw10
513  { QuantizationInfo(0.00490700313821435f, 127), QuantizationInfo(0.10364262014627457f, 140) }, // pw11
514  { QuantizationInfo(0.006063731852918863, 124), QuantizationInfo(0.11241862177848816f, 125) }, // pw12
515  { QuantizationInfo(0.007901716977357864f, 139), QuantizationInfo(0.49889302253723145f, 141) } // pw13
516  };
517 
518  // Quantization info taken from the TfLite SSD MobileNet example
519  const QuantizationInfo in_quant_info = QuantizationInfo(0.0078125f, 128);
520  // Create core graph
521  graph << InputLayer(input_descriptor.set_quantization_info(in_quant_info),
522  get_weights_accessor(data_path, common_params.image, DataLayout::NHWC));
523  graph << ConvolutionLayer(
524  3U, 3U, 32U,
525  get_weights_accessor(data_path, "conv0_w.npy"),
526  get_weights_accessor(data_path, "conv0_b.npy"),
527  PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::CEIL), 1, conv_quant_info.at(0).first, conv_quant_info.at(0).second)
528  .set_name("conv0");
530  graph << get_node_A_qasymm(graph, data_path, "conv1", 64U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(0),
531  point_quant_info.at(0));
532  graph << get_node_A_qasymm(graph, data_path, "conv2", 128U, PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::CEIL), PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(1),
533  point_quant_info.at(1));
534  graph << get_node_A_qasymm(graph, data_path, "conv3", 128U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(2),
535  point_quant_info.at(2));
536  graph << get_node_A_qasymm(graph, data_path, "conv4", 256U, PadStrideInfo(2U, 2U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(3),
537  point_quant_info.at(3));
538  graph << get_node_A_qasymm(graph, data_path, "conv5", 256U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(4),
539  point_quant_info.at(4));
540  graph << get_node_A_qasymm(graph, data_path, "conv6", 512U, PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::CEIL), PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(5),
541  point_quant_info.at(5));
542  graph << get_node_A_qasymm(graph, data_path, "conv7", 512U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(6),
543  point_quant_info.at(6));
544  graph << get_node_A_qasymm(graph, data_path, "conv8", 512U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(7),
545  point_quant_info.at(7));
546  graph << get_node_A_qasymm(graph, data_path, "conv9", 512U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(8),
547  point_quant_info.at(8));
548  graph << get_node_A_qasymm(graph, data_path, "conv10", 512U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(9),
549  point_quant_info.at(9));
550  graph << get_node_A_qasymm(graph, data_path, "conv11", 512U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(10),
551  point_quant_info.at(10));
552 
553  SubStream conv_13(graph);
554  conv_13 << get_node_A_qasymm(graph, data_path, "conv12", 1024U, PadStrideInfo(2U, 2U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(11),
555  point_quant_info.at(11));
556  conv_13 << get_node_A_qasymm(conv_13, data_path, "conv13", 1024U, PadStrideInfo(1U, 1U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), PadStrideInfo(1U, 1U, 0U, 0U), depth_quant_info.at(12),
557  point_quant_info.at(12));
558  SubStream conv_14(conv_13);
559  conv_14 << get_node_B_qasymm(conv_13, data_path, "conv13_2", 512U, PadStrideInfo(1U, 1U, 0U, 0U), PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::CEIL), conv_quant_info.at(1),
560  conv_quant_info.at(2));
561  SubStream conv_15(conv_14);
562  conv_15 << get_node_B_qasymm(conv_14, data_path, "conv13_3", 256U, PadStrideInfo(1U, 1U, 0U, 0U), PadStrideInfo(2U, 2U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), conv_quant_info.at(3),
563  conv_quant_info.at(4));
564  SubStream conv_16(conv_15);
565  conv_16 << get_node_B_qasymm(conv_15, data_path, "conv13_4", 256U, PadStrideInfo(1U, 1U, 0U, 0U), PadStrideInfo(2U, 2U, 1U, 1U, 1U, 1U, DimensionRoundingType::CEIL), conv_quant_info.at(5),
566  conv_quant_info.at(6));
567  SubStream conv_17(conv_16);
568  conv_17 << get_node_B_qasymm(conv_16, data_path, "conv13_5", 128U, PadStrideInfo(1U, 1U, 0U, 0U), PadStrideInfo(2U, 2U, 0U, 1U, 0U, 1U, DimensionRoundingType::CEIL), conv_quant_info.at(7),
569  conv_quant_info.at(8));
570 
571  // box_predictor
572  const std::vector<std::pair<QuantizationInfo, QuantizationInfo>> box_enc_pred_quant_info =
573  {
574  { QuantizationInfo(0.005202020984143019f, 136), QuantizationInfo(0.08655580133199692f, 183) }, // boxpredictor0_bep
575  { QuantizationInfo(0.003121797926723957f, 132), QuantizationInfo(0.03218776360154152f, 140) }, // boxpredictor1_bep
576  { QuantizationInfo(0.002995674265548587f, 130), QuantizationInfo(0.029072262346744537f, 125) }, // boxpredictor2_bep
577  { QuantizationInfo(0.0023131705820560455f, 130), QuantizationInfo(0.026488754898309708f, 127) }, // boxpredictor3_bep
578  { QuantizationInfo(0.0013905081432312727f, 132), QuantizationInfo(0.0199890099465847f, 137) }, // boxpredictor4_bep
579  { QuantizationInfo(0.00216794665902853f, 121), QuantizationInfo(0.019798893481492996f, 151) } // boxpredictor5_bep
580  };
581 
582  const std::vector<TensorShape> box_reshape = // NHWC
583  {
584  TensorShape(4U, 1U, 1083U), // boxpredictor0_bep_reshape
585  TensorShape(4U, 1U, 600U), // boxpredictor1_bep_reshape
586  TensorShape(4U, 1U, 150U), // boxpredictor2_bep_reshape
587  TensorShape(4U, 1U, 54U), // boxpredictor3_bep_reshape
588  TensorShape(4U, 1U, 24U), // boxpredictor4_bep_reshape
589  TensorShape(4U, 1U, 6U) // boxpredictor5_bep_reshape
590  };
591 
592  SubStream conv_11_box_enc_pre(graph);
593  conv_11_box_enc_pre << get_node_C_qasymm(graph, data_path, "BoxPredictor_0_BEP", 12U, PadStrideInfo(1U, 1U, 0U, 0U), box_enc_pred_quant_info.at(0), box_reshape.at(0));
594 
595  SubStream conv_13_box_enc_pre(conv_13);
596  conv_13_box_enc_pre << get_node_C_qasymm(conv_13, data_path, "BoxPredictor_1_BEP", 24U, PadStrideInfo(1U, 1U, 0U, 0U), box_enc_pred_quant_info.at(1), box_reshape.at(1));
597 
598  SubStream conv_14_2_box_enc_pre(conv_14);
599  conv_14_2_box_enc_pre << get_node_C_qasymm(conv_14, data_path, "BoxPredictor_2_BEP", 24U, PadStrideInfo(1U, 1U, 0U, 0U), box_enc_pred_quant_info.at(2), box_reshape.at(2));
600 
601  SubStream conv_15_2_box_enc_pre(conv_15);
602  conv_15_2_box_enc_pre << get_node_C_qasymm(conv_15, data_path, "BoxPredictor_3_BEP", 24U, PadStrideInfo(1U, 1U, 0U, 0U), box_enc_pred_quant_info.at(3), box_reshape.at(3));
603 
604  SubStream conv_16_2_box_enc_pre(conv_16);
605  conv_16_2_box_enc_pre << get_node_C_qasymm(conv_16, data_path, "BoxPredictor_4_BEP", 24U, PadStrideInfo(1U, 1U, 0U, 0U), box_enc_pred_quant_info.at(4), box_reshape.at(4));
606 
607  SubStream conv_17_2_box_enc_pre(conv_17);
608  conv_17_2_box_enc_pre << get_node_C_qasymm(conv_17, data_path, "BoxPredictor_5_BEP", 24U, PadStrideInfo(1U, 1U, 0U, 0U), box_enc_pred_quant_info.at(5), box_reshape.at(5));
609 
610  SubStream box_enc_pre(graph);
611  const QuantizationInfo bep_concate_qinfo = QuantizationInfo(0.08655580133199692f, 183);
613  std::move(conv_11_box_enc_pre), std::move(conv_13_box_enc_pre), conv_14_2_box_enc_pre, std::move(conv_15_2_box_enc_pre),
614  std::move(conv_16_2_box_enc_pre), std::move(conv_17_2_box_enc_pre))
615  .set_name("BoxPredictor/concat");
616  box_enc_pre << ReshapeLayer(TensorShape(4U, 1917U)).set_name("BoxPredictor/reshape");
617 
618  // class_predictor
619  const std::vector<std::pair<QuantizationInfo, QuantizationInfo>> class_pred_quant_info =
620  {
621  { QuantizationInfo(0.002744135679677129f, 125), QuantizationInfo(0.05746262148022652f, 234) }, // boxpredictor0_cp
622  { QuantizationInfo(0.0024326108396053314f, 80), QuantizationInfo(0.03764628246426582f, 217) }, // boxpredictor1_cp
623  { QuantizationInfo(0.0013898586621508002f, 141), QuantizationInfo(0.034081317484378815f, 214) }, // boxpredictor2_cp
624  { QuantizationInfo(0.0014176908880472183f, 133), QuantizationInfo(0.033889178186655045f, 215) }, // boxpredictor3_cp
625  { QuantizationInfo(0.001090311910957098f, 125), QuantizationInfo(0.02646234817802906f, 230) }, // boxpredictor4_cp
626  { QuantizationInfo(0.001134163816459477f, 115), QuantizationInfo(0.026926767081022263f, 218) } // boxpredictor5_cp
627  };
628 
629  const std::vector<TensorShape> class_reshape =
630  {
631  TensorShape(91U, 1083U), // boxpredictor0_cp_reshape
632  TensorShape(91U, 600U), // boxpredictor1_cp_reshape
633  TensorShape(91U, 150U), // boxpredictor2_cp_reshape
634  TensorShape(91U, 54U), // boxpredictor3_cp_reshape
635  TensorShape(91U, 24U), // boxpredictor4_cp_reshape
636  TensorShape(91U, 6U) // boxpredictor5_cp_reshape
637  };
638 
639  SubStream conv_11_class_pre(graph);
640  conv_11_class_pre << get_node_C_qasymm(graph, data_path, "BoxPredictor_0_CP", 273U, PadStrideInfo(1U, 1U, 0U, 0U), class_pred_quant_info.at(0), class_reshape.at(0));
641 
642  SubStream conv_13_class_pre(conv_13);
643  conv_13_class_pre << get_node_C_qasymm(conv_13, data_path, "BoxPredictor_1_CP", 546U, PadStrideInfo(1U, 1U, 0U, 0U), class_pred_quant_info.at(1), class_reshape.at(1));
644 
645  SubStream conv_14_2_class_pre(conv_14);
646  conv_14_2_class_pre << get_node_C_qasymm(conv_14, data_path, "BoxPredictor_2_CP", 546U, PadStrideInfo(1U, 1U, 0U, 0U), class_pred_quant_info.at(2), class_reshape.at(2));
647 
648  SubStream conv_15_2_class_pre(conv_15);
649  conv_15_2_class_pre << get_node_C_qasymm(conv_15, data_path, "BoxPredictor_3_CP", 546U, PadStrideInfo(1U, 1U, 0U, 0U), class_pred_quant_info.at(3), class_reshape.at(3));
650 
651  SubStream conv_16_2_class_pre(conv_16);
652  conv_16_2_class_pre << get_node_C_qasymm(conv_16, data_path, "BoxPredictor_4_CP", 546U, PadStrideInfo(1U, 1U, 0U, 0U), class_pred_quant_info.at(4), class_reshape.at(4));
653 
654  SubStream conv_17_2_class_pre(conv_17);
655  conv_17_2_class_pre << get_node_C_qasymm(conv_17, data_path, "BoxPredictor_5_CP", 546U, PadStrideInfo(1U, 1U, 0U, 0U), class_pred_quant_info.at(5), class_reshape.at(5));
656 
657  const QuantizationInfo cp_concate_qinfo = QuantizationInfo(0.0584389753639698f, 230);
658  SubStream class_pred(graph);
659  class_pred << ConcatLayer(
661  std::move(conv_11_class_pre), std::move(conv_13_class_pre), std::move(conv_14_2_class_pre),
662  std::move(conv_15_2_class_pre), std::move(conv_16_2_class_pre), std::move(conv_17_2_class_pre))
663  .set_name("ClassPrediction/concat");
664 
665  const QuantizationInfo logistic_out_qinfo = QuantizationInfo(0.00390625f, 0);
666  class_pred << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC), logistic_out_qinfo).set_name("ClassPrediction/logistic");
667 
668  const int max_detections = 10;
669  const int max_classes_per_detection = 1;
670  const float nms_score_threshold = 0.30000001192092896f;
671  const float nms_iou_threshold = 0.6000000238418579f;
672  const int num_classes = 90;
673  const float x_scale = 10.f;
674  const float y_scale = 10.f;
675  const float h_scale = 5.f;
676  const float w_scale = 5.f;
677  std::array<float, 4> scales = { y_scale, x_scale, w_scale, h_scale };
678  const QuantizationInfo anchors_qinfo = QuantizationInfo(0.006453060545027256f, 0);
679 
680  SubStream detection_ouput(box_enc_pre);
681  detection_ouput << DetectionPostProcessLayer(std::move(class_pred),
682  DetectionPostProcessLayerInfo(max_detections, max_classes_per_detection, nms_score_threshold, nms_iou_threshold, num_classes, scales),
683  get_weights_accessor(data_path, "anchors.npy"), anchors_qinfo)
684  .set_name("DetectionPostProcess");
685 
686  SubStream ouput_0(detection_ouput);
687  ouput_0 << OutputLayer(get_npy_output_accessor(detection_boxes_opt->value(), TensorShape(4U, 10U), DataType::F32), 0);
688 
689  SubStream ouput_1(detection_ouput);
690  ouput_1 << OutputLayer(get_npy_output_accessor(detection_classes_opt->value(), TensorShape(10U), DataType::F32), 1);
691 
692  SubStream ouput_2(detection_ouput);
693  ouput_2 << OutputLayer(get_npy_output_accessor(detection_scores_opt->value(), TensorShape(10U), DataType::F32), 2);
694 
695  SubStream ouput_3(detection_ouput);
696  ouput_3 << OutputLayer(get_npy_output_accessor(num_detections_opt->value(), TensorShape(1U), DataType::F32), 3);
697  }
698 };
699 
700 /** Main program for MobileNetSSD
701  *
702  * Model is based on:
703  * http://arxiv.org/abs/1512.02325
704  * SSD: Single Shot MultiBox Detector
705  * Wei Liu, Dragomir Anguelov, Dumitru Erhan, Christian Szegedy, Scott Reed, Cheng-Yang Fu, Alexander C. Berg
706  *
707  * Provenance: https://github.com/chuanqi305/MobileNet-SSD
708  *
709  * @note To list all the possible arguments execute the binary appended with the --help option
710  *
711  * @param[in] argc Number of arguments
712  * @param[in] argv Arguments
713  */
714 int main(int argc, char **argv)
715 {
716  return arm_compute::utils::run_example<GraphSSDMobilenetExample>(argc, argv);
717 }
Graph configuration structure Device target types.
Definition: Types.h:80
Shape of a tensor.
Definition: TensorShape.h:39
std::unique_ptr< graph::ITensorAccessor > get_input_accessor(const arm_compute::utils::CommonGraphParams &graph_parameters, std::unique_ptr< IPreprocessor > preprocessor=nullptr, bool bgr=true)
Generates appropriate input accessor according to the specified graph parameters. ...
Definition: GraphUtils.h:497
std::unique_ptr< graph::ITensorAccessor > get_detection_output_accessor(const arm_compute::utils::CommonGraphParams &graph_parameters, std::vector< TensorShape > tensor_shapes, bool is_validation=false, std::ostream &output_stream=std::cout)
Generates appropriate output accessor according to the specified graph parameters.
Definition: GraphUtils.h:577
1 channel, 1 F32 per channel
Strides PermutationVector
Permutation vector.
Definition: Types.h:49
void consume_common_graph_parameters(CommonGraphValidateOptions &options, CommonParams &common_params)
Consumes the consume_common_graph_parameters graph options and creates a structure containing any inf...
Includes all the Graph headers at once.
Common command line options used to configure the graph examples.
std::unique_ptr< graph::ITensorAccessor > get_npy_output_accessor(const std::string &npy_path, TensorShape shape, DataType data_type, DataLayout data_layout=DataLayout::NCHW, std::ostream &output_stream=std::cout)
Generates appropriate npy output accessor according to the specified npy_path.
Definition: GraphUtils.h:611
Class to parse command line arguments.
DetectionOutputLayerCodeType
Available Detection Output code types.
Definition: Types.h:967
Activation Layer Information class.
Definition: Types.h:1550
Copyright (c) 2017-2021 Arm Limited.
std::string mlgo_file
Filename to load MLGO heuristics from.
Definition: Types.h:90
int main(int argc, char **argv)
Main program for MobileNetSSD.
std::string tuner_file
File to load/store tuning values from.
Definition: Types.h:89
Quantization information.
DetectionOutputPostProcess Layer.
Definition: Layers.h:608
Abstract Example class.
Definition: Utils.h:78
PriorBox layer info.
Definition: Types.h:839
Padding and stride information class.
Definition: Types.h:722
TensorDescriptor & set_quantization_info(QuantizationInfo tensor_quant_info)
Sets tensor descriptor quantization info.
Num samples, channels, height, width.
TensorShape permute_shape(TensorShape tensor_shape, DataLayout in_data_layout, DataLayout out_data_layout)
Permutes a given tensor shape given the input and output data layout.
Definition: GraphUtils.h:664
TensorDescriptor & set_layout(DataLayout data_layout)
Sets tensor descriptor data layout.
Detection Output layer info.
Definition: Types.h:976
Structure holding all the common graph parameters.
Num samples, height, width, channels.
bool use_tuner
Use a tuner in tunable backends.
Definition: Types.h:85
std::unique_ptr< graph::ITensorAccessor > get_weights_accessor(const std::string &path, const std::string &data_file, DataLayout file_layout=DataLayout::NCHW)
Generates appropriate weights accessor according to the specified path.
Definition: GraphUtils.h:475
Detection Output layer info.
Definition: Types.h:1095
int num_threads
Number of threads to use (thread capable backends), if 0 the backend will auto-initialize, if -1 the backend will stay as it is.
Definition: Types.h:88
Stream frontend class to construct simple graphs in a stream fashion.
Definition: Stream.h:45
ILayer & set_name(std::string name)
Sets the name of the layer.
Definition: ILayer.h:55
void set_help(std::string help)
Set the help message for the option.
Definition: Option.h:125
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
Definition: Utils.h:1148