Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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 | */ |
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" |
| 28 | #include "arm_compute/graph/Types.h" |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 29 | |
| 30 | namespace arm_compute |
| 31 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 32 | namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 33 | { |
| 34 | // Forward declaration |
| 35 | class Graph; |
| 36 | |
| 37 | /** Graph builder class |
| 38 | * |
| 39 | * Builds and compiles a graph |
| 40 | */ |
| 41 | class GraphBuilder final |
| 42 | { |
| 43 | public: |
| 44 | /** Adds a Const node to the graph |
| 45 | * |
| 46 | * @param[in] g Graph to add the node to |
| 47 | * @param[in] params Common node parameters |
| 48 | * @param[in] desc Tensor descriptor of the node |
| 49 | * @param[in] accessor (Optional) Accessor of the const node data |
| 50 | * |
| 51 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 52 | */ |
| 53 | static NodeID add_const_node(Graph &g, NodeParams params, TensorDescriptor desc, ITensorAccessorUPtr accessor = nullptr); |
| 54 | /** Adds an input layer node to the graph |
| 55 | * |
| 56 | * @param[in] g Graph to add the node to |
| 57 | * @param[in] params Common node parameters |
| 58 | * @param[in] desc Tensor descriptor of the Tensor |
| 59 | * @param[in] accessor (Optional) Accessor of the input node data |
| 60 | * |
| 61 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 62 | */ |
| 63 | static NodeID add_input_node(Graph &g, NodeParams params, TensorDescriptor desc, ITensorAccessorUPtr accessor = nullptr); |
| 64 | /** Adds an output layer node to the graph |
| 65 | * |
| 66 | * @param[in] g Graph to add the node to |
| 67 | * @param[in] params Common node parameters |
| 68 | * @param[in] input Input to the output node as a NodeID-Index pair |
| 69 | * @param[in] accessor (Optional) Accessor of the output node data |
| 70 | * |
| 71 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 72 | */ |
| 73 | static NodeID add_output_node(Graph &g, NodeParams params, NodeIdxPair input, ITensorAccessorUPtr accessor = nullptr); |
| 74 | /** Adds an activation layer node to the graph |
| 75 | * |
| 76 | * @param[in] g Graph to add the node to |
| 77 | * @param[in] params Common node parameters |
| 78 | * @param[in] input Input to the activation layer node as a NodeID-Index pair |
| 79 | * @param[in] act_info Activation layer information |
| 80 | * |
| 81 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 82 | */ |
| 83 | static NodeID add_activation_node(Graph &g, NodeParams params, NodeIdxPair input, ActivationLayerInfo act_info); |
| 84 | /** Adds a batch normalization layer node to the graph |
| 85 | * |
| 86 | * @param[in] g Graph to add the node to |
| 87 | * @param[in] params Common node parameters |
| 88 | * @param[in] input Input to the batch normalization layer node as a NodeID-Index pair |
| 89 | * @param[in] epsilon Epsilon parameter |
| 90 | * @param[in] mean_accessor Const Node ID that contains the mean values |
| 91 | * @param[in] var_accessor Const Node ID that contains the variance values |
| 92 | * @param[in] beta_accessor Const Node ID that contains the beta values. Can be EmptyNodeID |
| 93 | * @param[in] gamma_accessor Const Node ID that contains the gamma values. Can be EmptyNodeID |
| 94 | * |
| 95 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 96 | */ |
| 97 | static NodeID add_batch_normalization_node(Graph &g, NodeParams params, NodeIdxPair input, float epsilon, |
| 98 | ITensorAccessorUPtr mean_accessor = nullptr, ITensorAccessorUPtr var_accessor = nullptr, |
| 99 | ITensorAccessorUPtr beta_accessor = nullptr, ITensorAccessorUPtr gamma_accessor = nullptr); |
Georgios Pinitas | 087eaf6 | 2018-05-16 15:52:35 +0100 | [diff] [blame] | 100 | /** Adds an channel shuffle layer node to the graph |
| 101 | * |
| 102 | * @param[in] g Graph to add the node to |
| 103 | * @param[in] params Common node parameters |
| 104 | * @param[in] input Input to the activation layer node as a NodeID-Index pair |
| 105 | * @param[in] num_groups Number of groups |
| 106 | * |
| 107 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 108 | */ |
| 109 | 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] | 110 | /** Adds a convolution layer node to the graph |
| 111 | * |
Giorgio Arena | 59631a1 | 2018-05-02 13:59:04 +0100 | [diff] [blame] | 112 | * TODO (COMPMID-1113): Add a graph descriptor for convolution layer node |
| 113 | * |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 114 | * @param[in] g Graph to add the node to |
| 115 | * @param[in] params Common node parameters |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 116 | * @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] | 117 | * @param[in] kernel_spatial_extend Spatial extend of convolution kernels |
| 118 | * @param[in] depth Number of convolution kernels |
| 119 | * @param[in] conv_info Convolution layer information |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 120 | * @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] | 121 | * @param[in] method (Optional) Convolution method to use |
Giorgio Arena | 59631a1 | 2018-05-02 13:59:04 +0100 | [diff] [blame] | 122 | * @param[in] fast_math_hint (Optional) Fast math hint |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 123 | * @param[in] weights_accessor (Optional) Accessor of the weights node data |
| 124 | * @param[in] bias_accessor (Optional) Accessor of the bias node data |
Giorgio Arena | bb54e4e | 2018-04-05 17:20:34 +0100 | [diff] [blame] | 125 | * @param[in] weights_quant_info (Optional) Weights quantization info |
| 126 | * @param[in] out_quant_info (Optional) Output quantization info |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 127 | * |
| 128 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 129 | */ |
| 130 | static NodeID add_convolution_node(Graph &g, NodeParams params, NodeIdxPair input, |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 131 | Size2D kernel_spatial_extend, unsigned int depth, PadStrideInfo conv_info, unsigned int num_groups = 1, |
| 132 | ConvolutionMethod method = ConvolutionMethod::Default, FastMathHint fast_math_hint = FastMathHint::Disabled, |
Giorgio Arena | bb54e4e | 2018-04-05 17:20:34 +0100 | [diff] [blame] | 133 | ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr, |
| 134 | const QuantizationInfo weights_quant_info = QuantizationInfo(), |
| 135 | const QuantizationInfo out_quant_info = QuantizationInfo()); |
Georgios Pinitas | 087eaf6 | 2018-05-16 15:52:35 +0100 | [diff] [blame] | 136 | /** Adds a deconvolution layer node to the graph |
| 137 | * |
| 138 | * @param[in] g Graph to add the node to |
| 139 | * @param[in] params Common node parameters |
| 140 | * @param[in] input Input to the convolution layer node as a NodeID-Index pair |
| 141 | * @param[in] kernel_spatial_extend Spatial extend of convolution kernels |
| 142 | * @param[in] depth Number of convolution kernels |
| 143 | * @param[in] deconv_info Convolution layer information |
| 144 | * @param[in] inner_border Inner border (right, top) |
| 145 | * @param[in] weights_accessor (Optional) Accessor of the weights node data |
| 146 | * @param[in] bias_accessor (Optional) Accessor of the bias node data |
| 147 | * |
| 148 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 149 | */ |
| 150 | static NodeID add_deconvolution_node(Graph &g, NodeParams params, NodeIdxPair input, |
| 151 | Size2D kernel_spatial_extend, unsigned int depth, PadStrideInfo deconv_info, Size2D inner_border, |
| 152 | ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 153 | /** Adds a depth concatenate node to the graph |
| 154 | * |
| 155 | * @param[in] g Graph to add the node to |
| 156 | * @param[in] params Common node parameters |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 157 | * @param[in] inputs Inputs to the depth concatenate layer node as a NodeID-Index pair |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 158 | * @param[in] axis Concatenation axis |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 159 | * |
| 160 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 161 | */ |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 162 | static NodeID add_concatenate_node(Graph &g, NodeParams params, std::vector<NodeIdxPair> inputs, DataLayoutDimension axis); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 163 | /** Adds a depth-wise convolution layer node to the graph |
| 164 | * |
| 165 | * @param[in] g Graph to add the node to |
| 166 | * @param[in] params Common node parameters |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 167 | * @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] | 168 | * @param[in] kernel_spatial_extend Spatial extend of convolution kernels |
| 169 | * @param[in] conv_info Convolution layer information |
| 170 | * @param[in] method (Optional) Convolution method to use |
| 171 | * @param[in] weights_accessor (Optional) Accessor of the weights node data |
| 172 | * @param[in] bias_accessor (Optional) Accessor of the bias node data |
Giorgio Arena | bb54e4e | 2018-04-05 17:20:34 +0100 | [diff] [blame] | 173 | * @param[in] quant_info (Optional) Weights quantization info |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 174 | * |
| 175 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 176 | */ |
| 177 | static NodeID add_depthwise_convolution_node(Graph &g, NodeParams params, NodeIdxPair input, |
| 178 | Size2D kernel_spatial_extend, PadStrideInfo conv_info, |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 179 | DepthwiseConvolutionMethod method = DepthwiseConvolutionMethod::Default, |
Giorgio Arena | bb54e4e | 2018-04-05 17:20:34 +0100 | [diff] [blame] | 180 | ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr, const QuantizationInfo quant_info = QuantizationInfo()); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 181 | /** Adds an element-wise layer 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] input0 First input to the element-wise operation layer node as a NodeID-Index pair |
| 186 | * @param[in] input1 Second input to the element-wise operation layer node as a NodeID-Index pair |
| 187 | * @param[in] operation Element-wise operation to perform |
| 188 | * |
| 189 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 190 | */ |
| 191 | static NodeID add_elementwise_node(Graph &g, NodeParams params, NodeIdxPair input0, NodeIdxPair input1, EltwiseOperation operation); |
Georgios Pinitas | 087eaf6 | 2018-05-16 15:52:35 +0100 | [diff] [blame] | 192 | /** Adds a Dummy node to the graph |
| 193 | * |
| 194 | * @note this node if for debugging purposes. Just alters the shape of the graph pipeline as requested. |
| 195 | * |
| 196 | * @param[in] g Graph to add the node to |
| 197 | * @param[in] params Common node parameters |
| 198 | * @param[in] input Input to the dummy node as a NodeID-Index pair |
| 199 | * @param[in] shape Output shape |
| 200 | * |
| 201 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 202 | */ |
| 203 | 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] | 204 | /** Adds a flatten layer node to the graph |
| 205 | * |
| 206 | * @param[in] g Graph to add the node to |
| 207 | * @param[in] params Common node parameters |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 208 | * @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] | 209 | * |
| 210 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 211 | */ |
| 212 | static NodeID add_flatten_node(Graph &g, NodeParams params, NodeIdxPair input); |
| 213 | /** Adds a fully connected layer node to the graph |
| 214 | * |
Georgios Pinitas | 2f1366a | 2018-07-31 16:33:06 +0100 | [diff] [blame] | 215 | * @param[in] g Graph to add the layer to |
| 216 | * @param[in] params Common node parameters |
| 217 | * @param[in] input Input to the fully connected layer node as a NodeID-Index pair |
| 218 | * @param[in] num_outputs Number of output neurons |
| 219 | * @param[in] weights_accessor (Optional) Accessor of the weights node data |
| 220 | * @param[in] bias_accessor (Optional) Accessor of the bias node data |
Georgios Pinitas | c55cef1 | 2018-08-01 15:24:18 +0100 | [diff] [blame] | 221 | * @param[in] fc_info (Optional) Fully connected layer metadata |
Georgios Pinitas | 2f1366a | 2018-07-31 16:33:06 +0100 | [diff] [blame] | 222 | * @param[in] weights_quant_info (Optional) Weights quantization info |
| 223 | * @param[in] out_quant_info (Optional) Output quantization info |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 224 | * |
| 225 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 226 | */ |
| 227 | 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] | 228 | ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr, |
Georgios Pinitas | c55cef1 | 2018-08-01 15:24:18 +0100 | [diff] [blame] | 229 | const FullyConnectedLayerInfo fc_info = FullyConnectedLayerInfo(), |
| 230 | const QuantizationInfo weights_quant_info = QuantizationInfo(), |
| 231 | const QuantizationInfo out_quant_info = QuantizationInfo()); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 232 | /** Adds a normalization layer node to the graph |
| 233 | * |
| 234 | * @param[in] g Graph to add the node to |
| 235 | * @param[in] params Common node parameters |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 236 | * @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] | 237 | * @param[in] norm_info Normalization layer information |
| 238 | * |
| 239 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 240 | */ |
| 241 | 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] | 242 | /** Adds a normalize planar YUV 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 Input to the normalize planar YUV layer node as a NodeID-Index pair |
| 247 | * @param[in] mean_accessor Const Node ID that contains the mean values |
| 248 | * @param[in] std_accessor Const Node ID that contains the variance values |
| 249 | * |
| 250 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 251 | */ |
| 252 | static NodeID add_normalize_planar_yuv_node(Graph &g, NodeParams params, NodeIdxPair input, |
| 253 | ITensorAccessorUPtr mean_accessor = nullptr, ITensorAccessorUPtr std_accessor = nullptr); |
Michele Di Giorgio | 4bb1733 | 2018-09-26 13:56:51 +0100 | [diff] [blame] | 254 | /** Adds a pad 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 Input to the reshape layer node as a NodeID-Index pair |
| 259 | * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i] |
| 260 | * specifies the front and the end padding in the i-th dimension. |
| 261 | * |
| 262 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 263 | */ |
| 264 | 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] | 265 | /** Adds a permute layer node to the graph |
| 266 | * |
| 267 | * @param[in] g Graph to add the node to |
| 268 | * @param[in] params Common node parameters |
| 269 | * @param[in] input Input to the reshape layer node as a NodeID-Index pair |
| 270 | * @param[in] perm Permutation vector |
| 271 | * @param[in] layout (Optional) Data layout to assign to permuted tensor. |
| 272 | * If UNKNOWN then the input's layout will be used. |
| 273 | * |
| 274 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 275 | */ |
| 276 | 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] | 277 | /** Adds a pooling layer node to the graph |
| 278 | * |
| 279 | * @param[in] g Graph to add the node to |
| 280 | * @param[in] params Common node parameters |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 281 | * @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] | 282 | * @param[in] pool_info Pooling layer information |
| 283 | * |
| 284 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 285 | */ |
| 286 | static NodeID add_pooling_node(Graph &g, NodeParams params, NodeIdxPair input, PoolingLayerInfo pool_info); |
Gian Marco Iodice | 23e2479 | 2018-09-07 15:32:14 +0100 | [diff] [blame] | 287 | /** Adds a reorg layer node to the graph |
| 288 | * |
| 289 | * @param[in] g Graph to add the node to |
| 290 | * @param[in] params Common node parameters |
| 291 | * @param[in] input Input to the reorg layer node as a NodeID-Index pair |
| 292 | * @param[in] stride Stride value to use for reorganizing the values in the output tensor. |
| 293 | * |
| 294 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 295 | */ |
| 296 | 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] | 297 | /** Adds a reshape layer node to the graph |
| 298 | * |
| 299 | * @param[in] g Graph to add the node to |
| 300 | * @param[in] params Common node parameters |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 301 | * @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] | 302 | * @param[in] shape Output reshaped shape |
| 303 | * |
| 304 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 305 | */ |
| 306 | 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] | 307 | /** Adds a resize layer node to the graph |
| 308 | * |
| 309 | * @param[in] g Graph to add the node to |
| 310 | * @param[in] params Common node parameters |
| 311 | * @param[in] input Input to the reshape layer node as a NodeID-Index pair |
| 312 | * @param[in] policy Interpolation policy |
| 313 | * @param[in] width_scale Width scaling factor |
| 314 | * @param[in] height_scale Height scaling factor |
| 315 | * |
| 316 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 317 | */ |
| 318 | static NodeID add_resize_node(Graph &g, NodeParams params, NodeIdxPair input, InterpolationPolicy policy, float width_scale, float height_scale); |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 319 | /** Adds a scale layer node to the graph |
| 320 | * This layer computes a product of the input with a scale (read from mul_accessor) and it applies an offset (read from add_accessor). |
| 321 | * output = input * mul_w + add_w |
| 322 | * |
| 323 | * @param[in] g Graph to add the layer to |
| 324 | * @param[in] params Common node parameters |
| 325 | * @param[in] input Input to the fully connected layer node as a NodeID-Index pair |
| 326 | * @param[in] mul_accessor (Optional) Accessor of the mul node data |
| 327 | * @param[in] add_accessor (Optional) Accessor of the add node data |
| 328 | * |
| 329 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 330 | */ |
| 331 | static NodeID add_scale_layer(Graph &g, const NodeParams ¶ms, NodeIdxPair input, |
| 332 | ITensorAccessorUPtr mul_accessor = nullptr, ITensorAccessorUPtr add_accessor = nullptr); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 333 | /** Adds a softmax node to the graph |
| 334 | * |
| 335 | * @param[in] g Graph to add the node to |
| 336 | * @param[in] params Common node parameters |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 337 | * @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] | 338 | * @param[in] beta Beta parameter |
| 339 | * |
| 340 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 341 | */ |
| 342 | 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] | 343 | /** Adds a slice node to the graph |
| 344 | * |
| 345 | * @param[in] g Graph to add the node to |
| 346 | * @param[in] params Common node parameters |
| 347 | * @param[in] input Input to the slice layer node as a NodeID-Index pair |
| 348 | * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 349 | * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). |
| 350 | * |
| 351 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 352 | */ |
| 353 | 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] | 354 | /** Adds a split node to the graph |
| 355 | * |
| 356 | * @param[in] g Graph to add the node to |
| 357 | * @param[in] params Common node parameters |
| 358 | * @param[in] input Input to the split layer node as a NodeID-Index pair |
| 359 | * @param[in] num_splits Number of different splits |
| 360 | * @param[in] axis (Optional) Split axis. Defaults to 0 |
| 361 | * |
| 362 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 363 | */ |
| 364 | static NodeID add_split_node(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_splits, unsigned int axis = 0); |
Michalis Spyrou | 4e1c3f3 | 2018-09-20 17:14:03 +0100 | [diff] [blame] | 365 | /** Adds an upsample layer to the graph |
| 366 | * |
| 367 | * @param[in] g Graph to add the node to |
| 368 | * @param[in] params Common node parameters |
| 369 | * @param[in] input Input to the yolo layer node as a NodeID-Index pair |
| 370 | * @param[in] info Upsample layer stride info |
| 371 | * @param[in] upsampling_policy Upsampling policy used |
| 372 | * |
| 373 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 374 | */ |
| 375 | 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] | 376 | /** Adds a yolo layer to the graph |
| 377 | * |
| 378 | * @param[in] g Graph to add the node to |
| 379 | * @param[in] params Common node parameters |
| 380 | * @param[in] input Input to the yolo layer node as a NodeID-Index pair |
| 381 | * @param[in] act_info Activation layer parameters |
| 382 | * @param[in] num_classes Number of classes to activate |
| 383 | * |
| 384 | * @return Node ID of the created node, EmptyNodeID in case of error |
| 385 | */ |
| 386 | 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] | 387 | }; |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 388 | } // namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 389 | } // namespace arm_compute |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 390 | #endif /* __ARM_COMPUTE_GRAPH_GRAPH_BUILDER_H__ */ |