ArmNN
 20.02
INetwork.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include <armnn/Deprecated.hpp>
10 #include <armnn/NetworkFwd.hpp>
11 #include <armnn/Optional.hpp>
12 #include <armnn/TensorFwd.hpp>
13 #include <armnn/Types.hpp>
14 #include <armnn/Deprecated.hpp>
15 
16 #include <memory>
17 #include <vector>
18 
19 namespace armnn
20 {
21 /// @brief An input connection slot for a layer.
22 /// The input slot can be connected to an output slot of the preceding layer in the graph.
23 /// Only one connection to the input slot is allowed.
25 {
26 public:
27  virtual const IOutputSlot* GetConnection() const = 0;
28  virtual IOutputSlot* GetConnection() = 0;
29 
30 protected:
31  /// Not user deletable.
33 };
34 
35 /// @brief An output connection slot for a layer.
36 /// The output slot may be connected to 1 or more input slots of subsequent layers in the graph.
38 {
39 public:
40  virtual unsigned int GetNumConnections() const = 0;
41  virtual const IInputSlot* GetConnection(unsigned int index) const = 0;
42  virtual IInputSlot* GetConnection(unsigned int index) = 0;
43 
44  virtual void SetTensorInfo(const TensorInfo& tensorInfo) = 0;
45  virtual const TensorInfo& GetTensorInfo() const = 0;
46  virtual bool IsTensorInfoSet() const = 0;
47 
48  virtual int Connect(IInputSlot& destination) = 0;
49  virtual void Disconnect(IInputSlot& slot) = 0;
50 
51  virtual unsigned int CalculateIndexOnOwner() const = 0;
52 
53  virtual LayerGuid GetOwningLayerGuid() const = 0;
54 
55 protected:
56  /// Not user deletable.
58 };
59 
60 /// @brief Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
62 {
63 public:
64  /// Returns the name of the layer
65  virtual const char* GetName() const = 0;
66 
67  /// Returns the number of connectable input slots
68  virtual unsigned int GetNumInputSlots() const = 0;
69 
70  /// Returns the number of connectable output slots
71  virtual unsigned int GetNumOutputSlots() const = 0;
72 
73  /// Get a const input slot handle by slot index
74  virtual const IInputSlot& GetInputSlot(unsigned int index) const = 0;
75 
76  /// Get the input slot handle by slot index
77  virtual IInputSlot& GetInputSlot(unsigned int index) = 0;
78 
79  /// Get the const output slot handle by slot index
80  virtual const IOutputSlot& GetOutputSlot(unsigned int index) const = 0;
81 
82  /// Get the output slot handle by slot index
83  virtual IOutputSlot& GetOutputSlot(unsigned int index) = 0;
84 
85  /// Infer the shape of the output(s) based on the provided input shape(s)
86  virtual std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const = 0;
87 
88  /// Returns the unique id of the layer
89  virtual LayerGuid GetGuid() const = 0;
90 
91  /// Apply a visitor to this layer
92  virtual void Accept(ILayerVisitor& visitor) const = 0;
93 
94  /// Provide a hint for the optimizer as to which backend to prefer for this layer
95  virtual void BackendSelectionHint(Optional<BackendId> backend) = 0;
96 protected:
97  /// Objects are not deletable via the handle
99 };
100 
101 using INetworkPtr = std::unique_ptr<INetwork, void(*)(INetwork* network)>;
102 
103 /// Main network class which provides the interface for building up a neural network.
104 /// This object is subsequently required by the IRuntime::Load() method.
105 class INetwork
106 {
107 public:
108  static INetwork* CreateRaw();
109  static INetworkPtr Create();
110  static void Destroy(INetwork* network);
111 
112  virtual Status PrintGraph() = 0;
113 
114  virtual profiling::ProfilingGuid GetGuid() const = 0;
115 
116  /// Adds an input layer to the network.
117  /// @param id - User generated id to uniquely identify a particular input. The same id needs to be specified.
118  /// when passing the inputs to the IRuntime::EnqueueWorkload() function.
119  /// @param name - Optional name for the layer.
120  /// @return - Interface for configuring the layer.
121  virtual IConnectableLayer* AddInputLayer(LayerBindingId id, const char* name = nullptr) = 0;
122 
123  /// Adds an ArgMinMax layer to the network.
124  /// @param desc - Parameters for the L2 normalization operation.
125  /// @param name - Optional name for the layer.
126  /// @return - Interface for configuring the layer.
127  virtual IConnectableLayer* AddArgMinMaxLayer(const ArgMinMaxDescriptor& desc,
128  const char* name = nullptr) = 0;
129 
130  /// Add a Comparison layer to the network.
131  /// @param name - Optional name for the layer.
132  /// @param desc - Descriptor for the comparison operation.
133  /// @ return - Interface for configuring the layer.
134  virtual IConnectableLayer* AddComparisonLayer(const ComparisonDescriptor& comparisonDescriptor,
135  const char* name = nullptr) = 0;
136 
137  /// Adds a concatenation layer to the network.
138  /// @param concatDescriptor - ConcatDescriptor (synonym for OriginsDescriptor) to configure the concatenation
139  /// process. Number of Views must be equal to the number of inputs, and their order
140  /// must match - e.g. first view corresponds to the first input, second view to the
141  /// second input, etc....
142  /// @param name - Optional name for the layer.
143  /// @return - Interface for configuring the layer.
144  virtual IConnectableLayer* AddConcatLayer(const ConcatDescriptor& concatDescriptor,
145  const char* name = nullptr) = 0;
146 
147  /// Adds a 2D convolution layer to the network.
148  /// @param convolution2dDescriptor - Description of the 2D convolution layer.
149  /// @param weights - Tensor for the weights data.
150  /// @param biases - Optional tensor for the bias data. If specified, must match the output tensor shape.
151  /// @param name - Optional name for the layer.
152  /// @return - Interface for configuring the layer.
153  virtual IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
154  const ConstTensor& weights,
155  const Optional<ConstTensor>& biases,
156  const char* name = nullptr) = 0;
157 
158  ARMNN_DEPRECATED_MSG("This AddConvolution2dLayer overload is deprecated")
159  virtual IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
160  const ConstTensor& weights,
161  const char* name = nullptr) = 0;
162 
163  ARMNN_DEPRECATED_MSG("This AddConvolution2dLayer overload is deprecated")
164  virtual IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
165  const ConstTensor& weights,
166  const ConstTensor& biases,
167  const char* name = nullptr) = 0;
168 
169  /// Adds a depth to space layer to the network.
170  /// @param depthToSpaceDescriptor - Parameters for the depth to space operation.
171  /// @param name - Optional name for the layer.
172  /// @return - Interface for configuring the layer.
173  virtual IConnectableLayer* AddDepthToSpaceLayer(const DepthToSpaceDescriptor& depthToSpaceDescriptor,
174  const char* name = nullptr) = 0;
175 
176  /// Adds a 2D depthwise convolution layer to the network.
177  /// @param convolution2dDescriptor - Description of the 2D depthwise convolution layer.
178  /// @param weights - Tensor for the weights. Expected format: [channelMultiplier, inputChannels, height, width].
179  /// @param biases Optional tensor for the bias data. If specified, must match the output tensor shape.
180  /// @param name - Optional name for the layer.
181  /// @return - Interface for configuring the layer.
182  virtual IConnectableLayer* AddDepthwiseConvolution2dLayer(
183  const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
184  const ConstTensor& weights,
185  const Optional<ConstTensor>& biases,
186  const char* name = nullptr) = 0;
187 
188  ARMNN_DEPRECATED_MSG("This AddDepthwiseConvolution2dLayer overload is deprecated")
189  virtual IConnectableLayer* AddDepthwiseConvolution2dLayer(
190  const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
191  const ConstTensor& weights,
192  const char* name = nullptr) = 0;
193 
194  ARMNN_DEPRECATED_MSG("This AddDepthwiseConvolution2dLayer overload is deprecated")
195  virtual IConnectableLayer* AddDepthwiseConvolution2dLayer(
196  const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
197  const ConstTensor& weights,
198  const ConstTensor& biases,
199  const char* name = nullptr) = 0;
200 
201  /// Adds a Dequantize layer to the network.
202  /// @return - Interface for configuring the layer.
203  virtual IConnectableLayer* AddDequantizeLayer(const char* name = nullptr) = 0;
204 
205  /// Adds a Detection PostProcess layer to the network.
206  /// @param descriptor - Description of the Detection PostProcess layer.
207  /// @param anchors - Tensor for anchors.
208  /// @param name - Optional name for the layer.
209  /// @return - Interface for configuring the layer.
210  virtual IConnectableLayer* AddDetectionPostProcessLayer(
211  const DetectionPostProcessDescriptor& descriptor,
212  const ConstTensor& anchors,
213  const char* name = nullptr) = 0;
214 
215  /// Add an ElementwiseUnary layer to the network.
216  /// @param name - Optional name for the layer.
217  /// @param desc - Descriptor for the elementwiseUnary operation.
218  /// @ return - Interface for configuring the layer.
219  virtual IConnectableLayer* AddElementwiseUnaryLayer(const ElementwiseUnaryDescriptor& elementwiseUnaryDescriptor,
220  const char* name = nullptr) = 0;
221 
222  /// Adds a fully connected layer to the network.
223  /// @param fullyConnectedDescriptor - Description of the fully connected layer.
224  /// @param weights - Tensor for the weights data.
225  /// @param biases - Optional tensor for the bias data.
226  /// @param name - Optional name for the layer.
227  /// @return - Interface for configuring the layer.
228  virtual IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
229  const ConstTensor& weights,
230  const Optional<ConstTensor>& biases,
231  const char* name = nullptr) = 0;
232 
233  ARMNN_DEPRECATED_MSG("This AddFullyConnectedLayer overload is deprecated")
234  virtual IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
235  const ConstTensor& weights,
236  const char* name = nullptr) = 0;
237 
238  ARMNN_DEPRECATED_MSG("This AddFullyConnectedLayer overload is deprecated")
239  virtual IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
240  const ConstTensor& weights,
241  const ConstTensor& biases,
242  const char* name = nullptr) = 0;
243 
244  /// Adds a permute layer to the network.
245  /// @param permuteDescriptor - PermuteDescriptor to configure the permute.
246  /// @param name - Optional name for the layer.
247  /// @return - Interface for configuring the layer.
248  virtual IConnectableLayer* AddPermuteLayer(const PermuteDescriptor& permuteDescriptor,
249  const char* name = nullptr) = 0;
250 
251  /// Adds a batch to space ND layer to the network.
252  /// @param batchToSpaceNdDescriptor - Description of the layer.
253  /// @param name - Optional name for the layer.
254  /// @return - Interface for configuring the layer.
255  virtual IConnectableLayer* AddBatchToSpaceNdLayer(const BatchToSpaceNdDescriptor& batchToSpaceNdDescriptor,
256  const char* name = nullptr) = 0;
257 
258  /// Adds a pooling layer to the network.
259  /// @param pooling2dDescriptor - Pooling2dDescriptor to configure the pooling.
260  /// @param name - Optional name for the layer.
261  /// @return - Interface for configuring the layer.
262  virtual IConnectableLayer* AddPooling2dLayer(const Pooling2dDescriptor& pooling2dDescriptor,
263  const char* name = nullptr) = 0;
264 
265  /// Adds an activation layer to the network.
266  /// @param activationDescriptor - ActivationDescriptor to configure the activation.
267  /// @param name - Optional name for the layer.
268  /// @return - Interface for configuring the layer.
269  virtual IConnectableLayer* AddActivationLayer(const ActivationDescriptor& activationDescriptor,
270  const char* name = nullptr) = 0;
271 
272  /// Adds a normalization layer to the network.
273  /// @param normalizationDescriptor - NormalizationDescriptor to configure the normalization.
274  /// @param name - Optional name for the layer.
275  /// @return - Interface for configuring the layer.
276  virtual IConnectableLayer* AddNormalizationLayer(const NormalizationDescriptor& normalizationDescriptor,
277  const char* name = nullptr) = 0;
278 
279  /// Adds a slice layer to the network.
280  /// @param sliceDescriptor - SliceDescriptor to configure the slice operation.
281  /// @param name - Optional name for the layer.
282  /// @return - Interface for configuring the layer.
283  virtual IConnectableLayer* AddSliceLayer(const SliceDescriptor& sliceDescriptor, const char* name = nullptr) = 0;
284 
285  /// Adds a softmax layer to the network.
286  /// If the data type is QAsymm8, then the output quantization parameters
287  /// must have a scale of 1/256 and an offset of 0
288  /// @param softmaxDescriptor - SoftmaxDescriptor to configure the softmax.
289  /// @param name - Optional name for the layer.
290  /// @return - Interface for configuring the layer.
291  virtual IConnectableLayer* AddSoftmaxLayer(const SoftmaxDescriptor& softmaxDescriptor,
292  const char* name = nullptr) = 0;
293 
294  /// Adds a splitter layer to the network.
295  /// @param splitterDescriptor - ViewsDescriptor to configure the splitting process.
296  /// Number of Views must be equal to the number of outputs,
297  /// and their order must match - e.g. first view corresponds to
298  /// the first output, second view to the second output, etc....
299  /// @param name - Optional name for the layer.
300  /// @return - Interface for configuring the layer.
301  virtual IConnectableLayer* AddSplitterLayer(const ViewsDescriptor& splitterDescriptor,
302  const char* name = nullptr) = 0;
303 
304  /// Adds a merge layer to the network.
305  /// @param name - Optional name for the layer.
306  /// @return - Interface for configuring the layer.
307  virtual IConnectableLayer* AddMergeLayer(const char* name = nullptr) = 0;
308 
309  /// Adds a concat layer to the network.
310  /// @param mergerDescriptor - MergerDescriptor (synonym for OriginsDescriptor) to configure the concatenation
311  /// process. Number of Views must be equal to the number of inputs, and their order
312  /// must match - e.g. first view corresponds to the first input, second view to the
313  /// second input, etc....
314  /// @param name - Optional name for the layer.
315  /// @return - Interface for configuring the layer.
316  ARMNN_DEPRECATED_MSG("Use AddConcatLayer instead")
317  virtual IConnectableLayer* AddMergerLayer(const MergerDescriptor& mergerDescriptor,
318  const char* name = nullptr) = 0;
319 
320  /// Add absolute layer to the network.
321  /// @param name - Optional name for the layer.
322  /// @ return - Interface for configuring the layer.
323  ARMNN_DEPRECATED_MSG("Use AddElementwiseUnaryLayer instead")
324  virtual IConnectableLayer* AddAbsLayer(const char* name = nullptr) = 0;
325 
326  /// Adds an addition layer to the network.
327  /// @param name - Optional name for the layer.
328  /// @return - Interface for configuring the layer.
329  virtual IConnectableLayer* AddAdditionLayer(const char* name = nullptr) = 0;
330 
331  /// Adds a multiplication layer to the network.
332  /// @param name - Optional name for the layer.
333  /// @return - Interface for configuring the layer.
334  virtual IConnectableLayer* AddMultiplicationLayer(const char* name = nullptr) = 0;
335 
336  /// Adds a batch normalization layer to the network.
337  /// @param mean - Pre-calculated mean for each channel.
338  /// @param variance - Pre-calculated variance for each channel.
339  /// @param beta - Per-channel additive factor.
340  /// @param gamma - Per-channel multiplicative factor.
341  /// @return - Interface for configuring the layer.
342  /// @param name - Optional name for the layer.
343  virtual IConnectableLayer* AddBatchNormalizationLayer(const BatchNormalizationDescriptor& desc,
344  const ConstTensor& mean,
345  const ConstTensor& variance,
346  const ConstTensor& beta,
347  const ConstTensor& gamma,
348  const char* name = nullptr) = 0;
349 
350  /// Adds a resize bilinear layer to the network.
351  /// @param resizeDesc - Parameters for the resize operation.
352  /// @param name - Optional name for the layer.
353  /// @return - Interface for configuring the layer.
354  ARMNN_DEPRECATED_MSG("Use AddResizeLayer instead")
355  virtual IConnectableLayer* AddResizeBilinearLayer(const ResizeBilinearDescriptor& resizeDesc,
356  const char* name = nullptr) = 0;
357 
358  /// Adds a resize layer to the network.
359  /// @param resizeDescriptor - Parameters for the resize operation.
360  /// @param name - Optional name for the layer.
361  /// @return - Interface for configuring the layer.
362  virtual IConnectableLayer* AddResizeLayer(const ResizeDescriptor& resizeDescriptor,
363  const char* name = nullptr) = 0;
364 
365  /// Adds an instance normalization layer to the network.
366  /// @param desc - Parameters for the instance normalization operation.
367  /// @param name - Optional name for the layer.
368  /// @return - Interface for configuring the layer.
369  virtual IConnectableLayer* AddInstanceNormalizationLayer(const InstanceNormalizationDescriptor& desc,
370  const char* name = nullptr) = 0;
371 
372  /// Adds an L2 normalization layer to the network.
373  /// Normalization is performed along dimension 1, but requires a 4d input.
374  /// @param desc - Parameters for the L2 normalization operation.
375  /// @param name - Optional name for the layer.
376  /// @return - Interface for configuring the layer.
377  virtual IConnectableLayer* AddL2NormalizationLayer(const L2NormalizationDescriptor& desc,
378  const char* name = nullptr) = 0;
379 
380  /// Adds a log softmax layer to the network.
381  /// @param logSoftmaxDescriptor - LogSoftmaxDescriptor to configure the log softmax.
382  /// @param name - Optional name for the layer.
383  /// @return - Interface for configuring the layer.
384  virtual IConnectableLayer* AddLogSoftmaxLayer(const LogSoftmaxDescriptor& logSoftmaxDescriptor,
385  const char* name = nullptr) = 0;
386 
387  /// Adds a layer with no inputs and a single output, which always corresponds to
388  /// the passed in constant tensor.
389  /// @param input - Tensor to be provided as the only output of the layer. The layer will maintain
390  /// its own copy of the tensor data, meaning the memory referenced by @a input can
391  /// be freed or reused after this function is called.
392  /// @param name - Optional name for the layer.
393  /// @return - Interface for configuring the layer.
394  virtual IConnectableLayer* AddConstantLayer(const ConstTensor& input,
395  const char* name = nullptr) = 0;
396 
397  /// Adds a reshape layer to the network.
398  /// @param reshapeDescriptor - Parameters for the reshape operation.
399  /// @param name - Optional name for the layer.
400  /// @return - Interface for configuring the layer.
401  virtual IConnectableLayer* AddReshapeLayer(const ReshapeDescriptor& reshapeDescriptor,
402  const char* name = nullptr) = 0;
403 
404  /// Adds a space to batch layer to the network.
405  /// @param spaceToBatchNdDescriptor - Parameters for the space to batch operation.
406  /// @param name - Optional name for the layer.
407  /// @return - Interface for configuring the layer.
408  virtual IConnectableLayer* AddSpaceToBatchNdLayer(const SpaceToBatchNdDescriptor& spaceToBatchNdDescriptor,
409  const char* name = nullptr) = 0;
410 
411  /// Adds a space to depth layer to the network.
412  /// @param spaceToDepthDescriptor - Parameters for the space to depth operation.
413  /// @param name - Optional name for the layer.
414  /// @return - Interface for configuring the layer.
415  virtual IConnectableLayer* AddSpaceToDepthLayer(const SpaceToDepthDescriptor& spaceToDepthDescriptor,
416  const char* name = nullptr) = 0;
417 
418  /// Adds a floor layer to the network.
419  /// @param name - Optional name for the layer.
420  /// @return - Interface for configuring the layer.
421  virtual IConnectableLayer* AddFloorLayer(const char* name = nullptr) = 0;
422 
423  /// Adds an output layer to the network.
424  /// @param id - User generated id to uniquely identify a particular output. The same id needs to be specified
425  /// when passing the outputs to the IRuntime::EnqueueWorkload() function.
426  /// @param name - Optional name for the layer.
427  /// @return - Interface for configuring the layer.
428  virtual IConnectableLayer* AddOutputLayer(LayerBindingId id, const char* name = nullptr) = 0;
429 
430  /// Add a Lstm layer to the network
431  /// @param descriptor - Parameters for the Lstm operation
432  /// @param params - Weights and biases for the LSTM cell
433  /// @param name - Optional name for the layer
434  /// @return - Interface for configuring the layer.
435  virtual IConnectableLayer* AddLstmLayer(const LstmDescriptor& descriptor,
436  const LstmInputParams& params,
437  const char* name = nullptr) = 0;
438 
439  /// Adds a division layer to the network.
440  /// @param name - Optional name for the layer.
441  /// @return - Interface for configuring the layer.
442  virtual IConnectableLayer* AddDivisionLayer(const char* name = nullptr) = 0;
443 
444  /// Adds a subtraction layer to the network.
445  /// @param name - Optional name for the layer.
446  /// @return - Interface for configuring the layer.
447  virtual IConnectableLayer* AddSubtractionLayer(const char* name = nullptr) = 0;
448 
449  /// Add a Maximum layer to the network.
450  /// @param name - Optional name for the layer.
451  /// @ return - Interface for configuring the layer.
452  virtual IConnectableLayer* AddMaximumLayer(const char* name = nullptr) = 0;
453 
454  /// Add a Mean layer to the network.
455  /// @param meanDescriptor - Parameters for the mean operation.
456  /// @param name - Optional name for the layer.
457  /// @ return - Interface for configuring the layer.
458  virtual IConnectableLayer* AddMeanLayer(const MeanDescriptor& meanDescriptor, const char* name = nullptr) = 0;
459 
460  /// Adds a fully pad layer to the network.
461  /// @param paddings - n by 2 tensor, where n is the rank of the input tensor,
462  /// such that paddings[i,0] indicates the amount of padding to add in front of dimonsion i, and
463  /// paddings[i,1] indicates the amount of padding to add after the end of dimension i
464  /// @param name - Optional name for the layer.
465  /// @return - Interface for configuring the layer.
466  virtual IConnectableLayer* AddPadLayer(const PadDescriptor& padDescriptor,
467  const char* name = nullptr) = 0;
468 
469  /// Add a quantize layer to the network
470  ///@param name - Optional name for the layer.
471  /// @return - Interface for configuring the layer.
472  virtual IConnectableLayer* AddQuantizeLayer(const char* name = nullptr) = 0;
473 
474  /// Adds a strided slice layer to the network.
475  /// @param StridedSliceDescriptor - Parameters for the strided slice operation.
476  /// @param name - Optional name for the layer.
477  /// @return - Interface for configuring the layer.
478  virtual IConnectableLayer* AddStridedSliceLayer(const StridedSliceDescriptor& stridedSliceDescriptor,
479  const char* name = nullptr) = 0;
480 
481  /// Add a Minimum layer to the network.
482  /// @param name - Optional name for the layer.
483  /// @ return - Interface for configuring the layer.
484  virtual IConnectableLayer* AddMinimumLayer(const char* name = nullptr) = 0;
485 
486  /// Add a Greater layer to the network.
487  /// @param name - Optional name for the layer.
488  /// @ return - Interface for configuring the layer.
489  ARMNN_DEPRECATED_MSG("Use AddComparisonLayer instead")
490  virtual IConnectableLayer* AddGreaterLayer(const char* name = nullptr) = 0;
491 
492  /// Add a Equal layer to the network.
493  /// @param name - Optional name for the layer.
494  /// @ return - Interface for configuring the layer.
495  ARMNN_DEPRECATED_MSG("Use AddComparisonLayer instead")
496  virtual IConnectableLayer* AddEqualLayer(const char* name = nullptr) = 0;
497 
498  /// Add Reciprocal of square root layer to the network.
499  /// @param name - Optional name for the layer.
500  /// @ return - Interface for configuring the layer.
501  ARMNN_DEPRECATED_MSG("Use AddElementwiseUnaryLayer instead")
502  virtual IConnectableLayer* AddRsqrtLayer(const char* name = nullptr) = 0;
503 
504  /// Add Gather layer to the network.
505  /// @param name - Optional name for the layer.
506  /// @ return - Interface for configuring the layer.
507  virtual IConnectableLayer* AddGatherLayer(const char* name = nullptr) = 0;
508 
509  /// Adds a switch layer to the network.
510  /// @param name - Optional name for the layer.
511  /// @return - Interface for configuring the layer.
512  virtual IConnectableLayer* AddSwitchLayer(const char* name = nullptr) = 0;
513 
514  /// Adds a PReLU layer to the network.
515  /// @param name - Optional name for the layer.
516  /// @return - Interface for configuring the layer.
517  virtual IConnectableLayer* AddPreluLayer(const char* name = nullptr) = 0;
518 
519  /// Adds a 2D transpose convolution layer to the network.
520  /// @param descriptor - Description of the 2D transpose convolution layer.
521  /// @param weights - Tensor for the weights data.
522  /// @param biases - Optional tensor for the bias data.
523  /// @param name - Optional name for the layer.
524  /// @return - Interface for configuring the layer.
525  virtual IConnectableLayer* AddTransposeConvolution2dLayer(const TransposeConvolution2dDescriptor& descriptor,
526  const ConstTensor& weights,
527  const Optional<ConstTensor>& biases,
528  const char* name = nullptr) = 0;
529 
530  /// Adds a transpose layer to the network.
531  /// @param transposeDescriptor - TransposeDescriptor to configure the transpose.
532  /// @param name - Optional name for the layer.
533  /// @return - Interface for configuring the layer.
534  virtual IConnectableLayer* AddTransposeLayer(const TransposeDescriptor& transposeDescriptor,
535  const char* name = nullptr) = 0;
536 
537  /// Adds a stack layer to the network.
538  /// @param descriptor - Description of the stack layer.
539  /// @param name - Optional name for the layer.
540  /// @return - Interface for configuring the layer.
541  virtual IConnectableLayer* AddStackLayer(const StackDescriptor& descriptor,
542  const char* name = nullptr) = 0;
543 
544  /// Add a stand-in layer for a type unknown to the Arm NN framework.
545  /// Note: Due to the nature of this layer, no validation can be performed by the framework.
546  /// Furthermore, Any model containing this layer cannot make use of dynamic tensors since the
547  /// tensor sizes cannot be inferred.
548  /// @descriptor - Descriptor for the StandIn layer.
549  /// @return - Interface for configuring the layer.
550  virtual IConnectableLayer* AddStandInLayer(const StandInDescriptor& descriptor,
551  const char* name = nullptr) = 0;
552 
553  /// Add a QuantizedLstm layer to the network
554  /// @param params - The weights and biases for the Quantized LSTM cell
555  /// @param name - Optional name for the layer
556  /// @return - Interface for configuring the layer.
557  virtual IConnectableLayer* AddQuantizedLstmLayer(const QuantizedLstmInputParams& params,
558  const char* name = nullptr) = 0;
559 
560  virtual void Accept(ILayerVisitor& visitor) const = 0;
561 
562 protected:
564 };
565 
566 using IOptimizedNetworkPtr = std::unique_ptr<IOptimizedNetwork, void(*)(IOptimizedNetwork* network)>;
567 
569 {
570 public:
571  static void Destroy(IOptimizedNetwork* network);
572 
573  virtual Status PrintGraph() = 0;
574  virtual Status SerializeToDot(std::ostream& stream) const = 0;
575 
576  virtual profiling::ProfilingGuid GetGuid() const = 0;
577 
578 protected:
580 };
581 
583 {
585  : m_ReduceFp32ToFp16(false)
586  , m_Debug(false)
587  {}
588 
589  OptimizerOptions(bool reduceFp32ToFp16, bool debug)
590  : m_ReduceFp32ToFp16(reduceFp32ToFp16)
591  , m_Debug(debug)
592  {}
593 
594  // Reduce Fp32 data to Fp16 for faster processing
596 
597  // Add debug data for easier troubleshooting
598  bool m_Debug;
599 };
600 
601 /// Create an optimized version of the network
602 /// @param network INetwork description of the network to be optimized.
603 /// @param backendPreferences The choice of the backend ordered by user preferences.
604 /// @param deviceSpec DeviceSpec object as queried from the runtime. See IRuntime::GetDeviceSpec()
605 /// @param messages If there are failures or warnings a string describing same will be added to the vector
606 /// @param options OptimizerOptions object with optimizer configuration options
607 /// @return An IOptimizedNetworkPtr interface to the optimized network, throws an exception derived from
608 /// armnn::Exception if process fails.
609 
610 IOptimizedNetworkPtr Optimize(const INetwork& network,
611  const std::vector<BackendId>& backendPreferences,
612  const IDeviceSpec& deviceSpec,
614  Optional<std::vector<std::string>&> messages = EmptyOptional());
615 } //namespace armnn
A ViewsDescriptor for the SplitterLayer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
~IConnectableLayer()
Objects are not deletable via the handle.
Definition: INetwork.hpp:98
A ReshapeDescriptor for the ReshapeLayer.
A ComparisonDescriptor for the ComparisonLayer.
Definition: Descriptors.hpp:62
A Convolution2dDescriptor for the Convolution2dLayer.
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers
Main network class which provides the interface for building up a neural network. ...
Definition: INetwork.hpp:105
Copyright (c) 2020 ARM Limited.
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
DataLayout::NHWC false
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
Definition: Types.hpp:171
A ResizeDescriptor for the ResizeLayer.
A StackDescriptor for the StackLayer.
A PadDescriptor for the PadLayer.
An LstmDescriptor for the LstmLayer.
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
Definition: Network.cpp:890
An output connection slot for a layer.
Definition: INetwork.hpp:37
A L2NormalizationDescriptor for the L2NormalizationLayer.
An ArgMinMaxDescriptor for ArgMinMaxLayer.
Definition: Descriptors.hpp:43
An OriginsDescriptor for the ConcatLayer.
OptimizerOptions(bool reduceFp32ToFp16, bool debug)
Definition: INetwork.hpp:589
A FullyConnectedDescriptor for the FullyConnectedLayer.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:199
Status
enumeration
Definition: Types.hpp:26
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Definition: INetwork.hpp:566
A StandInDescriptor for the StandIn layer.
Device specific knowledge to be passed to the optimizer.
Definition: Types.hpp:161
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:20
A SliceDescriptor for the SliceLayer.
armnnUtils::Sockets::Socket Accept(Socket s, sockaddr *addr, socklen_t *addrlen, int flags)
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
Definition: Optional.hpp:32
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
Definition: Descriptors.hpp:82
~IInputSlot()
Not user deletable.
Definition: INetwork.hpp:32
A MeanDescriptor for the MeanLayer.
virtual const IOutputSlot * GetConnection() const =0
A TransposeDescriptor for the TransposeLayer.
A StridedSliceDescriptor for the StridedSliceLayer.
void Connect(armnn::IConnectableLayer *from, armnn::IConnectableLayer *to, const armnn::TensorInfo &tensorInfo, unsigned int fromIndex, unsigned int toIndex)
Definition: TestUtils.cpp:12
#define ARMNN_DEPRECATED_MSG(message)
Definition: Deprecated.hpp:43
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:101
~IOutputSlot()
Not user deletable.
Definition: INetwork.hpp:57
A Pooling2dDescriptor for the Pooling2dLayer.
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
A NormalizationDescriptor for the NormalizationLayer.
An InstanceNormalizationDescriptor for InstanceNormalizationLayer.
A ResizeBilinearDescriptor for the ResizeBilinearLayer.
A SoftmaxDescriptor for the SoftmaxLayer.
An input connection slot for a layer.
Definition: INetwork.hpp:24
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
A PermuteDescriptor for the PermuteLayer.
std::vector< float > anchors({ 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 10.5f, 1.0f, 1.0f, 0.5f, 10.5f, 1.0f, 1.0f, 0.5f, 100.5f, 1.0f, 1.0f })