Compute Library
 21.05
GraphBuilder.h
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 #ifndef ARM_COMPUTE_GRAPH_GRAPH_BUILDER_H
25 #define ARM_COMPUTE_GRAPH_GRAPH_BUILDER_H
26 
30 
31 namespace arm_compute
32 {
33 namespace graph
34 {
35 // Forward declaration
36 class Graph;
37 
38 /** Graph builder class
39  *
40  * Builds and compiles a graph
41  */
42 class GraphBuilder final
43 {
44 public:
45  /** Adds a Const node to the graph
46  *
47  * @param[in] g Graph to add the node to
48  * @param[in] params Common node parameters
49  * @param[in] desc Tensor descriptor of the node
50  * @param[in] accessor (Optional) Accessor of the const node data
51  *
52  * @return Node ID of the created node, EmptyNodeID in case of error
53  */
54  static NodeID add_const_node(Graph &g, NodeParams params, const TensorDescriptor &desc, ITensorAccessorUPtr accessor = nullptr);
55  /** Adds an input layer node to the graph
56  *
57  * @param[in] g Graph to add the node to
58  * @param[in] params Common node parameters
59  * @param[in] desc Tensor descriptor of the Tensor
60  * @param[in] accessor (Optional) Accessor of the input node data
61  *
62  * @return Node ID of the created node, EmptyNodeID in case of error
63  */
64  static NodeID add_input_node(Graph &g, NodeParams params, const TensorDescriptor &desc, ITensorAccessorUPtr accessor = nullptr);
65  /** Adds an output layer node to the graph
66  *
67  * @param[in] g Graph to add the node to
68  * @param[in] params Common node parameters
69  * @param[in] input Input to the output node as a NodeID-Index pair
70  * @param[in] accessor (Optional) Accessor of the output node data
71  *
72  * @return Node ID of the created node, EmptyNodeID in case of error
73  */
74  static NodeID add_output_node(Graph &g, NodeParams params, NodeIdxPair input, ITensorAccessorUPtr accessor = nullptr);
75  /** Adds an activation layer node to the graph
76  *
77  * @param[in] g Graph to add the node to
78  * @param[in] params Common node parameters
79  * @param[in] input Input to the activation layer node as a NodeID-Index pair
80  * @param[in] act_info Activation layer information
81  * @param[in] out_quant_info (Optional) Output quantization info
82  *
83  * @return Node ID of the created node, EmptyNodeID in case of error
84  */
86  const QuantizationInfo &out_quant_info = QuantizationInfo());
87  /** Adds an activation layer node to the graph
88  *
89  * @param[in] g Graph to add the node to
90  * @param[in] params Common node parameters
91  * @param[in] input Input to the activation layer node as a NodeID-Index pair
92  * @param[in] op Reduction Operation: min or max
93  * @param[in] axis Axis to perform reduction operation across
94  * @param[in] out_data_type (Optional) Output data type
95  * @param[in] out_quant_info (Optional) Output quantization info
96  *
97  * @return Node ID of the created node, EmptyNodeID in case of error
98  */
99  static NodeID add_arg_min_max_node(Graph &g, NodeParams params, NodeIdxPair input, ReductionOperation op, unsigned int axis,
100  DataType out_data_type = DataType::UNKNOWN,
101  const QuantizationInfo &out_quant_info = QuantizationInfo());
102  /** Adds a batch normalization layer node to the graph
103  *
104  * @param[in] g Graph to add the node to
105  * @param[in] params Common node parameters
106  * @param[in] input Input to the batch normalization layer node as a NodeID-Index pair
107  * @param[in] epsilon Epsilon parameter
108  * @param[in] mean_accessor Const Node ID that contains the mean values
109  * @param[in] var_accessor Const Node ID that contains the variance values
110  * @param[in] beta_accessor Const Node ID that contains the beta values. Can be EmptyNodeID
111  * @param[in] gamma_accessor Const Node ID that contains the gamma values. Can be EmptyNodeID
112  *
113  * @return Node ID of the created node, EmptyNodeID in case of error
114  */
116  ITensorAccessorUPtr mean_accessor = nullptr, ITensorAccessorUPtr var_accessor = nullptr,
117  ITensorAccessorUPtr beta_accessor = nullptr, ITensorAccessorUPtr gamma_accessor = nullptr);
118  /** Adds a bounding box transform layer node to the graph
119  *
120  * @param[in] g Graph to add the node to
121  * @param[in] params Common node parameters
122  * @param[in] input Input to the bounding box transform layer node as a NodeID-Index pair
123  * @param[in] deltas Deltas input to the bounding box transform layer node as a NodeID-Index pair
124  * @param[in] info Bounding Box Transform information
125  *
126  * @return Node ID of the created node, EmptyNodeID in case of error
127  */
129  /** Adds an channel shuffle layer node to the graph
130  *
131  * @param[in] g Graph to add the node to
132  * @param[in] params Common node parameters
133  * @param[in] input Input to the activation layer node as a NodeID-Index pair
134  * @param[in] num_groups Number of groups
135  *
136  * @return Node ID of the created node, EmptyNodeID in case of error
137  */
138  static NodeID add_channel_shuffle_node(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_groups);
139  /** Adds a convolution layer node to the graph
140  *
141  * @param[in] g Graph to add the node to
142  * @param[in] params Common node parameters
143  * @param[in] input Input to the convolution layer node as a NodeID-Index pair
144  * @param[in] kernel_spatial_extend Spatial extend of convolution kernels
145  * @param[in] depth Number of convolution kernels
146  * @param[in] conv_info Convolution layer information
147  * @param[in] num_groups (Optional) Number of groups for a grouped convolution. Defaults to 1
148  * @param[in] method (Optional) Convolution method to use
149  * @param[in] fast_math_hint (Optional) Fast math hint
150  * @param[in] weights_accessor (Optional) Accessor of the weights node data
151  * @param[in] bias_accessor (Optional) Accessor of the bias node data
152  * @param[in] weights_quant_info (Optional) Weights quantization info
153  * @param[in] out_quant_info (Optional) Output quantization info
154  *
155  * @return Node ID of the created node, EmptyNodeID in case of error
156  */
158  Size2D kernel_spatial_extend, unsigned int depth, PadStrideInfo conv_info, unsigned int num_groups = 1,
160  ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr,
161  const QuantizationInfo &weights_quant_info = QuantizationInfo(),
162  const QuantizationInfo &out_quant_info = QuantizationInfo());
163  /** Adds a deconvolution layer node to the graph
164  *
165  * @param[in] g Graph to add the node to
166  * @param[in] params Common node parameters
167  * @param[in] input Input to the convolution layer node as a NodeID-Index pair
168  * @param[in] kernel_spatial_extend Spatial extend of convolution kernels
169  * @param[in] depth Number of convolution kernels
170  * @param[in] deconv_info Convolution layer information
171  * @param[in] weights_accessor (Optional) Accessor of the weights node data
172  * @param[in] bias_accessor (Optional) Accessor of the bias node data
173  *
174  * @return Node ID of the created node, EmptyNodeID in case of error
175  */
177  Size2D kernel_spatial_extend, unsigned int depth, PadStrideInfo deconv_info,
178  ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr);
179  /** Adds a depth concatenate node to the graph
180  *
181  * @param[in] g Graph to add the node to
182  * @param[in] params Common node parameters
183  * @param[in] inputs Inputs to the concatenate layer node as a NodeID-Index pair
184  * @param[in] concat_descriptor Concatenation layer descriptor
185  *
186  * @return Node ID of the created node, EmptyNodeID in case of error
187  */
188  static NodeID add_concatenate_node(Graph &g, NodeParams params, const std::vector<NodeIdxPair> &inputs, const descriptors::ConcatLayerDescriptor &concat_descriptor);
189  /** Adds an depth to space layer node to the graph
190  *
191  * @param[in] g Graph to add the node to
192  * @param[in] params Common node parameters
193  * @param[in] input Input to the depth to space layer node as a NodeID-Index pair
194  * @param[in] block_shape Block shape to reshape tensor with
195  *
196  * @return Node ID of the created node, EmptyNodeID in case of error
197  */
198  static NodeID add_depth_to_space_node(Graph &g, NodeParams params, NodeIdxPair input, int32_t block_shape);
199  /** Adds a depth-wise convolution layer node to the graph
200  *
201  * @param[in] g Graph to add the node to
202  * @param[in] params Common node parameters
203  * @param[in] input Input to the depthwise convolution layer node as a NodeID-Index pair
204  * @param[in] kernel_spatial_extend Spatial extend of convolution kernels
205  * @param[in] conv_info Convolution layer information
206  * @param[in] depth_multiplier (Optional) Depth multiplier parameter.
207  * @param[in] method (Optional) Convolution method to use
208  * @param[in] weights_accessor (Optional) Accessor of the weights node data
209  * @param[in] bias_accessor (Optional) Accessor of the bias node data
210  * @param[in] quant_info (Optional) Weights quantization info
211  * @param[in] out_quant_info (Optional) Output quantization info
212  *
213  * @return Node ID of the created node, EmptyNodeID in case of error
214  */
216  Size2D kernel_spatial_extend, PadStrideInfo conv_info, int depth_multiplier = 1,
218  ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr, const QuantizationInfo &quant_info = QuantizationInfo(),
219  const QuantizationInfo &out_quant_info = QuantizationInfo());
220  /** Adds an element-wise layer node to the graph
221  *
222  * @param[in] g Graph to add the node to
223  * @param[in] params Common node parameters
224  * @param[in] input0 First input to the element-wise operation layer node as a NodeID-Index pair
225  * @param[in] input1 Second input to the element-wise operation layer node as a NodeID-Index pair
226  * @param[in] operation Element-wise operation to perform
227  *
228  * @return Node ID of the created node, EmptyNodeID in case of error
229  */
230  static NodeID add_elementwise_node(Graph &g, NodeParams params, NodeIdxPair input0, NodeIdxPair input1, EltwiseOperation operation);
231  /** Adds a dequantization node to the graph
232  *
233  * @param[in] g Graph to add the node to
234  * @param[in] params Common node parameters
235  * @param[in] input Input to the dequantization node as a NodeID-Index pair
236  *
237  * @return Node ID of the created node, EmptyNodeID in case of error
238  */
240  /** Adds a detection output layer node to the graph
241  *
242  * @param[in] g Graph to add the node to
243  * @param[in] params Common node parameters
244  * @param[in] input_loc Location input to the detection output layer node as a NodeID-Index pair
245  * @param[in] input_conf Confidence input to the detection output layer node as a NodeID-Index pair
246  * @param[in] input_priorbox PriorBox input to the detection output layer node as a NodeID-Index pair
247  * @param[in] detect_info Detection output layer parameters
248  *
249  * @return Node ID of the created node, EmptyNodeID in case of error
250  */
251  static NodeID add_detection_output_node(Graph &g, NodeParams params, NodeIdxPair input_loc, NodeIdxPair input_conf, NodeIdxPair input_priorbox, const DetectionOutputLayerInfo &detect_info);
252  /** Adds a detection post process layer node to the graph
253  *
254  * @param[in] g Graph to add the node to
255  * @param[in] params Common node parameters
256  * @param[in] input_box_encoding Boxes input to the detection output layer node as a NodeID-Index pair
257  * @param[in] input_class_prediction Class prediction input to the detection output layer node as a NodeID-Index pair
258  * @param[in] detect_info Detection output layer parameters
259  * @param[in] anchors_accessor (Optional) Const Node ID that contains the anchor values
260  * @param[in] anchor_quant_info (Optional) Anchor quantization info
261  *
262  * @return Node ID of the created node, EmptyNodeID in case of error
263  */
264  static NodeID add_detection_post_process_node(Graph &g, NodeParams params, NodeIdxPair input_box_encoding, NodeIdxPair input_class_prediction,
265  const DetectionPostProcessLayerInfo &detect_info, ITensorAccessorUPtr anchors_accessor = nullptr,
266  const QuantizationInfo &anchor_quant_info = QuantizationInfo());
267  /** Adds a Dummy node to the graph
268  *
269  * @note this node if for debugging purposes. Just alters the shape of the graph pipeline as requested.
270  *
271  * @param[in] g Graph to add the node to
272  * @param[in] params Common node parameters
273  * @param[in] input Input to the dummy node as a NodeID-Index pair
274  * @param[in] shape Output shape
275  *
276  * @return Node ID of the created node, EmptyNodeID in case of error
277  */
279  /** Adds a flatten layer node to the graph
280  *
281  * @param[in] g Graph to add the node to
282  * @param[in] params Common node parameters
283  * @param[in] input Input to the flatten layer node as a NodeID-Index pair
284  *
285  * @return Node ID of the created node, EmptyNodeID in case of error
286  */
288  /** Adds a fully connected layer node to the graph
289  *
290  * @param[in] g Graph to add the layer to
291  * @param[in] params Common node parameters
292  * @param[in] input Input to the fully connected layer node as a NodeID-Index pair
293  * @param[in] num_outputs Number of output neurons
294  * @param[in] weights_nid Node ID of the weights node data
295  * @param[in] bias_nid (Optional) Node ID of the bias node data. Defaults to EmptyNodeID
296  * @param[in] fc_info (Optional) Fully connected layer metadata
297  * @param[in] out_quant_info (Optional) Output quantization info
298  *
299  * @return Node ID of the created node, EmptyNodeID in case of error
300  */
301  static NodeID add_fully_connected_layer(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_outputs,
302  NodeID weights_nid, NodeID bias_nid = EmptyNodeID,
304  const QuantizationInfo &out_quant_info = QuantizationInfo());
305  /** Adds a fully connected layer node to the graph
306  *
307  * @param[in] g Graph to add the layer to
308  * @param[in] params Common node parameters
309  * @param[in] input Input to the fully connected layer node as a NodeID-Index pair
310  * @param[in] num_outputs Number of output neurons
311  * @param[in] weights_accessor (Optional) Accessor of the weights node data
312  * @param[in] bias_accessor (Optional) Accessor of the bias node data
313  * @param[in] fc_info (Optional) Fully connected layer metadata
314  * @param[in] weights_quant_info (Optional) Weights quantization info
315  * @param[in] out_quant_info (Optional) Output quantization info
316  *
317  * @return Node ID of the created node, EmptyNodeID in case of error
318  */
319  static NodeID add_fully_connected_layer(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_outputs,
320  ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr,
322  const QuantizationInfo &weights_quant_info = QuantizationInfo(),
323  const QuantizationInfo &out_quant_info = QuantizationInfo());
324  /** Adds a generate proposals layer node to the graph
325  *
326  * @param[in] g Graph to add the layer to
327  * @param[in] params Common node parameters
328  * @param[in] scores Input scores to the generate proposals layer node as a NodeID-Index pair
329  * @param[in] deltas Input deltas to the generate proposals layer node as a NodeID-Index pair
330  * @param[in] anchors Input anchors to the generate proposals layer node as a NodeID-Index pair
331  * @param[in] info Generate proposals operation information
332  *
333  * @return Node ID of the created node, EmptyNodeID in case of error
334  */
335  static NodeID add_generate_proposals_node(Graph &g, NodeParams params, NodeIdxPair scores, NodeIdxPair deltas,
337  /** Adds a L2 Normalize layer node to the graph
338  *
339  * @param[in] g Graph to add the node to
340  * @param[in] params Common node parameters
341  * @param[in] input Input to the normalization layer node as a NodeID-Index pair
342  * @param[in] axis Axis to perform normalization on
343  * @param[in] epsilon Lower bound value for the normalization
344  *
345  * @return Node ID of the created node, EmptyNodeID in case of error
346  */
347  static NodeID add_l2_normalize_node(Graph &g, NodeParams params, NodeIdxPair input, int axis, float epsilon);
348  /** Adds a normalization layer node to the graph
349  *
350  * @param[in] g Graph to add the node to
351  * @param[in] params Common node parameters
352  * @param[in] input Input to the normalization layer node as a NodeID-Index pair
353  * @param[in] norm_info Normalization layer information
354  *
355  * @return Node ID of the created node, EmptyNodeID in case of error
356  */
358  /** Adds a normalize planar YUV layer node to the graph
359  *
360  * @param[in] g Graph to add the node to
361  * @param[in] params Common node parameters
362  * @param[in] input Input to the normalize planar YUV layer node as a NodeID-Index pair
363  * @param[in] mean_accessor Const Node ID that contains the mean values
364  * @param[in] std_accessor Const Node ID that contains the variance values
365  *
366  * @return Node ID of the created node, EmptyNodeID in case of error
367  */
369  ITensorAccessorUPtr mean_accessor = nullptr, ITensorAccessorUPtr std_accessor = nullptr);
370  /** Adds a pad layer node to the graph
371  *
372  * @param[in] g Graph to add the node to
373  * @param[in] params Common node parameters
374  * @param[in] input Input to the reshape layer node as a NodeID-Index pair
375  * @param[in] paddings The padding for each spatial dimension of the input tensor. The pair padding[i]
376  * specifies the front and the end padding in the i-th dimension.
377  * @param[in] pad_value Padding value to be used. Defaults to 0
378  *
379  * @return Node ID of the created node, EmptyNodeID in case of error
380  */
381  static NodeID add_pad_node(Graph &g, NodeParams params, NodeIdxPair input, const PaddingList &paddings, PixelValue pad_value = PixelValue());
382  /** Adds a permute layer node to the graph
383  *
384  * @param[in] g Graph to add the node to
385  * @param[in] params Common node parameters
386  * @param[in] input Input to the reshape layer node as a NodeID-Index pair
387  * @param[in] perm Permutation vector
388  * @param[in] layout (Optional) Data layout to assign to permuted tensor.
389  * If UNKNOWN then the input's layout will be used.
390  *
391  * @return Node ID of the created node, EmptyNodeID in case of error
392  */
394  /** Adds a pooling layer node to the graph
395  *
396  * @param[in] g Graph to add the node to
397  * @param[in] params Common node parameters
398  * @param[in] input Input to the pooling layer node as a NodeID-Index pair
399  * @param[in] pool_info Pooling layer information
400  *
401  * @return Node ID of the created node, EmptyNodeID in case of error
402  */
404  /** Adds a prelu layer node to the graph
405  *
406  * @param[in] g Graph to add the node to
407  * @param[in] params Common node parameters
408  * @param[in] input Input to the PRelu node as a NodeID-Index pair
409  * @param[in] alpha Alpha input to the PRelu node as a NodeID-Index pair
410  *
411  * @return Node ID of the created node, EmptyNodeID in case of error
412  */
414  /** Adds a print layer node to the graph
415  *
416  * @param[in] g Graph to add the node to
417  * @param[in] params Common node parameters
418  * @param[in] input Input to the print layer node as a NodeID-Index pair
419  * @param[in] stream Output stream.
420  * @param[in] format_info (Optional) Format info.
421  * @param[in] transform (Optional) Transformation function to be applied to the input tensor before printing.
422  *
423  * @return Node ID of the created node, EmptyNodeID in case of error
424  */
425  static NodeID add_print_node(Graph &g, NodeParams params, NodeIdxPair input, std::ostream &stream, const IOFormatInfo &format_info = IOFormatInfo(),
426  const std::function<ITensor *(ITensor *)> transform = nullptr);
427  /** Adds a priorbox layer node to the graph
428  *
429  * @param[in] g Graph to add the node to
430  * @param[in] params Common node parameters
431  * @param[in] input0 First input to the priorbox layer node as a NodeID-Index pair
432  * @param[in] input1 Second input to the priorbox layer node as a NodeID-Index pair
433  * @param[in] prior_info PriorBox parameters
434  *
435  * @return Node ID of the created node, EmptyNodeID in case of error
436  */
437  static NodeID add_priorbox_node(Graph &g, NodeParams params, NodeIdxPair input0, NodeIdxPair input1, const PriorBoxLayerInfo &prior_info);
438  /** Adds a quantization layer node to the graph
439  *
440  * @param[in] g Graph to add the node to
441  * @param[in] params Common node parameters
442  * @param[in] input Input to the quantization layer node as a NodeID-Index pair
443  * @param[in] out_quant_info Output quantization info
444  *
445  * @return Node ID of the created node, EmptyNodeID in case of error
446  */
447  static NodeID add_quantization_node(Graph &g, NodeParams params, NodeIdxPair input, const QuantizationInfo &out_quant_info);
448  /** Adds a reduction sum layer node to the graph
449  *
450  * @param[in] g Graph to add the node to
451  * @param[in] params Common node parameters
452  * @param[in] input Input to the reorg layer node as a NodeID-Index pair
453  * @param[in] op Reduction operation
454  * @param[in] axis Reduction axis
455  * @param[in] keep_dims (Optional) Whether to keep the reduced dimension after the operation. Defaults to true.
456  *
457  * @return Node ID of the created node, EmptyNodeID in case of error
458  */
459  static NodeID add_reduction_operation_node(Graph &g, NodeParams params, NodeIdxPair input, ReductionOperation op, int axis, bool keep_dims = true);
460  /** Adds a reorg layer node to the graph
461  *
462  * @param[in] g Graph to add the node to
463  * @param[in] params Common node parameters
464  * @param[in] input Input to the reorg layer node as a NodeID-Index pair
465  * @param[in] stride Stride value to use for reorganizing the values in the output tensor.
466  *
467  * @return Node ID of the created node, EmptyNodeID in case of error
468  */
469  static NodeID add_reorg_node(Graph &g, NodeParams params, NodeIdxPair input, int stride);
470  /** Adds a reshape layer node to the graph
471  *
472  * @param[in] g Graph to add the node to
473  * @param[in] params Common node parameters
474  * @param[in] input Input to the reshape layer node as a NodeID-Index pair
475  * @param[in] shape Output reshaped shape
476  *
477  * @return Node ID of the created node, EmptyNodeID in case of error
478  */
480  /** Adds a resize layer node to the graph
481  *
482  * @param[in] g Graph to add the node to
483  * @param[in] params Common node parameters
484  * @param[in] input Input to the reshape layer node as a NodeID-Index pair
485  * @param[in] policy Interpolation policy
486  * @param[in] width_scale Width scaling factor
487  * @param[in] height_scale Height scaling factor
488  *
489  * @return Node ID of the created node, EmptyNodeID in case of error
490  */
491  static NodeID add_resize_node(Graph &g, NodeParams params, NodeIdxPair input, InterpolationPolicy policy, float width_scale, float height_scale);
492  /** Adds a ROI align layer node to the graph
493  *
494  * @param[in] g Graph to add the node to
495  * @param[in] params Common node parameters
496  * @param[in] input Input to the reshape layer node as a NodeID-Index pair
497  * @param[in] rois Input containing the ROIs.
498  * @param[in] pool_info Contains pooling operation information described in @ref ROIPoolingLayerInfo.
499  *
500  * @return Node ID of the created node, EmptyNodeID in case of error
501  */
503  /** Adds a scale layer node to the graph
504  * This layer computes a product of the input with a scale (read from mul_accessor) and it applies an offset (read from add_accessor).
505  * output = input * mul_w + add_w
506  *
507  * @param[in] g Graph to add the layer to
508  * @param[in] params Common node parameters
509  * @param[in] input Input to the fully connected layer node as a NodeID-Index pair
510  * @param[in] mul_accessor (Optional) Accessor of the mul node data
511  * @param[in] add_accessor (Optional) Accessor of the add node data
512  *
513  * @return Node ID of the created node, EmptyNodeID in case of error
514  */
515  static NodeID add_scale_layer(Graph &g, const NodeParams &params, NodeIdxPair input,
516  ITensorAccessorUPtr mul_accessor = nullptr, ITensorAccessorUPtr add_accessor = nullptr);
517  /** Adds a softmax node to the graph
518  *
519  * @param[in] g Graph to add the node to
520  * @param[in] params Common node parameters
521  * @param[in] input Input to the softmax layer node as a NodeID-Index pair
522  * @param[in] beta Beta parameter
523  *
524  * @return Node ID of the created node, EmptyNodeID in case of error
525  */
526  static NodeID add_softmax_node(Graph &g, NodeParams params, NodeIdxPair input, float beta = 1.f);
527  /** Adds a slice node to the graph
528  *
529  * @param[in] g Graph to add the node to
530  * @param[in] params Common node parameters
531  * @param[in] input Input to the slice layer node as a NodeID-Index pair
532  * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
533  * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
534  *
535  * @return Node ID of the created node, EmptyNodeID in case of error
536  */
537  static NodeID add_slice_node(Graph &g, NodeParams params, NodeIdxPair input, Coordinates &starts, Coordinates &ends);
538  /** Adds a split node to the graph
539  *
540  * @param[in] g Graph to add the node to
541  * @param[in] params Common node parameters
542  * @param[in] input Input to the split layer node as a NodeID-Index pair
543  * @param[in] num_splits Number of different splits
544  * @param[in] axis (Optional) Split axis. Defaults to 0
545  *
546  * @return Node ID of the created node, EmptyNodeID in case of error
547  */
548  static NodeID add_split_node(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_splits, unsigned int axis = 0);
549  /** Adds a stack layer node to the graph
550  *
551  * @param[in] g Graph to add the node to
552  * @param[in] params Common node parameters
553  * @param[in] inputs Inputs to the reorg layer node as a NodeID-Index pair
554  * @param[in] axis Axis along which the input tensors have to be packed
555  *
556  * @return Node ID of the created node, EmptyNodeID in case of error
557  */
558  static NodeID add_stack_node(Graph &g, NodeParams params, const std::vector<NodeIdxPair> &inputs, int axis);
559  /** Adds a strided slice node to the graph
560  *
561  * @param[in] g Graph to add the node to
562  * @param[in] params Common node parameters
563  * @param[in] input Input to the strided slice layer node as a NodeID-Index pair
564  * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
565  * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
566  * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
567  * @param[in] info Contains masks for the starts, ends and strides
568  *
569  * @return Node ID of the created node, EmptyNodeID in case of error
570  */
572  /** Adds a yolo layer to the graph
573  *
574  * @param[in] g Graph to add the node to
575  * @param[in] params Common node parameters
576  * @param[in] input Input to the yolo layer node as a NodeID-Index pair
577  * @param[in] act_info Activation layer parameters
578  *
579  * @return Node ID of the created node, EmptyNodeID in case of error
580  */
582 };
583 } // namespace graph
584 } // namespace arm_compute
585 #endif /* ARM_COMPUTE_GRAPH_GRAPH_BUILDER_H */
static NodeID add_reduction_operation_node(Graph &g, NodeParams params, NodeIdxPair input, ReductionOperation op, int axis, bool keep_dims=true)
Adds a reduction sum layer node to the graph.
Common node parameters.
Definition: Types.h:217
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
static NodeID add_split_node(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_splits, unsigned int axis=0)
Adds a split node to the graph.
InterpolationPolicy
Interpolation method.
Definition: Types.h:392
static NodeID add_quantization_node(Graph &g, NodeParams params, NodeIdxPair input, const QuantizationInfo &out_quant_info)
Adds a quantization layer node to the graph.
static NodeID add_batch_normalization_node(Graph &g, NodeParams params, NodeIdxPair input, float epsilon, ITensorAccessorUPtr mean_accessor=nullptr, ITensorAccessorUPtr var_accessor=nullptr, ITensorAccessorUPtr beta_accessor=nullptr, ITensorAccessorUPtr gamma_accessor=nullptr)
Adds a batch normalization layer node to the graph.
Generate Proposals Information class.
Definition: Types.h:1280
Shape of a tensor.
Definition: TensorShape.h:39
EltwiseOperation
Supported Element-wise operations.
Definition: Types.h:108
static NodeID add_input_node(Graph &g, NodeParams params, const TensorDescriptor &desc, ITensorAccessorUPtr accessor=nullptr)
Adds an input layer node to the graph.
std::vector< PaddingInfo > PaddingList
List of padding information.
Definition: Types.h:434
ReductionOperation
Available reduction operations.
Definition: Types.h:457
static NodeID add_prelu_node(Graph &g, NodeParams params, NodeIdxPair input, NodeIdxPair alpha)
Adds a prelu layer node to the graph.
static NodeID add_resize_node(Graph &g, NodeParams params, NodeIdxPair input, InterpolationPolicy policy, float width_scale, float height_scale)
Adds a resize layer node to the graph.
static NodeID add_activation_node(Graph &g, NodeParams params, NodeIdxPair input, ActivationLayerInfo act_info, const QuantizationInfo &out_quant_info=QuantizationInfo())
Adds an activation layer node to the graph.
static NodeID add_normalization_node(Graph &g, NodeParams params, NodeIdxPair input, NormalizationLayerInfo norm_info)
Adds a normalization layer node to the graph.
static NodeID add_permute_node(Graph &g, NodeParams params, NodeIdxPair input, PermutationVector perm, DataLayout layout=DataLayout::UNKNOWN)
Adds a permute layer node to the graph.
Normalization Layer Information class.
Definition: Types.h:1575
static NodeID add_yolo_node(Graph &g, NodeParams params, NodeIdxPair input, ActivationLayerInfo act_info)
Adds a yolo layer to the graph.
Fully connected layer info.
Definition: Types.h:1541
std::unique_ptr< ITensorAccessor > ITensorAccessorUPtr
static NodeID add_bounding_box_transform_node(Graph &g, NodeParams params, NodeIdxPair input, NodeIdxPair deltas, BoundingBoxTransformInfo info)
Adds a bounding box transform layer node to the graph.
static NodeID add_reshape_node(Graph &g, NodeParams params, NodeIdxPair input, TensorShape shape)
Adds a reshape layer node to the graph.
Activation Layer Information class.
Definition: Types.h:1478
static NodeID add_priorbox_node(Graph &g, NodeParams params, NodeIdxPair input0, NodeIdxPair input1, const PriorBoxLayerInfo &prior_info)
Adds a priorbox layer node to the graph.
Interface for CPU tensor.
Definition: ITensor.h:36
static NodeID add_concatenate_node(Graph &g, NodeParams params, const std::vector< NodeIdxPair > &inputs, const descriptors::ConcatLayerDescriptor &concat_descriptor)
Adds a depth concatenate node to the graph.
static NodeID add_generate_proposals_node(Graph &g, NodeParams params, NodeIdxPair scores, NodeIdxPair deltas, NodeIdxPair anchors, GenerateProposalsInfo info)
Adds a generate proposals layer node to the graph.
static NodeID add_slice_node(Graph &g, NodeParams params, NodeIdxPair input, Coordinates &starts, Coordinates &ends)
Adds a slice node to the graph.
static NodeID add_deconvolution_node(Graph &g, NodeParams params, NodeIdxPair input, Size2D kernel_spatial_extend, unsigned int depth, PadStrideInfo deconv_info, ITensorAccessorUPtr weights_accessor=nullptr, ITensorAccessorUPtr bias_accessor=nullptr)
Adds a deconvolution layer node to the graph.
static NodeID add_convolution_node(Graph &g, NodeParams params, NodeIdxPair input, Size2D kernel_spatial_extend, unsigned int depth, PadStrideInfo conv_info, unsigned int num_groups=1, ConvolutionMethod method=ConvolutionMethod::Default, FastMathHint fast_math_hint=FastMathHint::Disabled, ITensorAccessorUPtr weights_accessor=nullptr, ITensorAccessorUPtr bias_accessor=nullptr, const QuantizationInfo &weights_quant_info=QuantizationInfo(), const QuantizationInfo &out_quant_info=QuantizationInfo())
Adds a convolution layer node to the graph.
static NodeID add_depth_to_space_node(Graph &g, NodeParams params, NodeIdxPair input, int32_t block_shape)
Adds an depth to space layer node to the graph.
Copyright (c) 2017-2021 Arm Limited.
static NodeID add_detection_output_node(Graph &g, NodeParams params, NodeIdxPair input_loc, NodeIdxPair input_conf, NodeIdxPair input_priorbox, const DetectionOutputLayerInfo &detect_info)
Adds a detection output layer node to the graph.
static NodeID add_pad_node(Graph &g, NodeParams params, NodeIdxPair input, const PaddingList &paddings, PixelValue pad_value=PixelValue())
Adds a pad layer node to the graph.
Fast math disabled for Convolution layer.
Quantization information.
static NodeID add_print_node(Graph &g, NodeParams params, NodeIdxPair input, std::ostream &stream, const IOFormatInfo &format_info=IOFormatInfo(), const std::function< ITensor *(ITensor *)> transform=nullptr)
Adds a print layer node to the graph.
static NodeID add_stack_node(Graph &g, NodeParams params, const std::vector< NodeIdxPair > &inputs, int axis)
Adds a stack layer node to the graph.
static NodeID add_elementwise_node(Graph &g, NodeParams params, NodeIdxPair input0, NodeIdxPair input1, EltwiseOperation operation)
Adds an element-wise layer node to the graph.
IO formatting information class.
Definition: Types.h:2140
static NodeID add_reorg_node(Graph &g, NodeParams params, NodeIdxPair input, int stride)
Adds a reorg layer node to the graph.
const unsigned int num_groups
Definition: Im2Col.cpp:153
DepthwiseConvolutionMethod
Supported Depthwise Convolution layer methods.
Definition: Types.h:133
Coordinates of an item.
Definition: Coordinates.h:37
Pooling Layer Information struct.
Definition: Types.h:1142
static NodeID add_roi_align_node(Graph &g, NodeParams params, NodeIdxPair input, NodeIdxPair rois, ROIPoolingLayerInfo pool_info)
Adds a ROI align layer node to the graph.
PriorBox layer info.
Definition: Types.h:767
static NodeID add_l2_normalize_node(Graph &g, NodeParams params, NodeIdxPair input, int axis, float epsilon)
Adds a L2 Normalize layer node to the graph.
Padding and stride information class.
Definition: Types.h:650
Bounding Box Transform information class.
Definition: Types.h:1411
static NodeID add_dummy_node(Graph &g, NodeParams params, NodeIdxPair input, TensorShape shape)
Adds a Dummy node to the graph.
static NodeID add_dequantization_node(Graph &g, NodeParams params, NodeIdxPair input)
Adds a dequantization node to the graph.
static NodeID add_normalize_planar_yuv_node(Graph &g, NodeParams params, NodeIdxPair input, ITensorAccessorUPtr mean_accessor=nullptr, ITensorAccessorUPtr std_accessor=nullptr)
Adds a normalize planar YUV layer node to the graph.
NodeID-index struct.
Definition: Types.h:210
FastMathHint
Enable or disable fast math for Convolution layer.
Definition: Types.h:141
static NodeID add_channel_shuffle_node(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_groups)
Adds an channel shuffle layer node to the graph.
Strides of an item in bytes.
Definition: Strides.h:37
Graph class.
Definition: Graph.h:53
Detection Output layer info.
Definition: Types.h:904
static NodeID add_detection_post_process_node(Graph &g, NodeParams params, NodeIdxPair input_box_encoding, NodeIdxPair input_class_prediction, const DetectionPostProcessLayerInfo &detect_info, ITensorAccessorUPtr anchors_accessor=nullptr, const QuantizationInfo &anchor_quant_info=QuantizationInfo())
Adds a detection post process layer node to the graph.
unsigned int NodeID
Definition: Types.h:68
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
static NodeID add_softmax_node(Graph &g, NodeParams params, NodeIdxPair input, float beta=1.f)
Adds a softmax node to the graph.
static NodeID add_fully_connected_layer(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_outputs, NodeID weights_nid, NodeID bias_nid=EmptyNodeID, const FullyConnectedLayerInfo fc_info=FullyConnectedLayerInfo(), const QuantizationInfo &out_quant_info=QuantizationInfo())
Adds a fully connected layer node to the graph.
ROI Pooling Layer Information class.
Definition: Types.h:1237
constexpr NodeID EmptyNodeID
Constant EdgeID specifying an equivalent of null edge.
Definition: Types.h:75
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
static NodeID add_scale_layer(Graph &g, const NodeParams &params, NodeIdxPair input, ITensorAccessorUPtr mul_accessor=nullptr, ITensorAccessorUPtr add_accessor=nullptr)
Adds a scale layer node to the graph This layer computes a product of the input with a scale (read fr...
ConvolutionMethod
Supported Convolution layer methods.
Definition: Types.h:124
Detection Output layer info.
Definition: Types.h:1023
Default approach using internal heuristics.
Default approach using internal heuristics.
static NodeID add_const_node(Graph &g, NodeParams params, const TensorDescriptor &desc, ITensorAccessorUPtr accessor=nullptr)
Adds a Const node to the graph.
static NodeID add_flatten_node(Graph &g, NodeParams params, NodeIdxPair input)
Adds a flatten layer node to the graph.
static NodeID add_pooling_node(Graph &g, NodeParams params, NodeIdxPair input, PoolingLayerInfo pool_info)
Adds a pooling layer node to the graph.
DataType
Available data types.
Definition: Types.h:77
static NodeID add_strided_slice_node(Graph &g, NodeParams params, NodeIdxPair input, Coordinates &starts, Coordinates &ends, BiStrides &strides, StridedSliceLayerInfo info)
Adds a strided slice node to the graph.
DataLayout
[DataLayout enum definition]
Definition: Types.h:114
static NodeID add_arg_min_max_node(Graph &g, NodeParams params, NodeIdxPair input, ReductionOperation op, unsigned int axis, DataType out_data_type=DataType::UNKNOWN, const QuantizationInfo &out_quant_info=QuantizationInfo())
Adds an activation layer node to the graph.
static NodeID add_output_node(Graph &g, NodeParams params, NodeIdxPair input, ITensorAccessorUPtr accessor=nullptr)
Adds an output layer node to the graph.
static NodeID add_depthwise_convolution_node(Graph &g, NodeParams params, NodeIdxPair input, Size2D kernel_spatial_extend, PadStrideInfo conv_info, int depth_multiplier=1, DepthwiseConvolutionMethod method=DepthwiseConvolutionMethod::Default, ITensorAccessorUPtr weights_accessor=nullptr, ITensorAccessorUPtr bias_accessor=nullptr, const QuantizationInfo &quant_info=QuantizationInfo(), const QuantizationInfo &out_quant_info=QuantizationInfo())
Adds a depth-wise convolution layer node to the graph.