1 /* 2 * Copyright (c) 2018-2020 Arm Limited. 3 * 4 * SPDX-License-Identifier: MIT 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to 8 * deal in the Software without restriction, including without limitation the 9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 * sell copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in all 14 * copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 */ 24 #ifndef ARM_COMPUTE_GRAPH_GRAPH_BUILDER_H 25 #define ARM_COMPUTE_GRAPH_GRAPH_BUILDER_H 26 27 #include "arm_compute/graph/ITensorAccessor.h" 28 #include "arm_compute/graph/LayerDescriptors.h" 29 #include "arm_compute/graph/Types.h" 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 */ 85 static NodeID add_activation_node(Graph &g, NodeParams params, NodeIdxPair input, ActivationLayerInfo act_info, 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 */ 115 static NodeID add_batch_normalization_node(Graph &g, NodeParams params, NodeIdxPair input, float epsilon, 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 */ 128 static NodeID add_bounding_box_transform_node(Graph &g, NodeParams params, NodeIdxPair input, NodeIdxPair deltas, BoundingBoxTransformInfo info); 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 * TODO (COMPMID-1113): Add a graph descriptor for convolution layer node 142 * 143 * @param[in] g Graph to add the node to 144 * @param[in] params Common node parameters 145 * @param[in] input Input to the convolution layer node as a NodeID-Index pair 146 * @param[in] kernel_spatial_extend Spatial extend of convolution kernels 147 * @param[in] depth Number of convolution kernels 148 * @param[in] conv_info Convolution layer information 149 * @param[in] num_groups (Optional) Number of groups for a grouped convolution. Defaults to 1 150 * @param[in] method (Optional) Convolution method to use 151 * @param[in] fast_math_hint (Optional) Fast math hint 152 * @param[in] weights_accessor (Optional) Accessor of the weights node data 153 * @param[in] bias_accessor (Optional) Accessor of the bias node data 154 * @param[in] weights_quant_info (Optional) Weights quantization info 155 * @param[in] out_quant_info (Optional) Output quantization info 156 * 157 * @return Node ID of the created node, EmptyNodeID in case of error 158 */ 159 static NodeID add_convolution_node(Graph &g, NodeParams params, NodeIdxPair input, 160 Size2D kernel_spatial_extend, unsigned int depth, PadStrideInfo conv_info, unsigned int num_groups = 1, 161 ConvolutionMethod method = ConvolutionMethod::Default, FastMathHint fast_math_hint = FastMathHint::Disabled, 162 ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr, 163 const QuantizationInfo &weights_quant_info = QuantizationInfo(), 164 const QuantizationInfo &out_quant_info = QuantizationInfo()); 165 /** Adds a deconvolution layer node to the graph 166 * 167 * @param[in] g Graph to add the node to 168 * @param[in] params Common node parameters 169 * @param[in] input Input to the convolution layer node as a NodeID-Index pair 170 * @param[in] kernel_spatial_extend Spatial extend of convolution kernels 171 * @param[in] depth Number of convolution kernels 172 * @param[in] deconv_info Convolution layer information 173 * @param[in] weights_accessor (Optional) Accessor of the weights node data 174 * @param[in] bias_accessor (Optional) Accessor of the bias node data 175 * 176 * @return Node ID of the created node, EmptyNodeID in case of error 177 */ 178 static NodeID add_deconvolution_node(Graph &g, NodeParams params, NodeIdxPair input, 179 Size2D kernel_spatial_extend, unsigned int depth, PadStrideInfo deconv_info, 180 ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr); 181 /** Adds a depth concatenate node to the graph 182 * 183 * @param[in] g Graph to add the node to 184 * @param[in] params Common node parameters 185 * @param[in] inputs Inputs to the concatenate layer node as a NodeID-Index pair 186 * @param[in] concat_descriptor Concatenation layer descriptor 187 * 188 * @return Node ID of the created node, EmptyNodeID in case of error 189 */ 190 static NodeID add_concatenate_node(Graph &g, NodeParams params, const std::vector<NodeIdxPair> &inputs, const descriptors::ConcatLayerDescriptor &concat_descriptor); 191 /** Adds an depth to space layer node to the graph 192 * 193 * @param[in] g Graph to add the node to 194 * @param[in] params Common node parameters 195 * @param[in] input Input to the depth to space layer node as a NodeID-Index pair 196 * @param[in] block_shape Block shape to reshape tensor with 197 * 198 * @return Node ID of the created node, EmptyNodeID in case of error 199 */ 200 static NodeID add_depth_to_space_node(Graph &g, NodeParams params, NodeIdxPair input, int32_t block_shape); 201 /** Adds a depth-wise convolution layer node to the graph 202 * 203 * @param[in] g Graph to add the node to 204 * @param[in] params Common node parameters 205 * @param[in] input Input to the depthwise convolution layer node as a NodeID-Index pair 206 * @param[in] kernel_spatial_extend Spatial extend of convolution kernels 207 * @param[in] conv_info Convolution layer information 208 * @param[in] depth_multiplier (Optional) Depth multiplier parameter. 209 * @param[in] method (Optional) Convolution method to use 210 * @param[in] weights_accessor (Optional) Accessor of the weights node data 211 * @param[in] bias_accessor (Optional) Accessor of the bias node data 212 * @param[in] quant_info (Optional) Weights quantization info 213 * @param[in] out_quant_info (Optional) Output quantization info 214 * 215 * @return Node ID of the created node, EmptyNodeID in case of error 216 */ 217 static NodeID add_depthwise_convolution_node(Graph &g, NodeParams params, NodeIdxPair input, 218 Size2D kernel_spatial_extend, PadStrideInfo conv_info, int depth_multiplier = 1, 219 DepthwiseConvolutionMethod method = DepthwiseConvolutionMethod::Default, 220 ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr, const QuantizationInfo &quant_info = QuantizationInfo(), 221 const QuantizationInfo &out_quant_info = QuantizationInfo()); 222 /** Adds an element-wise layer node to the graph 223 * 224 * @param[in] g Graph to add the node to 225 * @param[in] params Common node parameters 226 * @param[in] input0 First input to the element-wise operation layer node as a NodeID-Index pair 227 * @param[in] input1 Second input to the element-wise operation layer node as a NodeID-Index pair 228 * @param[in] operation Element-wise operation to perform 229 * 230 * @return Node ID of the created node, EmptyNodeID in case of error 231 */ 232 static NodeID add_elementwise_node(Graph &g, NodeParams params, NodeIdxPair input0, NodeIdxPair input1, EltwiseOperation operation); 233 /** Adds a dequantization node to the graph 234 * 235 * @param[in] g Graph to add the node to 236 * @param[in] params Common node parameters 237 * @param[in] input Input to the dequantization node as a NodeID-Index pair 238 * 239 * @return Node ID of the created node, EmptyNodeID in case of error 240 */ 241 static NodeID add_dequantization_node(Graph &g, NodeParams params, NodeIdxPair input); 242 /** Adds a detection output layer node to the graph 243 * 244 * @param[in] g Graph to add the node to 245 * @param[in] params Common node parameters 246 * @param[in] input_loc Location input to the detection output layer node as a NodeID-Index pair 247 * @param[in] input_conf Confidence input to the detection output layer node as a NodeID-Index pair 248 * @param[in] input_priorbox PriorBox input to the detection output layer node as a NodeID-Index pair 249 * @param[in] detect_info Detection output layer parameters 250 * 251 * @return Node ID of the created node, EmptyNodeID in case of error 252 */ 253 static NodeID add_detection_output_node(Graph &g, NodeParams params, NodeIdxPair input_loc, NodeIdxPair input_conf, NodeIdxPair input_priorbox, const DetectionOutputLayerInfo &detect_info); 254 /** Adds a detection post process layer node to the graph 255 * 256 * @param[in] g Graph to add the node to 257 * @param[in] params Common node parameters 258 * @param[in] input_box_encoding Boxes input to the detection output layer node as a NodeID-Index pair 259 * @param[in] input_class_prediction Class prediction input to the detection output layer node as a NodeID-Index pair 260 * @param[in] detect_info Detection output layer parameters 261 * @param[in] anchors_accessor (Optional) Const Node ID that contains the anchor values 262 * @param[in] anchor_quant_info (Optional) Anchor quantization info 263 * 264 * @return Node ID of the created node, EmptyNodeID in case of error 265 */ 266 static NodeID add_detection_post_process_node(Graph &g, NodeParams params, NodeIdxPair input_box_encoding, NodeIdxPair input_class_prediction, 267 const DetectionPostProcessLayerInfo &detect_info, ITensorAccessorUPtr anchors_accessor = nullptr, 268 const QuantizationInfo &anchor_quant_info = QuantizationInfo()); 269 /** Adds a Dummy node to the graph 270 * 271 * @note this node if for debugging purposes. Just alters the shape of the graph pipeline as requested. 272 * 273 * @param[in] g Graph to add the node to 274 * @param[in] params Common node parameters 275 * @param[in] input Input to the dummy node as a NodeID-Index pair 276 * @param[in] shape Output shape 277 * 278 * @return Node ID of the created node, EmptyNodeID in case of error 279 */ 280 static NodeID add_dummy_node(Graph &g, NodeParams params, NodeIdxPair input, TensorShape shape); 281 /** Adds a flatten layer node to the graph 282 * 283 * @param[in] g Graph to add the node to 284 * @param[in] params Common node parameters 285 * @param[in] input Input to the flatten layer node as a NodeID-Index pair 286 * 287 * @return Node ID of the created node, EmptyNodeID in case of error 288 */ 289 static NodeID add_flatten_node(Graph &g, NodeParams params, NodeIdxPair input); 290 /** Adds a fully connected layer node to the graph 291 * 292 * @param[in] g Graph to add the layer to 293 * @param[in] params Common node parameters 294 * @param[in] input Input to the fully connected layer node as a NodeID-Index pair 295 * @param[in] num_outputs Number of output neurons 296 * @param[in] weights_nid Node ID of the weights node data 297 * @param[in] bias_nid (Optional) Node ID of the bias node data. Defaults to EmptyNodeID 298 * @param[in] fc_info (Optional) Fully connected layer metadata 299 * @param[in] out_quant_info (Optional) Output quantization info 300 * 301 * @return Node ID of the created node, EmptyNodeID in case of error 302 */ 303 static NodeID add_fully_connected_layer(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_outputs, 304 NodeID weights_nid, NodeID bias_nid = EmptyNodeID, 305 const FullyConnectedLayerInfo fc_info = FullyConnectedLayerInfo(), 306 const QuantizationInfo &out_quant_info = QuantizationInfo()); 307 /** Adds a fully connected layer node to the graph 308 * 309 * @param[in] g Graph to add the layer to 310 * @param[in] params Common node parameters 311 * @param[in] input Input to the fully connected layer node as a NodeID-Index pair 312 * @param[in] num_outputs Number of output neurons 313 * @param[in] weights_accessor (Optional) Accessor of the weights node data 314 * @param[in] bias_accessor (Optional) Accessor of the bias node data 315 * @param[in] fc_info (Optional) Fully connected layer metadata 316 * @param[in] weights_quant_info (Optional) Weights quantization info 317 * @param[in] out_quant_info (Optional) Output quantization info 318 * 319 * @return Node ID of the created node, EmptyNodeID in case of error 320 */ 321 static NodeID add_fully_connected_layer(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_outputs, 322 ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr, 323 const FullyConnectedLayerInfo fc_info = FullyConnectedLayerInfo(), 324 const QuantizationInfo &weights_quant_info = QuantizationInfo(), 325 const QuantizationInfo &out_quant_info = QuantizationInfo()); 326 /** Adds a generate proposals layer node to the graph 327 * 328 * @param[in] g Graph to add the layer to 329 * @param[in] params Common node parameters 330 * @param[in] scores Input scores to the generate proposals layer node as a NodeID-Index pair 331 * @param[in] deltas Input deltas to the generate proposals layer node as a NodeID-Index pair 332 * @param[in] anchors Input anchors to the generate proposals layer node as a NodeID-Index pair 333 * @param[in] info Generate proposals operation information 334 * 335 * @return Node ID of the created node, EmptyNodeID in case of error 336 */ 337 static NodeID add_generate_proposals_node(Graph &g, NodeParams params, NodeIdxPair scores, NodeIdxPair deltas, 338 NodeIdxPair anchors, GenerateProposalsInfo info); 339 /** Adds a L2 Normalize layer node to the graph 340 * 341 * @param[in] g Graph to add the node to 342 * @param[in] params Common node parameters 343 * @param[in] input Input to the normalization layer node as a NodeID-Index pair 344 * @param[in] axis Axis to perform normalization on 345 * @param[in] epsilon Lower bound value for the normalization 346 * 347 * @return Node ID of the created node, EmptyNodeID in case of error 348 */ 349 static NodeID add_l2_normalize_node(Graph &g, NodeParams params, NodeIdxPair input, int axis, float epsilon); 350 /** Adds a normalization layer node to the graph 351 * 352 * @param[in] g Graph to add the node to 353 * @param[in] params Common node parameters 354 * @param[in] input Input to the normalization layer node as a NodeID-Index pair 355 * @param[in] norm_info Normalization layer information 356 * 357 * @return Node ID of the created node, EmptyNodeID in case of error 358 */ 359 static NodeID add_normalization_node(Graph &g, NodeParams params, NodeIdxPair input, NormalizationLayerInfo norm_info); 360 /** Adds a normalize planar YUV layer node to the graph 361 * 362 * @param[in] g Graph to add the node to 363 * @param[in] params Common node parameters 364 * @param[in] input Input to the normalize planar YUV layer node as a NodeID-Index pair 365 * @param[in] mean_accessor Const Node ID that contains the mean values 366 * @param[in] std_accessor Const Node ID that contains the variance values 367 * 368 * @return Node ID of the created node, EmptyNodeID in case of error 369 */ 370 static NodeID add_normalize_planar_yuv_node(Graph &g, NodeParams params, NodeIdxPair input, 371 ITensorAccessorUPtr mean_accessor = nullptr, ITensorAccessorUPtr std_accessor = nullptr); 372 /** Adds a pad layer node to the graph 373 * 374 * @param[in] g Graph to add the node to 375 * @param[in] params Common node parameters 376 * @param[in] input Input to the reshape layer node as a NodeID-Index pair 377 * @param[in] paddings The padding for each spatial dimension of the input tensor. The pair padding[i] 378 * specifies the front and the end padding in the i-th dimension. 379 * @param[in] pad_value Padding value to be used. Defaults to 0 380 * 381 * @return Node ID of the created node, EmptyNodeID in case of error 382 */ 383 static NodeID add_pad_node(Graph &g, NodeParams params, NodeIdxPair input, const PaddingList &paddings, PixelValue pad_value = PixelValue()); 384 /** Adds a permute layer node to the graph 385 * 386 * @param[in] g Graph to add the node to 387 * @param[in] params Common node parameters 388 * @param[in] input Input to the reshape layer node as a NodeID-Index pair 389 * @param[in] perm Permutation vector 390 * @param[in] layout (Optional) Data layout to assign to permuted tensor. 391 * If UNKNOWN then the input's layout will be used. 392 * 393 * @return Node ID of the created node, EmptyNodeID in case of error 394 */ 395 static NodeID add_permute_node(Graph &g, NodeParams params, NodeIdxPair input, PermutationVector perm, DataLayout layout = DataLayout::UNKNOWN); 396 /** Adds a pooling layer node to the graph 397 * 398 * @param[in] g Graph to add the node to 399 * @param[in] params Common node parameters 400 * @param[in] input Input to the pooling layer node as a NodeID-Index pair 401 * @param[in] pool_info Pooling layer information 402 * 403 * @return Node ID of the created node, EmptyNodeID in case of error 404 */ 405 static NodeID add_pooling_node(Graph &g, NodeParams params, NodeIdxPair input, PoolingLayerInfo pool_info); 406 /** Adds a prelu layer node to the graph 407 * 408 * @param[in] g Graph to add the node to 409 * @param[in] params Common node parameters 410 * @param[in] input Input to the PRelu node as a NodeID-Index pair 411 * @param[in] alpha Alpha input to the PRelu node as a NodeID-Index pair 412 * 413 * @return Node ID of the created node, EmptyNodeID in case of error 414 */ 415 static NodeID add_prelu_node(Graph &g, NodeParams params, NodeIdxPair input, NodeIdxPair alpha); 416 /** Adds a print layer node to the graph 417 * 418 * @param[in] g Graph to add the node to 419 * @param[in] params Common node parameters 420 * @param[in] input Input to the print layer node as a NodeID-Index pair 421 * @param[in] stream Output stream. 422 * @param[in] format_info (Optional) Format info. 423 * @param[in] transform (Optional) Transformation function to be applied to the input tensor before printing. 424 * 425 * @return Node ID of the created node, EmptyNodeID in case of error 426 */ 427 static NodeID add_print_node(Graph &g, NodeParams params, NodeIdxPair input, std::ostream &stream, const IOFormatInfo &format_info = IOFormatInfo(), 428 const std::function<ITensor *(ITensor *)> transform = nullptr); 429 /** Adds a priorbox layer node to the graph 430 * 431 * @param[in] g Graph to add the node to 432 * @param[in] params Common node parameters 433 * @param[in] input0 First input to the priorbox layer node as a NodeID-Index pair 434 * @param[in] input1 Second input to the priorbox layer node as a NodeID-Index pair 435 * @param[in] prior_info PriorBox parameters 436 * 437 * @return Node ID of the created node, EmptyNodeID in case of error 438 */ 439 static NodeID add_priorbox_node(Graph &g, NodeParams params, NodeIdxPair input0, NodeIdxPair input1, const PriorBoxLayerInfo &prior_info); 440 /** Adds a quantization layer node to the graph 441 * 442 * @param[in] g Graph to add the node to 443 * @param[in] params Common node parameters 444 * @param[in] input Input to the quantization layer node as a NodeID-Index pair 445 * @param[in] out_quant_info Output quantization info 446 * 447 * @return Node ID of the created node, EmptyNodeID in case of error 448 */ 449 static NodeID add_quantization_node(Graph &g, NodeParams params, NodeIdxPair input, const QuantizationInfo &out_quant_info); 450 /** Adds a reduction sum layer node to the graph 451 * 452 * @param[in] g Graph to add the node to 453 * @param[in] params Common node parameters 454 * @param[in] input Input to the reorg layer node as a NodeID-Index pair 455 * @param[in] op Reduction operation 456 * @param[in] axis Reduction axis 457 * @param[in] keep_dims (Optional) Whether to keep the reduced dimension after the operation. Defaults to true. 458 * 459 * @return Node ID of the created node, EmptyNodeID in case of error 460 */ 461 static NodeID add_reduction_operation_node(Graph &g, NodeParams params, NodeIdxPair input, ReductionOperation op, int axis, bool keep_dims = true); 462 /** Adds a reorg layer node to the graph 463 * 464 * @param[in] g Graph to add the node to 465 * @param[in] params Common node parameters 466 * @param[in] input Input to the reorg layer node as a NodeID-Index pair 467 * @param[in] stride Stride value to use for reorganizing the values in the output tensor. 468 * 469 * @return Node ID of the created node, EmptyNodeID in case of error 470 */ 471 static NodeID add_reorg_node(Graph &g, NodeParams params, NodeIdxPair input, int stride); 472 /** Adds a reshape layer node to the graph 473 * 474 * @param[in] g Graph to add the node to 475 * @param[in] params Common node parameters 476 * @param[in] input Input to the reshape layer node as a NodeID-Index pair 477 * @param[in] shape Output reshaped shape 478 * 479 * @return Node ID of the created node, EmptyNodeID in case of error 480 */ 481 static NodeID add_reshape_node(Graph &g, NodeParams params, NodeIdxPair input, TensorShape shape); 482 /** Adds a resize layer node to the graph 483 * 484 * @param[in] g Graph to add the node to 485 * @param[in] params Common node parameters 486 * @param[in] input Input to the reshape layer node as a NodeID-Index pair 487 * @param[in] policy Interpolation policy 488 * @param[in] width_scale Width scaling factor 489 * @param[in] height_scale Height scaling factor 490 * 491 * @return Node ID of the created node, EmptyNodeID in case of error 492 */ 493 static NodeID add_resize_node(Graph &g, NodeParams params, NodeIdxPair input, InterpolationPolicy policy, float width_scale, float height_scale); 494 /** Adds a ROI align layer node to the graph 495 * 496 * @param[in] g Graph to add the node to 497 * @param[in] params Common node parameters 498 * @param[in] input Input to the reshape layer node as a NodeID-Index pair 499 * @param[in] rois Input containing the ROIs. 500 * @param[in] pool_info Contains pooling operation information described in @ref ROIPoolingLayerInfo. 501 * 502 * @return Node ID of the created node, EmptyNodeID in case of error 503 */ 504 static NodeID add_roi_align_node(Graph &g, NodeParams params, NodeIdxPair input, NodeIdxPair rois, ROIPoolingLayerInfo pool_info); 505 /** Adds a scale layer node to the graph 506 * This layer computes a product of the input with a scale (read from mul_accessor) and it applies an offset (read from add_accessor). 507 * output = input * mul_w + add_w 508 * 509 * @param[in] g Graph to add the layer to 510 * @param[in] params Common node parameters 511 * @param[in] input Input to the fully connected layer node as a NodeID-Index pair 512 * @param[in] mul_accessor (Optional) Accessor of the mul node data 513 * @param[in] add_accessor (Optional) Accessor of the add node data 514 * 515 * @return Node ID of the created node, EmptyNodeID in case of error 516 */ 517 static NodeID add_scale_layer(Graph &g, const NodeParams ¶ms, NodeIdxPair input, 518 ITensorAccessorUPtr mul_accessor = nullptr, ITensorAccessorUPtr add_accessor = nullptr); 519 /** Adds a softmax node to the graph 520 * 521 * @param[in] g Graph to add the node to 522 * @param[in] params Common node parameters 523 * @param[in] input Input to the softmax layer node as a NodeID-Index pair 524 * @param[in] beta Beta parameter 525 * 526 * @return Node ID of the created node, EmptyNodeID in case of error 527 */ 528 static NodeID add_softmax_node(Graph &g, NodeParams params, NodeIdxPair input, float beta = 1.f); 529 /** Adds a slice node to the graph 530 * 531 * @param[in] g Graph to add the node to 532 * @param[in] params Common node parameters 533 * @param[in] input Input to the slice layer node as a NodeID-Index pair 534 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). 535 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). 536 * 537 * @return Node ID of the created node, EmptyNodeID in case of error 538 */ 539 static NodeID add_slice_node(Graph &g, NodeParams params, NodeIdxPair input, Coordinates &starts, Coordinates &ends); 540 /** Adds a split node to the graph 541 * 542 * @param[in] g Graph to add the node to 543 * @param[in] params Common node parameters 544 * @param[in] input Input to the split layer node as a NodeID-Index pair 545 * @param[in] num_splits Number of different splits 546 * @param[in] axis (Optional) Split axis. Defaults to 0 547 * 548 * @return Node ID of the created node, EmptyNodeID in case of error 549 */ 550 static NodeID add_split_node(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_splits, unsigned int axis = 0); 551 /** Adds a stack layer node to the graph 552 * 553 * @param[in] g Graph to add the node to 554 * @param[in] params Common node parameters 555 * @param[in] inputs Inputs to the reorg layer node as a NodeID-Index pair 556 * @param[in] axis Axis along which the input tensors have to be packed 557 * 558 * @return Node ID of the created node, EmptyNodeID in case of error 559 */ 560 static NodeID add_stack_node(Graph &g, NodeParams params, const std::vector<NodeIdxPair> &inputs, int axis); 561 /** Adds a strided slice node to the graph 562 * 563 * @param[in] g Graph to add the node to 564 * @param[in] params Common node parameters 565 * @param[in] input Input to the strided slice layer node as a NodeID-Index pair 566 * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). 567 * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). 568 * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input). 569 * @param[in] info Contains masks for the starts, ends and strides 570 * 571 * @return Node ID of the created node, EmptyNodeID in case of error 572 */ 573 static NodeID add_strided_slice_node(Graph &g, NodeParams params, NodeIdxPair input, Coordinates &starts, Coordinates &ends, BiStrides &strides, StridedSliceLayerInfo info); 574 /** Adds an upsample layer to the graph 575 * 576 * @param[in] g Graph to add the node to 577 * @param[in] params Common node parameters 578 * @param[in] input Input to the yolo layer node as a NodeID-Index pair 579 * @param[in] info Upsample layer stride info 580 * @param[in] upsampling_policy Upsampling policy used 581 * 582 * @return Node ID of the created node, EmptyNodeID in case of error 583 */ 584 static NodeID add_upsample_node(Graph &g, NodeParams params, NodeIdxPair input, Size2D info, InterpolationPolicy upsampling_policy); 585 /** Adds a yolo layer to the graph 586 * 587 * @param[in] g Graph to add the node to 588 * @param[in] params Common node parameters 589 * @param[in] input Input to the yolo layer node as a NodeID-Index pair 590 * @param[in] act_info Activation layer parameters 591 * @param[in] num_classes Number of classes to activate 592 * 593 * @return Node ID of the created node, EmptyNodeID in case of error 594 */ 595 static NodeID add_yolo_node(Graph &g, NodeParams params, NodeIdxPair input, ActivationLayerInfo act_info, int32_t num_classes); 596 }; 597 } // namespace graph 598 } // namespace arm_compute 599 #endif /* ARM_COMPUTE_GRAPH_GRAPH_BUILDER_H */ 600