Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 1 | /* |
Giuseppe Rossini | bb365de | 2019-02-15 10:24:47 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 ARM Limited. |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 24 | #ifndef __ARM_COMPUTE_GRAPH_GRAPH_BUILDER_H__ |
| 25 | #define __ARM_COMPUTE_GRAPH_GRAPH_BUILDER_H__ |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 26 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 27 | #include "arm_compute/graph/ITensorAccessor.h" |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 28 | #include "arm_compute/graph/LayerDescriptors.h" |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 29 | #include "arm_compute/graph/Types.h" |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 30 | |
| 31 | namespace arm_compute |
| 32 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 33 | namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 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 | */ |
Michalis Spyrou | 299fdd3 | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 54 | static NodeID add_const_node(Graph &g, NodeParams params, const TensorDescriptor &desc, ITensorAccessorUPtr accessor = nullptr); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 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 | */ |
Michalis Spyrou | 299fdd3 | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 64 | static NodeID add_input_node(Graph &g, NodeParams params, const TensorDescriptor &desc, ITensorAccessorUPtr accessor = nullptr); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 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 | * |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 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 |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 82 | * |
| 83 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 84 | */ |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 85 | static NodeID add_activation_node(Graph &g, NodeParams params, NodeIdxPair input, ActivationLayerInfo act_info, |
Michalis Spyrou | 18574c1 | 2019-06-05 10:51:07 +0100 | [diff] [blame] | 86 | const QuantizationInfo &out_quant_info = QuantizationInfo()); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 87 | /** Adds a batch normalization 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 batch normalization layer node as a NodeID-Index pair |
| 92 | * @param[in] epsilon Epsilon parameter |
| 93 | * @param[in] mean_accessor Const Node ID that contains the mean values |
| 94 | * @param[in] var_accessor Const Node ID that contains the variance values |
| 95 | * @param[in] beta_accessor Const Node ID that contains the beta values. Can be EmptyNodeID |
| 96 | * @param[in] gamma_accessor Const Node ID that contains the gamma values. Can be EmptyNodeID |
| 97 | * |
| 98 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 99 | */ |
| 100 | static NodeID add_batch_normalization_node(Graph &g, NodeParams params, NodeIdxPair input, float epsilon, |
| 101 | ITensorAccessorUPtr mean_accessor = nullptr, ITensorAccessorUPtr var_accessor = nullptr, |
| 102 | ITensorAccessorUPtr beta_accessor = nullptr, ITensorAccessorUPtr gamma_accessor = nullptr); |
Manuel Bottini | d2048ce | 2018-10-23 17:00:42 +0100 | [diff] [blame] | 103 | /** Adds a bounding box transform layer node to the graph |
| 104 | * |
| 105 | * @param[in] g Graph to add the node to |
| 106 | * @param[in] params Common node parameters |
| 107 | * @param[in] input Input to the bounding box transform layer node as a NodeID-Index pair |
| 108 | * @param[in] deltas Deltas input to the bounding box transform layer node as a NodeID-Index pair |
| 109 | * @param[in] info Bounding Box Transform information |
| 110 | * |
| 111 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 112 | */ |
| 113 | static NodeID add_bounding_box_transform_node(Graph &g, NodeParams params, NodeIdxPair input, NodeIdxPair deltas, BoundingBoxTransformInfo info); |
Georgios Pinitas | 087eaf6 | 2018-05-16 15:52:35 +0100 | [diff] [blame] | 114 | /** Adds an channel shuffle layer node to the graph |
| 115 | * |
| 116 | * @param[in] g Graph to add the node to |
| 117 | * @param[in] params Common node parameters |
| 118 | * @param[in] input Input to the activation layer node as a NodeID-Index pair |
| 119 | * @param[in] num_groups Number of groups |
| 120 | * |
| 121 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 122 | */ |
| 123 | static NodeID add_channel_shuffle_node(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_groups); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 124 | /** Adds a convolution layer node to the graph |
| 125 | * |
Giorgio Arena | 59631a1 | 2018-05-02 13:59:04 +0100 | [diff] [blame] | 126 | * TODO (COMPMID-1113): Add a graph descriptor for convolution layer node |
| 127 | * |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 128 | * @param[in] g Graph to add the node to |
| 129 | * @param[in] params Common node parameters |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 130 | * @param[in] input Input to the convolution layer node as a NodeID-Index pair |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 131 | * @param[in] kernel_spatial_extend Spatial extend of convolution kernels |
| 132 | * @param[in] depth Number of convolution kernels |
| 133 | * @param[in] conv_info Convolution layer information |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 134 | * @param[in] num_groups (Optional) Number of groups for a grouped convolution. Defaults to 1 |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 135 | * @param[in] method (Optional) Convolution method to use |
Giorgio Arena | 59631a1 | 2018-05-02 13:59:04 +0100 | [diff] [blame] | 136 | * @param[in] fast_math_hint (Optional) Fast math hint |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 137 | * @param[in] weights_accessor (Optional) Accessor of the weights node data |
| 138 | * @param[in] bias_accessor (Optional) Accessor of the bias node data |
Giorgio Arena | bb54e4e | 2018-04-05 17:20:34 +0100 | [diff] [blame] | 139 | * @param[in] weights_quant_info (Optional) Weights quantization info |
| 140 | * @param[in] out_quant_info (Optional) Output quantization info |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 141 | * |
| 142 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 143 | */ |
| 144 | static NodeID add_convolution_node(Graph &g, NodeParams params, NodeIdxPair input, |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 145 | Size2D kernel_spatial_extend, unsigned int depth, PadStrideInfo conv_info, unsigned int num_groups = 1, |
| 146 | ConvolutionMethod method = ConvolutionMethod::Default, FastMathHint fast_math_hint = FastMathHint::Disabled, |
Giorgio Arena | bb54e4e | 2018-04-05 17:20:34 +0100 | [diff] [blame] | 147 | ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr, |
Michalis Spyrou | 18574c1 | 2019-06-05 10:51:07 +0100 | [diff] [blame] | 148 | const QuantizationInfo &weights_quant_info = QuantizationInfo(), |
| 149 | const QuantizationInfo &out_quant_info = QuantizationInfo()); |
Georgios Pinitas | 087eaf6 | 2018-05-16 15:52:35 +0100 | [diff] [blame] | 150 | /** Adds a deconvolution layer node to the graph |
| 151 | * |
| 152 | * @param[in] g Graph to add the node to |
| 153 | * @param[in] params Common node parameters |
| 154 | * @param[in] input Input to the convolution layer node as a NodeID-Index pair |
| 155 | * @param[in] kernel_spatial_extend Spatial extend of convolution kernels |
| 156 | * @param[in] depth Number of convolution kernels |
| 157 | * @param[in] deconv_info Convolution layer information |
Georgios Pinitas | 087eaf6 | 2018-05-16 15:52:35 +0100 | [diff] [blame] | 158 | * @param[in] weights_accessor (Optional) Accessor of the weights node data |
| 159 | * @param[in] bias_accessor (Optional) Accessor of the bias node data |
| 160 | * |
| 161 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 162 | */ |
| 163 | static NodeID add_deconvolution_node(Graph &g, NodeParams params, NodeIdxPair input, |
Manuel Bottini | c1b76fa | 2019-06-17 12:04:40 +0100 | [diff] [blame] | 164 | Size2D kernel_spatial_extend, unsigned int depth, PadStrideInfo deconv_info, |
Georgios Pinitas | 087eaf6 | 2018-05-16 15:52:35 +0100 | [diff] [blame] | 165 | ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 166 | /** Adds a depth concatenate node to the graph |
| 167 | * |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 168 | * @param[in] g Graph to add the node to |
| 169 | * @param[in] params Common node parameters |
Michele Di Giorgio | ec69975 | 2019-03-22 15:25:32 +0000 | [diff] [blame] | 170 | * @param[in] inputs Inputs to the concatenate layer node as a NodeID-Index pair |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 171 | * @param[in] concat_descriptor Concatenation layer descriptor |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 172 | * |
| 173 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 174 | */ |
Michalis Spyrou | 18574c1 | 2019-06-05 10:51:07 +0100 | [diff] [blame] | 175 | static NodeID add_concatenate_node(Graph &g, NodeParams params, const std::vector<NodeIdxPair> &inputs, const descriptors::ConcatLayerDescriptor &concat_descriptor); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 176 | /** Adds a depth-wise convolution layer node to the graph |
| 177 | * |
| 178 | * @param[in] g Graph to add the node to |
| 179 | * @param[in] params Common node parameters |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 180 | * @param[in] input Input to the depthwise convolution layer node as a NodeID-Index pair |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 181 | * @param[in] kernel_spatial_extend Spatial extend of convolution kernels |
| 182 | * @param[in] conv_info Convolution layer information |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 183 | * @param[in] depth_multiplier (Optional) Depth multiplier parameter. |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 184 | * @param[in] method (Optional) Convolution method to use |
| 185 | * @param[in] weights_accessor (Optional) Accessor of the weights node data |
| 186 | * @param[in] bias_accessor (Optional) Accessor of the bias node data |
Giorgio Arena | bb54e4e | 2018-04-05 17:20:34 +0100 | [diff] [blame] | 187 | * @param[in] quant_info (Optional) Weights quantization info |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 188 | * @param[in] out_quant_info (Optional) Output quantization info |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 189 | * |
| 190 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 191 | */ |
| 192 | static NodeID add_depthwise_convolution_node(Graph &g, NodeParams params, NodeIdxPair input, |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 193 | Size2D kernel_spatial_extend, PadStrideInfo conv_info, int depth_multiplier = 1, |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 194 | DepthwiseConvolutionMethod method = DepthwiseConvolutionMethod::Default, |
Michalis Spyrou | 18574c1 | 2019-06-05 10:51:07 +0100 | [diff] [blame] | 195 | ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr, const QuantizationInfo &quant_info = QuantizationInfo(), |
| 196 | const QuantizationInfo &out_quant_info = QuantizationInfo()); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 197 | /** Adds an element-wise layer node to the graph |
| 198 | * |
| 199 | * @param[in] g Graph to add the node to |
| 200 | * @param[in] params Common node parameters |
| 201 | * @param[in] input0 First input to the element-wise operation layer node as a NodeID-Index pair |
| 202 | * @param[in] input1 Second input to the element-wise operation layer node as a NodeID-Index pair |
| 203 | * @param[in] operation Element-wise operation to perform |
| 204 | * |
| 205 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 206 | */ |
| 207 | static NodeID add_elementwise_node(Graph &g, NodeParams params, NodeIdxPair input0, NodeIdxPair input1, EltwiseOperation operation); |
Isabella Gottardi | 7234ed8 | 2018-11-27 08:51:10 +0000 | [diff] [blame] | 208 | /** Adds a detection output layer node to the graph |
| 209 | * |
| 210 | * @param[in] g Graph to add the node to |
| 211 | * @param[in] params Common node parameters |
| 212 | * @param[in] input_loc Location input to the detection output layer node as a NodeID-Index pair |
| 213 | * @param[in] input_conf Confidence input to the detection output layer node as a NodeID-Index pair |
| 214 | * @param[in] input_priorbox PriorBox input to the detection output layer node as a NodeID-Index pair |
| 215 | * @param[in] detect_info Detection output layer parameters |
| 216 | * |
| 217 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 218 | */ |
Georgios Pinitas | f52cd78 | 2019-03-25 14:06:14 +0000 | [diff] [blame] | 219 | static NodeID add_detection_output_node(Graph &g, NodeParams params, NodeIdxPair input_loc, NodeIdxPair input_conf, NodeIdxPair input_priorbox, const DetectionOutputLayerInfo &detect_info); |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 220 | /** Adds a detection post process 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] input_box_encoding Boxes input to the detection output layer node as a NodeID-Index pair |
| 225 | * @param[in] input_class_prediction Class prediction input to the detection output layer node as a NodeID-Index pair |
| 226 | * @param[in] detect_info Detection output layer parameters |
| 227 | * @param[in] anchors_accessor (Optional) Const Node ID that contains the anchor values |
| 228 | * @param[in] anchor_quant_info (Optional) Anchor quantization info |
| 229 | * |
| 230 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 231 | */ |
| 232 | static NodeID add_detection_post_process_node(Graph &g, NodeParams params, NodeIdxPair input_box_encoding, NodeIdxPair input_class_prediction, |
| 233 | const DetectionPostProcessLayerInfo &detect_info, ITensorAccessorUPtr anchors_accessor = nullptr, |
| 234 | const QuantizationInfo &anchor_quant_info = QuantizationInfo()); |
Georgios Pinitas | 087eaf6 | 2018-05-16 15:52:35 +0100 | [diff] [blame] | 235 | /** Adds a Dummy node to the graph |
| 236 | * |
| 237 | * @note this node if for debugging purposes. Just alters the shape of the graph pipeline as requested. |
| 238 | * |
| 239 | * @param[in] g Graph to add the node to |
| 240 | * @param[in] params Common node parameters |
| 241 | * @param[in] input Input to the dummy node as a NodeID-Index pair |
| 242 | * @param[in] shape Output shape |
| 243 | * |
| 244 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 245 | */ |
| 246 | static NodeID add_dummy_node(Graph &g, NodeParams params, NodeIdxPair input, TensorShape shape); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 247 | /** Adds a flatten layer node to the graph |
| 248 | * |
| 249 | * @param[in] g Graph to add the node to |
| 250 | * @param[in] params Common node parameters |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 251 | * @param[in] input Input to the flatten layer node as a NodeID-Index pair |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 252 | * |
| 253 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 254 | */ |
| 255 | static NodeID add_flatten_node(Graph &g, NodeParams params, NodeIdxPair input); |
| 256 | /** Adds a fully connected layer node to the graph |
| 257 | * |
Michele Di Giorgio | a42f55f | 2019-03-08 14:52:17 +0000 | [diff] [blame] | 258 | * @param[in] g Graph to add the layer to |
| 259 | * @param[in] params Common node parameters |
| 260 | * @param[in] input Input to the fully connected layer node as a NodeID-Index pair |
| 261 | * @param[in] num_outputs Number of output neurons |
| 262 | * @param[in] weights_nid Node ID of the weights node data |
| 263 | * @param[in] bias_nid (Optional) Node ID of the bias node data. Defaults to EmptyNodeID |
| 264 | * @param[in] fc_info (Optional) Fully connected layer metadata |
| 265 | * @param[in] out_quant_info (Optional) Output quantization info |
| 266 | * |
| 267 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 268 | */ |
| 269 | static NodeID add_fully_connected_layer(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_outputs, |
| 270 | NodeID weights_nid, NodeID bias_nid = EmptyNodeID, |
| 271 | const FullyConnectedLayerInfo fc_info = FullyConnectedLayerInfo(), |
Michalis Spyrou | 18574c1 | 2019-06-05 10:51:07 +0100 | [diff] [blame] | 272 | const QuantizationInfo &out_quant_info = QuantizationInfo()); |
Michele Di Giorgio | a42f55f | 2019-03-08 14:52:17 +0000 | [diff] [blame] | 273 | /** Adds a fully connected layer node to the graph |
| 274 | * |
Georgios Pinitas | 2f1366a | 2018-07-31 16:33:06 +0100 | [diff] [blame] | 275 | * @param[in] g Graph to add the layer to |
| 276 | * @param[in] params Common node parameters |
| 277 | * @param[in] input Input to the fully connected layer node as a NodeID-Index pair |
| 278 | * @param[in] num_outputs Number of output neurons |
| 279 | * @param[in] weights_accessor (Optional) Accessor of the weights node data |
| 280 | * @param[in] bias_accessor (Optional) Accessor of the bias node data |
Georgios Pinitas | c55cef1 | 2018-08-01 15:24:18 +0100 | [diff] [blame] | 281 | * @param[in] fc_info (Optional) Fully connected layer metadata |
Georgios Pinitas | 2f1366a | 2018-07-31 16:33:06 +0100 | [diff] [blame] | 282 | * @param[in] weights_quant_info (Optional) Weights quantization info |
| 283 | * @param[in] out_quant_info (Optional) Output quantization info |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 284 | * |
| 285 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 286 | */ |
| 287 | static NodeID add_fully_connected_layer(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_outputs, |
Georgios Pinitas | 2f1366a | 2018-07-31 16:33:06 +0100 | [diff] [blame] | 288 | ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr, |
Georgios Pinitas | c55cef1 | 2018-08-01 15:24:18 +0100 | [diff] [blame] | 289 | const FullyConnectedLayerInfo fc_info = FullyConnectedLayerInfo(), |
Michalis Spyrou | 18574c1 | 2019-06-05 10:51:07 +0100 | [diff] [blame] | 290 | const QuantizationInfo &weights_quant_info = QuantizationInfo(), |
| 291 | const QuantizationInfo &out_quant_info = QuantizationInfo()); |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 292 | /** Adds a generate proposals layer node to the graph |
| 293 | * |
| 294 | * @param[in] g Graph to add the layer to |
| 295 | * @param[in] params Common node parameters |
| 296 | * @param[in] scores Input scores to the generate proposals layer node as a NodeID-Index pair |
| 297 | * @param[in] deltas Input deltas to the generate proposals layer node as a NodeID-Index pair |
| 298 | * @param[in] anchors Input anchors to the generate proposals layer node as a NodeID-Index pair |
| 299 | * @param[in] info Generate proposals operation information |
| 300 | * |
| 301 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 302 | */ |
| 303 | static NodeID add_generate_proposals_node(Graph &g, NodeParams params, NodeIdxPair scores, NodeIdxPair deltas, |
| 304 | NodeIdxPair anchors, GenerateProposalsInfo info); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 305 | /** Adds a normalization layer node to the graph |
| 306 | * |
| 307 | * @param[in] g Graph to add the node to |
| 308 | * @param[in] params Common node parameters |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 309 | * @param[in] input Input to the normalization layer node as a NodeID-Index pair |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 310 | * @param[in] norm_info Normalization layer information |
| 311 | * |
| 312 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 313 | */ |
| 314 | static NodeID add_normalization_node(Graph &g, NodeParams params, NodeIdxPair input, NormalizationLayerInfo norm_info); |
Michele Di Giorgio | 555d110 | 2018-09-12 13:51:59 +0100 | [diff] [blame] | 315 | /** Adds a normalize planar YUV layer node to the graph |
| 316 | * |
| 317 | * @param[in] g Graph to add the node to |
| 318 | * @param[in] params Common node parameters |
| 319 | * @param[in] input Input to the normalize planar YUV layer node as a NodeID-Index pair |
| 320 | * @param[in] mean_accessor Const Node ID that contains the mean values |
| 321 | * @param[in] std_accessor Const Node ID that contains the variance values |
| 322 | * |
| 323 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 324 | */ |
| 325 | static NodeID add_normalize_planar_yuv_node(Graph &g, NodeParams params, NodeIdxPair input, |
| 326 | ITensorAccessorUPtr mean_accessor = nullptr, ITensorAccessorUPtr std_accessor = nullptr); |
Michele Di Giorgio | 4bb1733 | 2018-09-26 13:56:51 +0100 | [diff] [blame] | 327 | /** Adds a pad layer node to the graph |
| 328 | * |
| 329 | * @param[in] g Graph to add the node to |
| 330 | * @param[in] params Common node parameters |
| 331 | * @param[in] input Input to the reshape layer node as a NodeID-Index pair |
| 332 | * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i] |
| 333 | * specifies the front and the end padding in the i-th dimension. |
| 334 | * |
| 335 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 336 | */ |
| 337 | static NodeID add_pad_node(Graph &g, NodeParams params, NodeIdxPair input, PaddingList padding); |
Georgios Pinitas | 57c4824 | 2018-08-02 13:41:49 +0100 | [diff] [blame] | 338 | /** Adds a permute layer node to the graph |
| 339 | * |
| 340 | * @param[in] g Graph to add the node to |
| 341 | * @param[in] params Common node parameters |
| 342 | * @param[in] input Input to the reshape layer node as a NodeID-Index pair |
| 343 | * @param[in] perm Permutation vector |
| 344 | * @param[in] layout (Optional) Data layout to assign to permuted tensor. |
| 345 | * If UNKNOWN then the input's layout will be used. |
| 346 | * |
| 347 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 348 | */ |
| 349 | static NodeID add_permute_node(Graph &g, NodeParams params, NodeIdxPair input, PermutationVector perm, DataLayout layout = DataLayout::UNKNOWN); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 350 | /** Adds a pooling layer node to the graph |
| 351 | * |
| 352 | * @param[in] g Graph to add the node to |
| 353 | * @param[in] params Common node parameters |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 354 | * @param[in] input Input to the pooling layer node as a NodeID-Index pair |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 355 | * @param[in] pool_info Pooling layer information |
| 356 | * |
| 357 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 358 | */ |
| 359 | static NodeID add_pooling_node(Graph &g, NodeParams params, NodeIdxPair input, PoolingLayerInfo pool_info); |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 360 | /** Adds a priorbox 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] input0 First input to the priorbox layer node as a NodeID-Index pair |
| 365 | * @param[in] input1 Second input to the priorbox layer node as a NodeID-Index pair |
| 366 | * @param[in] prior_info PriorBox parameters |
| 367 | * |
| 368 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 369 | */ |
Georgios Pinitas | f52cd78 | 2019-03-25 14:06:14 +0000 | [diff] [blame] | 370 | static NodeID add_priorbox_node(Graph &g, NodeParams params, NodeIdxPair input0, NodeIdxPair input1, const PriorBoxLayerInfo &prior_info); |
Isabella Gottardi | 3db1ba9 | 2019-05-17 12:35:20 +0100 | [diff] [blame] | 371 | /** Adds a quantization layer node to the graph |
| 372 | * |
| 373 | * @param[in] g Graph to add the node to |
| 374 | * @param[in] params Common node parameters |
| 375 | * @param[in] input Input to the quantization layer node as a NodeID-Index pair |
| 376 | * @param[in] out_quant_info Output quantization info |
| 377 | * |
| 378 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 379 | */ |
Michalis Spyrou | 18574c1 | 2019-06-05 10:51:07 +0100 | [diff] [blame] | 380 | static NodeID add_quantization_node(Graph &g, NodeParams params, NodeIdxPair input, const QuantizationInfo &out_quant_info); |
Gian Marco Iodice | 23e2479 | 2018-09-07 15:32:14 +0100 | [diff] [blame] | 381 | /** Adds a reorg layer node to the graph |
| 382 | * |
| 383 | * @param[in] g Graph to add the node to |
| 384 | * @param[in] params Common node parameters |
| 385 | * @param[in] input Input to the reorg layer node as a NodeID-Index pair |
| 386 | * @param[in] stride Stride value to use for reorganizing the values in the output tensor. |
| 387 | * |
| 388 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 389 | */ |
| 390 | static NodeID add_reorg_node(Graph &g, NodeParams params, NodeIdxPair input, int stride); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 391 | /** Adds a reshape layer node to the graph |
| 392 | * |
| 393 | * @param[in] g Graph to add the node to |
| 394 | * @param[in] params Common node parameters |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 395 | * @param[in] input Input to the reshape layer node as a NodeID-Index pair |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 396 | * @param[in] shape Output reshaped shape |
| 397 | * |
| 398 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 399 | */ |
| 400 | static NodeID add_reshape_node(Graph &g, NodeParams params, NodeIdxPair input, TensorShape shape); |
Georgios Pinitas | 087eaf6 | 2018-05-16 15:52:35 +0100 | [diff] [blame] | 401 | /** Adds a resize layer node to the graph |
| 402 | * |
| 403 | * @param[in] g Graph to add the node to |
| 404 | * @param[in] params Common node parameters |
| 405 | * @param[in] input Input to the reshape layer node as a NodeID-Index pair |
| 406 | * @param[in] policy Interpolation policy |
| 407 | * @param[in] width_scale Width scaling factor |
| 408 | * @param[in] height_scale Height scaling factor |
| 409 | * |
| 410 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 411 | */ |
| 412 | static NodeID add_resize_node(Graph &g, NodeParams params, NodeIdxPair input, InterpolationPolicy policy, float width_scale, float height_scale); |
Manuel Bottini | 3f9d4d7 | 2018-10-19 14:04:42 +0100 | [diff] [blame] | 413 | /** Adds a ROI align layer node to the graph |
| 414 | * |
| 415 | * @param[in] g Graph to add the node to |
| 416 | * @param[in] params Common node parameters |
| 417 | * @param[in] input Input to the reshape layer node as a NodeID-Index pair |
Manuel Bottini | cc5171b | 2019-01-09 17:04:39 +0000 | [diff] [blame] | 418 | * @param[in] rois Input containing the ROIs. |
Manuel Bottini | 3f9d4d7 | 2018-10-19 14:04:42 +0100 | [diff] [blame] | 419 | * @param[in] pool_info Contains pooling operation information described in @ref ROIPoolingLayerInfo. |
| 420 | * |
| 421 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 422 | */ |
| 423 | static NodeID add_roi_align_node(Graph &g, NodeParams params, NodeIdxPair input, NodeIdxPair rois, ROIPoolingLayerInfo pool_info); |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 424 | /** Adds a scale layer node to the graph |
| 425 | * This layer computes a product of the input with a scale (read from mul_accessor) and it applies an offset (read from add_accessor). |
| 426 | * output = input * mul_w + add_w |
| 427 | * |
| 428 | * @param[in] g Graph to add the layer to |
| 429 | * @param[in] params Common node parameters |
| 430 | * @param[in] input Input to the fully connected layer node as a NodeID-Index pair |
| 431 | * @param[in] mul_accessor (Optional) Accessor of the mul node data |
| 432 | * @param[in] add_accessor (Optional) Accessor of the add node data |
| 433 | * |
| 434 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 435 | */ |
| 436 | static NodeID add_scale_layer(Graph &g, const NodeParams ¶ms, NodeIdxPair input, |
| 437 | ITensorAccessorUPtr mul_accessor = nullptr, ITensorAccessorUPtr add_accessor = nullptr); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 438 | /** Adds a softmax node to the graph |
| 439 | * |
| 440 | * @param[in] g Graph to add the node to |
| 441 | * @param[in] params Common node parameters |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 442 | * @param[in] input Input to the softmax layer node as a NodeID-Index pair |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 443 | * @param[in] beta Beta parameter |
| 444 | * |
| 445 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 446 | */ |
| 447 | static NodeID add_softmax_node(Graph &g, NodeParams params, NodeIdxPair input, float beta = 1.f); |
Michele Di Giorgio | c30b668 | 2018-09-12 17:44:08 +0100 | [diff] [blame] | 448 | /** Adds a slice 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 slice layer node as a NodeID-Index pair |
| 453 | * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 454 | * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 455 | * |
| 456 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 457 | */ |
| 458 | static NodeID add_slice_node(Graph &g, NodeParams params, NodeIdxPair input, Coordinates &starts, Coordinates &ends); |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 459 | /** Adds a split node to the graph |
| 460 | * |
| 461 | * @param[in] g Graph to add the node to |
| 462 | * @param[in] params Common node parameters |
| 463 | * @param[in] input Input to the split layer node as a NodeID-Index pair |
| 464 | * @param[in] num_splits Number of different splits |
| 465 | * @param[in] axis (Optional) Split axis. Defaults to 0 |
| 466 | * |
| 467 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 468 | */ |
| 469 | static NodeID add_split_node(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_splits, unsigned int axis = 0); |
Michele Di Giorgio | ec69975 | 2019-03-22 15:25:32 +0000 | [diff] [blame] | 470 | /** Adds a stack 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] inputs Inputs to the reorg layer node as a NodeID-Index pair |
| 475 | * @param[in] axis Axis along which the input tensors have to be packed |
| 476 | * |
| 477 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 478 | */ |
| 479 | static NodeID add_stack_node(Graph &g, NodeParams params, const std::vector<NodeIdxPair> &inputs, int axis); |
Michalis Spyrou | 4e1c3f3 | 2018-09-20 17:14:03 +0100 | [diff] [blame] | 480 | /** Adds an upsample layer 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 yolo layer node as a NodeID-Index pair |
| 485 | * @param[in] info Upsample layer stride info |
| 486 | * @param[in] upsampling_policy Upsampling policy used |
| 487 | * |
| 488 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 489 | */ |
| 490 | static NodeID add_upsample_node(Graph &g, NodeParams params, NodeIdxPair input, Size2D info, InterpolationPolicy upsampling_policy); |
Michalis Spyrou | 96f6769 | 2018-09-13 11:39:28 +0100 | [diff] [blame] | 491 | /** Adds a yolo layer to the graph |
| 492 | * |
| 493 | * @param[in] g Graph to add the node to |
| 494 | * @param[in] params Common node parameters |
| 495 | * @param[in] input Input to the yolo layer node as a NodeID-Index pair |
| 496 | * @param[in] act_info Activation layer parameters |
| 497 | * @param[in] num_classes Number of classes to activate |
| 498 | * |
| 499 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 500 | */ |
| 501 | static NodeID add_yolo_node(Graph &g, NodeParams params, NodeIdxPair input, ActivationLayerInfo act_info, int32_t num_classes); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 502 | }; |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 503 | } // namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 504 | } // namespace arm_compute |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 505 | #endif /* __ARM_COMPUTE_GRAPH_GRAPH_BUILDER_H__ */ |