blob: 3e3a36570ee0612784d54f228439185498d36ec6 [file] [log] [blame]
Richard Burtondc0c6ed2020-04-08 16:39:05 +01001//
2// Copyright © 2020 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5%{
6#include "armnn/INetwork.hpp"
7#include "armnn/BackendId.hpp"
8#include "armnn/Types.hpp"
9#include "armnn/Optional.hpp"
10#include <fstream>
11%}
12
13%include <typemaps/network_optimize.i>
alexander73010782021-10-18 19:17:24 +010014%include <typemaps/model_options.i>
15
16namespace std {
17 %template() std::vector<armnn::BackendOptions>;
18}
Richard Burtondc0c6ed2020-04-08 16:39:05 +010019
20namespace armnn
21{
22%feature("docstring",
23"
24Struct for holding options relating to the Arm NN optimizer. See `Optimize`.
25
26Contains:
27 m_debug (bool): Add debug data for easier troubleshooting.
Jan Eilers841aca12020-08-12 14:59:06 +010028 m_ReduceFp32ToBf16 (bool): Reduces Fp32 network to BFloat16 (Bf16) for faster processing. Layers
29 that can not be reduced will be left in Fp32.
30 m_ReduceFp32ToFp16 (bool): Reduces Fp32 network to Fp16 for faster processing. Layers
31 that can not be reduced will be left in Fp32.
alexander73010782021-10-18 19:17:24 +010032 m_ImportEnabled (bool): Enable memory import.
33 m_shapeInferenceMethod: The ShapeInferenceMethod modifies how the output shapes are treated.
34 When ValidateOnly is selected, the output shapes are inferred from the input parameters
35 of the layer and any mismatch is reported.
36 When InferAndValidate is selected 2 actions are performed: (1)infer output shape from
37 inputs and (2)validate the shapes as in ValidateOnly. This option has been added to work
38 with tensors which rank or dimension sizes are not specified explicitly, however this
39 information can be calculated from the inputs.
40 m_ModelOptions: List of backends optimisation options.
Richard Burtondc0c6ed2020-04-08 16:39:05 +010041
42") OptimizerOptions;
alexander73010782021-10-18 19:17:24 +010043
44%model_options_typemap;
Richard Burtondc0c6ed2020-04-08 16:39:05 +010045struct OptimizerOptions
46{
47 OptimizerOptions();
48
Jan Eilers841aca12020-08-12 14:59:06 +010049 OptimizerOptions(bool reduceFp32ToFp16,
50 bool debug,
Narumol Prangnawaratea063df2020-08-21 10:03:49 +010051 bool reduceFp32ToBf16 = false,
alexander73010782021-10-18 19:17:24 +010052 ShapeInferenceMethod shapeInferenceMethod = armnn::ShapeInferenceMethod::ValidateOnly,
53 bool importEnabled = false,
54 std::vector<armnn::BackendOptions> modelOptions = {});
Richard Burtondc0c6ed2020-04-08 16:39:05 +010055
Jan Eilers841aca12020-08-12 14:59:06 +010056 bool m_ReduceFp32ToBf16;
Richard Burtondc0c6ed2020-04-08 16:39:05 +010057 bool m_ReduceFp32ToFp16;
58 bool m_Debug;
alexander73010782021-10-18 19:17:24 +010059 ShapeInferenceMethod m_shapeInferenceMethod;
Narumol Prangnawaratea063df2020-08-21 10:03:49 +010060 bool m_ImportEnabled;
alexander73010782021-10-18 19:17:24 +010061 std::vector<armnn::BackendOptions> m_ModelOptions;
Richard Burtondc0c6ed2020-04-08 16:39:05 +010062};
alexander73010782021-10-18 19:17:24 +010063%model_options_clear;
Richard Burtondc0c6ed2020-04-08 16:39:05 +010064
65%feature("docstring",
66"
67An input connection slot for a layer. Slot lifecycle is managed by the layer.
68
69The input slot can be connected to an output slot of the preceding layer in the graph.
70Only one connection to the input slot is allowed.
71
72") IInputSlot;
73%nodefaultctor IInputSlot;
74%nodefaultdtor IInputSlot;
75class IInputSlot
76{
77public:
78 %feature("docstring",
79 "
80 Returns output slot of a preceding layer that is connected to the given input slot.
81
82 Returns:
83 IOutputSlot: Borrowed reference to an output connection slot for a preceding layer.
84
85 ") GetConnection;
86
87 armnn::IOutputSlot* GetConnection();
88};
89
90%feature("docstring",
91"
92An output connection slot for a layer. Slot lifecycle is managed by the layer.
93
94The output slot may be connected to 1 or more input slots of subsequent layers in the graph.
95") IOutputSlot;
96%nodefaultctor IOutputSlot;
97%nodefaultdtor IOutputSlot;
98class IOutputSlot
99{
100public:
101
102 %feature("docstring",
103 "
104 Returns the total number of connected input slots.
105
106 The same result could be obtained by calling `len()`:
107
108 >>> output_slot = ...
109 >>> size = len(output_slot)
110 >>> assert size == output_slot.GetNumConnections()
111
112 Returns:
113 int: Number of connected input slots.
114 ") GetNumConnections;
115 unsigned int GetNumConnections();
116
117
118 %feature("docstring",
119 "
120 Retrieves connected input slot by index.
121
122 The same result could be obtained by using square brackets:
123
124 >>> output_slot = ...
125 >>> connected_input_slot = output_slot[0]
126
127 Args:
128 index (int): Slot index.
129
130 Returns:
131 IInputSlot: Borrowed reference to connected input slot with given index.
132
133 Raises:
134 RuntimeError: If index out of bounds.
135 ") GetConnection;
136 armnn::IInputSlot* GetConnection(unsigned int index);
137
138 %feature("docstring",
139 "
140 Sets tensor info for output slot.
141 Operation does not change TensorInfo ownership.
142 Args:
143 tensorInfo (TensorInfo): Output tensor info.
144
145 ") SetTensorInfo;
146 void SetTensorInfo(const armnn::TensorInfo& tensorInfo);
147
148 %feature("docstring",
149 "
150 Gets tensor info for output slot.
151
152 Args:
153 tensorInfo (TensorInfo): Output tensor info.
154
155 ") GetTensorInfo;
156 const armnn::TensorInfo& GetTensorInfo();
157
158 %feature("docstring",
159 "
160 Checks if tensor info was set previously.
161
162 Returns:
163 bool: True if output tensor info was set, False - otherwise.
164
165 ") IsTensorInfoSet;
166 bool IsTensorInfoSet();
167
168 %feature("docstring",
169 "
170 Connects this output slot with given input slot.
171 Input slot is updated with this output connection.
172
173 Args:
174 destination (IInputSlot): Output tensor info.
175
176 Returns:
177 int: Total number of connections.
178
179 Raises:
180 RuntimeError: If input slot was already connected.
181
182 ") Connect;
183 int Connect(IInputSlot& destination);
184
185 %feature("docstring",
186 "
187 Disconnects this output slot from given input slot.
188
189 Args:
190 slot (IInputSlot): Input slot to disconnect from.
191
192 ") Disconnect;
193 void Disconnect(IInputSlot& slot);
194
195 %feature("docstring",
196 "
197 Calculates the index of this slot for the layer.
198
199 Returns:
200 int: Slot index.
201
202 ") CalculateIndexOnOwner;
203 unsigned int CalculateIndexOnOwner();
204
205 %feature("docstring",
206 "
207 Returns the index of the layer. Same value as `IConnectableLayer.GetGuid`.
208
209 Returns:
210 int: Layer id.
211
212 ") GetOwningLayerGuid;
213 unsigned int GetOwningLayerGuid();
214
215};
216
217%extend IOutputSlot {
218
219 armnn::IInputSlot* __getitem__(unsigned int index) {
220 return $self->GetConnection(index);
221 }
222
223 unsigned int __len__() const {
224 return $self->GetNumConnections();
225 }
226
227}
228
229%feature("docstring",
230"
231Interface for a layer that is connectable to other layers via `IInputSlot` and `IOutputSlot`.
232The object implementing this interface is returned by `INetwork` when calling `add*Layer` methods.
233
234") IConnectableLayer;
235%nodefaultctor IConnectableLayer;
236%nodefaultdtor IConnectableLayer;
237class IConnectableLayer
238{
239public:
240 %feature("docstring",
241 "
242 Returns the name of the layer. Name attribute is optional for a layer, thus
243 `None` value could be returned.
244
245 Returns:
246 str: Layer name or `None`.
247
248 ") GetName;
249 const char* GetName();
250
251 %feature("docstring",
252 "
253 Gets the number of input slots for the layer.
254
255 Returns:
256 int: Number of input slots.
257
258 ") GetNumInputSlots;
259 unsigned int GetNumInputSlots();
260
261 %feature("docstring",
262 "
263 Gets the number of output slots for the layer.
264
265 Returns:
266 int: Number of output slots.
267
268 ") GetNumOutputSlots;
269 unsigned int GetNumOutputSlots();
270
271 %feature("docstring",
272 "
273 Gets the input slot by index.
274
275 Args:
276 index (int): Slot index.
277
278 Returns:
279 IInputSlot: Borrowed reference to input slot.
280
281 ") GetInputSlot;
282 armnn::IInputSlot& GetInputSlot(unsigned int index);
283
284 %feature("docstring",
285 "
286 Gets the output slot by index.
287
288 Args:
289 index (int): Slot index.
290
291 Returns:
292 IOutputSlot: Borrowed reference to output slot.
293
294 ") GetOutputSlot;
295 armnn::IOutputSlot& GetOutputSlot(unsigned int index);
296
297
298 %feature("docstring",
299 "
300 Gets the unique layer id (within one process).
301 Guid is generated and assigned automatically when the layer is created.
302
303 Returns:
304 int: The unique layer id.
305
306 ") GetGuid;
307 unsigned int GetGuid();
308};
309
310%feature("docstring",
311 "
312 Interface for a network object. Network objects contain the whole computation graph, made up of different layers connected together.
313
314 INetwork objects can be constructed manually or obtained by using parsers. INetwork objects are used to create optimized networks, see `Optimize`.
315
316 ") INetwork;
317%nodefaultctor INetwork;
318%nodefaultdtor INetwork;
319class INetwork
320{
321public:
322
323 %feature("docstring",
324 "
325 Adds an input layer to the network. Input layers are placed at the start of a network and used for feeding input data during inference.
326
327 Args:
328 id (int): User generated id to uniquely identify a particular input. The same id needs to be specified
329 when passing the inputs to the IRuntime::EnqueueWorkload() function.
330 name (str): Optional name for the layer.
331
332 Returns:
333 IConnectableLayer: Interface for configuring the layer.
334 ") AddInputLayer;
335 armnn::IConnectableLayer* AddInputLayer(int id, const char* name = nullptr);
336
337 %feature("docstring",
338 "
339 Adds an addition layer to the network.
340
341 Args:
342 name (str): Optional name for the layer.
343
344 Returns:
345 IConnectableLayer: Interface for configuring the layer.
346 ") AddAdditionLayer;
347 armnn::IConnectableLayer* AddAdditionLayer(const char* name = nullptr);
348
349 %feature("docstring",
350 "
351 Adds an output layer to the network. Output layer is the final layer in your network.
352
353 Args:
354 id (int): User generated id to uniquely identify a particular input. The same id needs to be specified
355 when passing the inputs to `IRuntime.EnqueueWorkload()`.
356 name (str): Optional name for the layer.
357
358 Returns:
359 IConnectableLayer: Interface for configuring the layer.
360 ") AddOutputLayer;
361 armnn::IConnectableLayer* AddOutputLayer(int id, const char* name = nullptr);
362
363
364 %feature("docstring",
365 "
366 Adds an Activation layer to the network. Type of activation is decided by activationDescriptor.
367
368 Args:
369 activationDescriptor (ActivationDescriptor): ActivationDescriptor to configure the activation.
370 name (str): Optional name for the layer.
371
372 Returns:
373 IConnectableLayer: Interface for configuring the layer.
374 ") AddActivationLayer;
375 armnn::IConnectableLayer* AddActivationLayer(const ActivationDescriptor& activationDescriptor,
376 const char* name = nullptr);
377
378
379 %feature("docstring",
380 "
381 Adds an ArgMinMax layer to the network.
382
383 Args:
384 desc (ArgMinMaxDescriptor): Parameters for the ArgMinMax layer.
385 name (str): Optional name for the layer.
386
387 Returns:
388 IConnectableLayer: Interface for configuring the layer.
389 ") AddArgMinMaxLayer;
390 armnn::IConnectableLayer* AddArgMinMaxLayer(const armnn::ArgMinMaxDescriptor& desc,
391 const char* name = nullptr);
392
393
394 %feature("docstring",
395 "
396 Adds a Batch Normalization layer to the network.
397
398 Args:
399 mean (ConstTensor): Pre-calculated mean for each channel.
400 variance (ConstTensor): Pre-calculated variance for each channel.
401 beta (ConstTensor): Per-channel additive factor.
402 gamma (ConstTensor): Per-channel multiplicative factor.
403 name (str): Optional name for the layer.
404
405 Returns:
406 IConnectableLayer: Interface for configuring the layer.
407 ") AddBatchNormalizationLayer;
408 armnn::IConnectableLayer* AddBatchNormalizationLayer(const armnn::BatchNormalizationDescriptor& desc,
409 const armnn::ConstTensor& mean,
410 const armnn::ConstTensor& variance,
411 const armnn::ConstTensor& beta,
412 const armnn::ConstTensor& gamma,
413 const char* name = nullptr);
414
415
416 %feature("docstring",
417 "
418 Adds a Batch To Space ND layer to the network.
419
420 Args:
421 batchToSpaceNdDescriptor (BatchToSpaceNdDescriptor): Configuration parameters for the layer.
422 name (str): Optional name for the layer.
423
424 Returns:
425 IConnectableLayer: Interface for configuring the layer.
426 ") AddBatchToSpaceNdLayer;
427 armnn::IConnectableLayer* AddBatchToSpaceNdLayer(const armnn::BatchToSpaceNdDescriptor& batchToSpaceNdDescriptor,
428 const char* name = nullptr);
429
Teresa Charlin87dc8122021-11-22 15:34:26 +0000430
431 %feature("docstring",
432 "
433 Adds a Cast layer to the network.
434
435 Args:
436 name (str): Optional name for the layer.
437
438 Returns:
439 IConnectableLayer: Interface for configuring the layer.
440 ") AddCastLayer;
441 armnn::IConnectableLayer* AddCastLayer(const char* name = nullptr);
442
443
Richard Burtondc0c6ed2020-04-08 16:39:05 +0100444 %feature("docstring",
445 "
446 Adds a Comparison layer to the network.
447
448 Args:
449 comparisonDescriptor (ComparisonDescriptor): Configuration parameters for the layer.
450 name (str): Optional name for the layer.
451
452 Returns:
453 IConnectableLayer: Interface for configuring the layer.
454 ") AddComparisonLayer;
455 armnn::IConnectableLayer* AddComparisonLayer(const armnn::ComparisonDescriptor& comparisonDescriptor,
456 const char* name = nullptr);
457
458 %feature("docstring",
459 "
460 Adds a Concatenation layer to the network.
461
462 Args:
463 concatDescriptor (ConcatDescriptor): Parameters to configure the Concatenation layer.
464 name (str): Optional name for the layer.
465
466 Returns:
467 IConnectableLayer: Interface for configuring the layer.
468 ") AddConcatLayer;
469 armnn::IConnectableLayer* AddConcatLayer(const armnn::ConcatDescriptor& concatDescriptor,
470 const char* name = nullptr);
471
472
473 %feature("docstring",
474 "
475 Adds a layer with no inputs and a single output, which always corresponds to the passed in constant tensor.
476
477 Args:
478 input (ConstTensor): Tensor to be provided as the only output of the layer. The layer will maintain
479 its own copy of the tensor data, meaning the memory referenced by input can
480 be freed or reused after this function is called.
481 name (str): Optional name for the layer.
482
483 Returns:
484 IConnectableLayer: Interface for configuring the layer.
485 ") AddConstantLayer;
486 armnn::IConnectableLayer* AddConstantLayer(const armnn::ConstTensor& input,
487 const char* name = nullptr);
488
489 %feature("docstring",
490 "
491 Adds a Depth To Space layer to the network.
492
493 Args:
494 depthToSpaceDescriptor (DepthToSpaceDescriptor): Parameters for the depth to space operation.
495 name (str): Optional name for the layer.
496
497 Returns:
498 IConnectableLayer: Interface for configuring the layer.
499 ") AddDepthToSpaceLayer;
500 armnn::IConnectableLayer* AddDepthToSpaceLayer(const armnn::DepthToSpaceDescriptor& depthToSpaceDescriptor,
501 const char* name = nullptr);
502
503 %feature("docstring",
504 "
505 Adds a Dequantize layer to the network.
506
507 Args:
508 name (str): Optional name for the layer.
509
510 Returns:
511 IConnectableLayer: Interface for configuring the layer.
512 ") AddDequantizeLayer;
513 armnn::IConnectableLayer* AddDequantizeLayer(const char* name = nullptr);
514
515
516 %feature("docstring",
517 "
518 Adds a Detection PostProcess layer to the network. Detection PostProcess is a custom layer for SSD MobilenetV1.
519
520 Args:
521 descriptor (DetectionPostProcessDescriptor): Description of the Detection PostProcess layer.
522 anchors (ConstTensor): Tensor for anchors.
523 name (str): Optional name for the layer.
524
525 Returns:
526 IConnectableLayer: Interface for configuring the layer.
527 ") AddDetectionPostProcessLayer;
528 armnn::IConnectableLayer* AddDetectionPostProcessLayer(
529 const armnn::DetectionPostProcessDescriptor& descriptor,
530 const armnn::ConstTensor& anchors,
531 const char* name = nullptr);
532
533
534 %feature("docstring",
535 "
536 Adds a Division layer to the network.
537
538 Args:
539 name (str): Optional name for the layer.
540
541 Returns:
542 IConnectableLayer: Interface for configuring the layer.
543 ") AddDivisionLayer;
544 armnn::IConnectableLayer* AddDivisionLayer(const char* name = nullptr);
545
546 %feature("docstring",
Jan Eilers841aca12020-08-12 14:59:06 +0100547 "
548 Adds an Elementwise Unary layer to the network. Type of unary operation to use is decided by elementwiseUnaryDescriptor. Unary operations supported are (Abs, Exp, Neg, Rsqrt, Sqrt)
Richard Burtondc0c6ed2020-04-08 16:39:05 +0100549
Jan Eilers841aca12020-08-12 14:59:06 +0100550 Args:
551 elementwiseUnaryDescriptor (ElementwiseUnaryDescriptor): ElementwiseUnaryDescriptor to configure the choice of unary operation added to the network.
552 name (str): Optional name for the layer.
Richard Burtondc0c6ed2020-04-08 16:39:05 +0100553
Jan Eilers841aca12020-08-12 14:59:06 +0100554 Returns:
555 IConnectableLayer: Interface for configuring the layer.
556 ") AddElementwiseUnaryLayer;
Richard Burtondc0c6ed2020-04-08 16:39:05 +0100557 armnn::IConnectableLayer* AddElementwiseUnaryLayer(const ElementwiseUnaryDescriptor& elementwiseUnaryDescriptor,
558 const char* name = nullptr);
559
560 %feature("docstring",
561 "
Jan Eilers841aca12020-08-12 14:59:06 +0100562 Add a Fill layer to the network.
563
564 Args:
565 FillDescriptor (FillDescriptor): Descriptor for the fill operation.
566 name (str): Optional name for the layer.
567
568 Returns:
569 IConnectableLayer: Interface for configuring the layer.
570 ") AddFillLayer;
571 armnn::IConnectableLayer* AddFillLayer(const FillDescriptor& fillDescriptor,
572 const char* name = nullptr);
573
574 %feature("docstring",
575 "
Richard Burtondc0c6ed2020-04-08 16:39:05 +0100576 Adds a Floor layer to the network.
577
578 Args:
579 name (str): Optional name for the layer.
580
581 Returns:
582 IConnectableLayer: Interface for configuring the layer.
583 ") AddFloorLayer;
584 armnn::IConnectableLayer* AddFloorLayer(const char* name = nullptr);
585
586 %feature("docstring",
587 "
588 Add Gather layer to the network.
589
590 Args:
Jan Eilers841aca12020-08-12 14:59:06 +0100591 descriptor (GatherDescriptor): Descriptor for the gather operation.
Richard Burtondc0c6ed2020-04-08 16:39:05 +0100592 name (str): Optional name for the layer.
593
594 Returns:
595 IConnectableLayer: Interface for configuring the layer.
596 ") AddGatherLayer;
Jan Eilers841aca12020-08-12 14:59:06 +0100597 armnn::IConnectableLayer* AddGatherLayer(const GatherDescriptor& descriptor,
598 const char* name = nullptr);
Richard Burtondc0c6ed2020-04-08 16:39:05 +0100599
600 %feature("docstring",
601 "
602 Adds an Instance Normalization layer to the network.
603
604 Args:
605 desc (InstanceNormalizationDescriptor): Parameters for the instance normalization operation.
606 name (str): Optional name for the layer.
607
608 Returns:
609 IConnectableLayer: Interface for configuring the layer.
610 ") AddInstanceNormalizationLayer;
611 armnn::IConnectableLayer* AddInstanceNormalizationLayer(const armnn::InstanceNormalizationDescriptor& desc,
612 const char* name = nullptr);
613
Cathal Corbett9f184c42021-11-10 12:14:39 +0000614 %feature("docstring",
Richard Burtondc0c6ed2020-04-08 16:39:05 +0100615 "
616 Adds a Log Softmax layer to the network.
617
618 Args:
619 desc (SoftmaxDescriptor): parameters to configure the log softmax.
620 name (str): Optional name for the layer.
621
622 Returns:
623 IConnectableLayer: Interface for configuring the layer.
624 ") AddLogSoftmaxLayer;
625 armnn::IConnectableLayer* AddLogSoftmaxLayer(const armnn::LogSoftmaxDescriptor& logSoftmaxDescriptor,
626 const char* name = nullptr);
627
Cathal Corbett9f184c42021-11-10 12:14:39 +0000628 %feature("docstring",
Richard Burtondc0c6ed2020-04-08 16:39:05 +0100629 "
630 Adds an L2 Normalization layer to the network.
631 Normalization is performed along dimension 1, but requires a 4d input.
632
633 Args:
634 desc (L2NormalizationDescriptor): Parameters for the L2 normalization operation.
635 name (str): Optional name for the layer.
636
637 Returns:
638 IConnectableLayer: Interface for configuring the layer.
639 ") AddL2NormalizationLayer;
640 armnn::IConnectableLayer* AddL2NormalizationLayer(const armnn::L2NormalizationDescriptor& desc,
641 const char* name = nullptr);
642
643 %feature("docstring",
644 "
645 Add a Long Short-Term Memory layer to the network.
646
647 Args:
648 descriptor (LstmDescriptor): Parameters for the Lstm operation.
649 params (LstmInputParams): Weights and biases for the LSTM cell.
650 name (str): Optional name for the layer.
651
652 Returns:
653 IConnectableLayer: Interface for configuring the layer.
654 ") AddLstmLayer;
655 armnn::IConnectableLayer* AddLstmLayer(const armnn::LstmDescriptor& descriptor,
656 const armnn::LstmInputParams& params,
657 const char* name = nullptr);
658
Cathal Corbett9f184c42021-11-10 12:14:39 +0000659 %feature("docstring",
Richard Burtondc0c6ed2020-04-08 16:39:05 +0100660 "
661 Add a Maximum layer to the network.
662
663 Args:
664 name (str): Optional name for the layer.
665
666 Returns:
667 IConnectableLayer: Interface for configuring the layer.
668 ") AddMaximumLayer;
669 armnn::IConnectableLayer* AddMaximumLayer(const char* name = nullptr);
670
671 %feature("docstring",
672 "
673 Adds a Mean layer to the network.
674
675 Args:
676 meanDescriptor (meanDescriptor): Parameters for the mean operation.
677 name (str): Optional name for the layer.
678
679 Returns:
680 IConnectableLayer: Interface for configuring the layer.
681 ") AddMeanLayer;
682 armnn::IConnectableLayer* AddMeanLayer(const armnn::MeanDescriptor& meanDescriptor, const char* name = nullptr);
683
684 %feature("docstring",
685 "
686 Adds a Merge layer to the network.
687
688 Args:
689 name (str): Optional name for the layer.
690
691 Returns:
692 IConnectableLayer: Interface for configuring the layer.
693 ") AddMergeLayer;
694 armnn::IConnectableLayer* AddMergeLayer(const char* name = nullptr);
695
696 %feature("docstring",
697 "
698 Adds a Minimum layer to the network.
699
700 Args:
701 name (str): Optional name for the layer.
702
703 Returns:
704 IConnectableLayer: Interface for configuring the layer.
705 ") AddMinimumLayer;
706 armnn::IConnectableLayer* AddMinimumLayer(const char* name = nullptr);
707
708 %feature("docstring",
709 "
710 Adds a Multiplication layer to the network.
711
712 Args:
713 name (str): Optional name for the layer.
714
715 Returns:
716 IConnectableLayer: Interface for configuring the layer.
717 ") AddMultiplicationLayer;
718 armnn::IConnectableLayer* AddMultiplicationLayer(const char* name = nullptr);
719
720 %feature("docstring",
721 "
722 Adds a Normalization layer to the network.
723
724 Args:
725 normalizationDescriptor (NormalizationDescriptor): Parameters to configure the normalization.
726 name (str): Optional name for the layer.
727
728 Returns:
729 IConnectableLayer: Interface for configuring the layer.
730 ") AddNormalizationLayer;
731 armnn::IConnectableLayer* AddNormalizationLayer(const armnn::NormalizationDescriptor& normalizationDescriptor,
732 const char* name = nullptr);
733
734 %feature("docstring",
735 "
736 Adds a Pad layer to the network.
737
738 Args:
739 padDescriptor (PadDescriptor): Padding configuration for the layer. See `PadDescriptor` for more details.
740 name (str): Optional name for the layer.
741
742 Returns:
743 IConnectableLayer: Interface for configuring the layer.
744 ") AddPadLayer;
745 armnn::IConnectableLayer* AddPadLayer(const armnn::PadDescriptor& padDescriptor,
746 const char* name = nullptr);
747
748 %feature("docstring",
749 "
750 Adds a Permute layer to the network.
751
752 Args:
753 permuteDescriptor (PermuteDescriptor): Configuration of the permutation layer.
754 name (str): Optional name for the layer.
755
756 Returns:
757 IConnectableLayer: Interface for configuring the layer.
758 ") AddPermuteLayer;
759 armnn::IConnectableLayer* AddPermuteLayer(const armnn::PermuteDescriptor& permuteDescriptor,
760 const char* name = nullptr);
761
762 %feature("docstring",
763 "
764 Adds a Pooling layer to the network. Type of pooling is decided by the configuration.
765
766 Args:
767 pooling2dDescriptor (Pooling2dDescriptor): Configuration for the pooling layer.
768 name (str): Optional name for the layer.
769
770 Returns:
771 IConnectableLayer: Interface for configuring the layer.
772 ") AddPooling2dLayer;
773 armnn::IConnectableLayer* AddPooling2dLayer(const armnn::Pooling2dDescriptor& pooling2dDescriptor,
774 const char* name = nullptr);
775
776 %feature("docstring",
777 "
778 Adds a PReLU layer to the network.
779
780 Args:
781 name (str): Optional name for the layer.
782
783 Returns:
784 IConnectableLayer: Interface for configuring the layer.
785 ") AddPreluLayer;
786 armnn::IConnectableLayer* AddPreluLayer(const char* name = nullptr);
787
788 %feature("docstring",
789 "
790 Adds a Quantize layer to the network.
791
792 Args:
793 name (str): Optional name for the layer.
794
795 Returns:
796 IConnectableLayer: Interface for configuring the layer.
797 ") AddQuantizeLayer;
798 armnn::IConnectableLayer* AddQuantizeLayer(const char* name = nullptr);
799
800 %feature("docstring",
801 "
802 Adds a Quantized Long Short-Term Memory layer to the network.
803
804 Args:
805 params (`QuantizedLstmInputParams`): The weights and biases for the Quantized LSTM cell.
806 name (str): Optional name for the layer.
807
808 Returns:
809 IConnectableLayer: Interface for configuring the layer.
810 ") AddQuantizedLstmLayer;
811 armnn::IConnectableLayer* AddQuantizedLstmLayer(const armnn::QuantizedLstmInputParams& params,
812 const char* name = nullptr);
813
Jan Eilers841aca12020-08-12 14:59:06 +0100814
815 %feature("docstring",
816 "
817 Adds a Rank layer to the network.
818
819 Args:
820 name (str): Optional name for the layer.
821
822 Returns:
823 IConnectableLayer: Interface for configuring the layer.
824 ") AddRankLayer;
825 armnn::IConnectableLayer* AddRankLayer(const char* name = nullptr);
826
Cathal Corbett2b4182f2021-11-18 10:28:47 +0000827
Richard Burtondc0c6ed2020-04-08 16:39:05 +0100828 %feature("docstring",
829 "
830 Adds a Reshape layer to the network.
831
832 Args:
833 reshapeDescriptor (ReshapeDescriptor): Parameters for the reshape operation.
834 name (str): Optional name for the layer.
835
836 Returns:
837 IConnectableLayer: Interface for configuring the layer.
838 ") AddReshapeLayer;
839 armnn::IConnectableLayer* AddReshapeLayer(const armnn::ReshapeDescriptor& reshapeDescriptor,
840 const char* name = nullptr);
841
842 %feature("docstring",
843 "
844 Adds a Resize layer to the network.
845
846 Args:
847 resizeDescriptor (ResizeDescriptor): Configuration for the resize layer.
848 name (str): Optional name for the layer.
849
850 Returns:
851 IConnectableLayer: Interface for configuring the layer.
852 ") AddResizeLayer;
853 armnn::IConnectableLayer* AddResizeLayer(const armnn::ResizeDescriptor& resizeDescriptor,
854 const char* name = nullptr);
855
856
857 %feature("docstring",
858 "
Ryan OSheaaeee9ad2021-11-18 17:43:55 +0000859 Adds a Shape layer to the network.
860
861 Args:
862 name(str): Optional name for the layer.
863
864 Returns:
865 IConnectableLayer: Interface for configuring the layer
866 ") AddShapeLayer;
867 armnn::IConnectableLayer* AddShapeLayer(const char* name = nullptr);
868
869 %feature("docstring",
870 "
Richard Burtondc0c6ed2020-04-08 16:39:05 +0100871 Adds a Slice layer to the network.
872
873 Args:
874 sliceDescriptor (SliceDescriptor): Descriptor to configure the slice operation.
875 name (str): Optional name for the layer.
876
877 Returns:
878 IConnectableLayer: Interface for configuring the layer.
879 ") AddSliceLayer;
880 armnn::IConnectableLayer* AddSliceLayer(const armnn::SliceDescriptor& sliceDescriptor,
881 const char* name = nullptr);
882
883 %feature("docstring",
884 "
885 Adds a Softmax layer to the network.
886
887 If the data type is `DataType_QuantisedAsymm8`, then the output quantization parameters
888 must have a scale of 1/256 and an offset of 0.
889
890 Args:
891 softmaxDescriptor (SoftmaxDescriptor): Configuration for the softmax layer.
892 name (str): Optional name for the layer.
893
894 Returns:
895 IConnectableLayer: Interface for configuring the layer.
896 ") AddSoftmaxLayer;
897 armnn::IConnectableLayer* AddSoftmaxLayer(const armnn::SoftmaxDescriptor& softmaxDescriptor,
898 const char* name = nullptr);
899
900 %feature("docstring",
901 "
902 Adds a Space To Batch layer to the network.
903
904 Args:
905 spaceToBatchNdDescriptor (SpaceToBatchNdDescriptor): Configuration for the space to batch layer.
906 name (str): Optional name for the layer.
907
908 Returns:
909 IConnectableLayer: Interface for configuring the layer.
910 ") AddSpaceToBatchNdLayer;
911 armnn::IConnectableLayer* AddSpaceToBatchNdLayer(const armnn::SpaceToBatchNdDescriptor& spaceToBatchNdDescriptor,
912 const char* name = nullptr);
913
914 %feature("docstring",
915 "
916 Adds a space to depth layer to the network.
917
918 Args:
919 spaceToDepthDescriptor (SpaceToDepthDescriptor): Parameters for the space to depth operation.
920 name (str): Optional name for the layer.
921
922 Returns:
923 IConnectableLayer: Interface for configuring the layer.
924 ") AddSpaceToDepthLayer;
925 armnn::IConnectableLayer* AddSpaceToDepthLayer(const armnn::SpaceToDepthDescriptor& spaceToDepthDescriptor,
926 const char* name = nullptr);
927
928 %feature("docstring",
929 "
930 Adds a Splitter layer to the network.
931
932 Args:
933 splitterDescriptor (SplitterDescriptor): Parameters to configure the splitter layer.
934 name (str): Optional name for the layer.
935
936 Returns:
937 IConnectableLayer: Interface for configuring the layer.
938 ") AddSplitterLayer;
939 armnn::IConnectableLayer* AddSplitterLayer(const armnn::SplitterDescriptor& splitterDescriptor,
940 const char* name = nullptr);
941
942 %feature("docstring",
943 "
944 Adds a Stack layer to the network.
945
946 Args:
947 descriptor (StackDescriptor): Descriptor to configure the stack layer.
948 name (str): Optional name for the layer.
949
950 Returns:
951 IConnectableLayer: Interface for configuring the layer.
952 ") AddStackLayer;
953 armnn::IConnectableLayer* AddStackLayer(const armnn::StackDescriptor& descriptor,
954 const char* name = nullptr);
955
956 %feature("docstring",
957 "
958 Adds a StandIn layer to the network.
959
960 Args:
961 descriptor (StandInDescriptor): Parameters to configure the standIn layer.
962 name (str): Optional name for the layer.
963
964 Returns:
965 IConnectableLayer: Interface for configuring the layer.
966 ") AddStandInLayer;
967 armnn::IConnectableLayer* AddStandInLayer(const armnn::StandInDescriptor& descriptor,
968 const char* name = nullptr);
969
970 %feature("docstring",
971 "
972 Adds a Strided Slice layer to the network.
973
974 Args:
975 stridedSliceDescriptor (StridedSliceDescriptor): Parameters for the strided slice operation.
976 name (str): Optional name for the layer.
977
978 Returns:
979 IConnectableLayer: Interface for configuring the layer.
980 ") AddStridedSliceLayer;
981 armnn::IConnectableLayer* AddStridedSliceLayer(const armnn::StridedSliceDescriptor& stridedSliceDescriptor,
982 const char* name = nullptr);
983
984 %feature("docstring",
985 "
986 Adds a Subtraction layer to the network.
987
988 Args:
989 name (str): Optional name for the layer.
990
991 Returns:
992 IConnectableLayer: Interface for configuring the layer.
993 ") AddSubtractionLayer;
994 armnn::IConnectableLayer* AddSubtractionLayer(const char* name = nullptr);
995
996 %feature("docstring",
997 "
998 Adds a Switch layer to the network.
999
1000 Args:
1001 name (str): Optional name for the layer.
1002
1003 Returns:
1004 IConnectableLayer: Interface for configuring the layer.
1005 ") AddSwitchLayer;
1006 armnn::IConnectableLayer* AddSwitchLayer(const char* name = nullptr);
1007
Cathal Corbett9f184c42021-11-10 12:14:39 +00001008 %feature("docstring",
1009 "
1010 Adds a Fully Connected layer to the network. Also known as a Linear or Dense layer.
1011
1012 Args:
1013 fullyConnectedDescriptor (FullyConnectedDescriptor): Description of the fully connected layer.
1014 name (str): Optional name for the layer.
1015
1016 Returns:
1017 IConnectableLayer: Interface for configuring the layer.
1018 ") AddFullyConnectedLayer;
1019 armnn::IConnectableLayer* AddFullyConnectedLayer(const armnn::FullyConnectedDescriptor& fullyConnectedDescriptor,
1020 const char* name = nullptr);
1021
Cathal Corbettf0836e02021-11-18 18:17:38 +00001022 %feature("docstring",
1023 "
1024 Adds a LogicalBinary layer to the network.
1025
1026 Args:
1027 logicalBinaryDescriptor (LogicalBinaryDescriptor): Description of the LogicalBinary layer.
1028 name (str): Optional name for the layer.
1029
1030 Returns:
1031 IConnectableLayer: Interface for configuring the layer.
1032 ") AddLogicalBinaryLayer;
1033 armnn::IConnectableLayer* AddLogicalBinaryLayer(const armnn::LogicalBinaryDescriptor& logicalBinaryDescriptor,
1034 const char* name = nullptr);
Cathal Corbett2b4182f2021-11-18 10:28:47 +00001035
1036 %feature("docstring",
1037 "
1038 Adds a Transpose layer to the network.
1039
1040 Args:
1041 transposeDescriptor (TransposeDescriptor): Description of the transpose layer.
1042 name (str): Optional name for the layer.
1043
1044 Returns:
1045 IConnectableLayer: Interface for configuring the layer.
1046 ") AddTransposeLayer;
1047 armnn::IConnectableLayer* AddTransposeLayer(const armnn::TransposeDescriptor& transposeDescriptor,
1048 const char* name = nullptr);
Richard Burtondc0c6ed2020-04-08 16:39:05 +01001049};
1050
1051%extend INetwork {
1052
1053 INetwork() {
1054 return armnn::INetwork::CreateRaw();
1055 }
1056
1057 ~INetwork() {
1058 armnn::INetwork::Destroy($self);
1059 }
1060
1061 %feature("docstring",
Cathal Corbett9f184c42021-11-10 12:14:39 +00001062 "
1063 Adds a Fully Connected layer to the network with input weights and optional bias.
1064 Also known as a Linear or Dense layer.
Richard Burtondc0c6ed2020-04-08 16:39:05 +01001065
Cathal Corbett9f184c42021-11-10 12:14:39 +00001066 Args:
1067 fullyConnectedDescriptor (FullyConnectedDescriptor): Description of the fully connected layer.
1068 weights (ConstTensor): Tensor for the weights data.
1069 biases (ConstTensor): Optional tensor for the bias data.
1070 name (str): Optional name for the layer.
Richard Burtondc0c6ed2020-04-08 16:39:05 +01001071
Cathal Corbett9f184c42021-11-10 12:14:39 +00001072 Returns:
1073 IConnectableLayer: Interface for configuring the layer.
Richard Burtondc0c6ed2020-04-08 16:39:05 +01001074 ") AddFullyConnectedLayer;
1075 armnn::IConnectableLayer* AddFullyConnectedLayer(const armnn::FullyConnectedDescriptor& fullyConnectedDescriptor,
1076 const armnn::ConstTensor& weights,
1077 armnn::ConstTensor* biases = nullptr,
1078 const char* name = nullptr) {
Jan Eilers1b2654f2021-09-24 15:45:46 +01001079 ARMNN_NO_DEPRECATE_WARN_BEGIN
Richard Burtondc0c6ed2020-04-08 16:39:05 +01001080 if (biases) {
1081 return $self->AddFullyConnectedLayer(fullyConnectedDescriptor, weights,
1082 armnn::Optional<armnn::ConstTensor>(*biases), name);
1083 } else {
1084 return $self->AddFullyConnectedLayer(fullyConnectedDescriptor, weights,
1085 armnn::Optional<armnn::ConstTensor>(), name);
1086 }
Jan Eilers1b2654f2021-09-24 15:45:46 +01001087 ARMNN_NO_DEPRECATE_WARN_END
Richard Burtondc0c6ed2020-04-08 16:39:05 +01001088 }
1089
1090 %feature("docstring",
Cathal Corbett9f184c42021-11-10 12:14:39 +00001091 "
1092 Adds a 2D Transpose Convolution layer to the network.
Richard Burtondc0c6ed2020-04-08 16:39:05 +01001093
Cathal Corbett9f184c42021-11-10 12:14:39 +00001094 Args:
1095 descriptor (TransposeConvolution2dDescriptor): Descriptor containing all parameters to configure this layer.
1096 weights (ConstTensor): Tensor for the weights data.
1097 biases (ConstTensor): Optional tensor for the bias data.
1098 name (str): Optional name for the layer.
Richard Burtondc0c6ed2020-04-08 16:39:05 +01001099
Cathal Corbett9f184c42021-11-10 12:14:39 +00001100 Returns:
1101 IConnectableLayer: Interface for configuring the layer.
1102 ") AddTransposeConvolution2dLayer;
Richard Burtondc0c6ed2020-04-08 16:39:05 +01001103 armnn::IConnectableLayer* AddTransposeConvolution2dLayer(const armnn::TransposeConvolution2dDescriptor& descriptor,
1104 const armnn::ConstTensor& weights,
1105 armnn::ConstTensor* biases = nullptr,
Cathal Corbett9f184c42021-11-10 12:14:39 +00001106 const char* name = nullptr) {
Richard Burtondc0c6ed2020-04-08 16:39:05 +01001107
1108 if (biases) {
1109 return $self->AddTransposeConvolution2dLayer(descriptor, weights,
1110 armnn::Optional<armnn::ConstTensor>(*biases), name);
1111 } else {
1112 return $self->AddTransposeConvolution2dLayer(descriptor, weights,
1113 armnn::Optional<armnn::ConstTensor>(), name);
1114 }
1115 }
1116
1117
1118 %feature("docstring",
1119 "
1120 Adds a 2D Convolution layer to the network.
1121
1122 Args:
1123 convolution2dDescriptor (Convolution2dDescriptor): Description of the 2D convolution layer.
1124 weights (ConstTensor): Tensor for the weights data.
1125 biases (ConstTensor): Optional tensor for the bias data. If specified, must match the output tensor shape.
1126 name (str): Optional name for the layer.
1127
1128 Returns:
1129 IConnectableLayer: Interface for configuring the layer.
1130 ") AddConvolution2dLayer;
1131 armnn::IConnectableLayer* AddConvolution2dLayer(const armnn::Convolution2dDescriptor& convolution2dDescriptor,
1132 const armnn::ConstTensor& weights,
1133 armnn::ConstTensor* biases = nullptr,
1134 const char* name = nullptr) {
1135
1136 if (biases) {
1137 return $self->AddConvolution2dLayer(convolution2dDescriptor, weights,
1138 armnn::Optional<armnn::ConstTensor>(*biases), name);
1139 } else {
1140 return $self->AddConvolution2dLayer(convolution2dDescriptor, weights,
1141 armnn::Optional<armnn::ConstTensor>(), name);
1142 }
1143 }
1144
1145 %feature("docstring",
1146 "
1147 Adds a 2D Depthwise Convolution layer to the network.
1148
1149 Args:
1150 convolution2dDescriptor (DepthwiseConvolution2dDescriptor): Description of the 2D depthwise convolution layer.
1151 weights (ConstTensor): Tensor for the weights. Expected format: [channelMultiplier, inputChannels, height, width].
1152 biases (ConstTensor): Optional tensor for the bias data. If specified, must match the output tensor shape.
1153 name (str): Optional name for the layer.
1154
1155 Returns:
1156 IConnectableLayer: Interface for configuring the layer.
1157 ") AddDepthwiseConvolution2dLayer;
1158
1159 armnn::IConnectableLayer* AddDepthwiseConvolution2dLayer(
1160 const armnn::DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
1161 const armnn::ConstTensor& weights,
1162 const armnn::ConstTensor* biases = nullptr,
1163 const char* name = nullptr) {
1164
1165 if (biases) {
1166 return $self->AddDepthwiseConvolution2dLayer(convolution2dDescriptor, weights,
1167 armnn::Optional<armnn::ConstTensor>(*biases), name);
1168 } else {
1169 return $self->AddDepthwiseConvolution2dLayer(convolution2dDescriptor, weights,
1170 armnn::Optional<armnn::ConstTensor>(), name);
1171 }
1172 }
1173}
1174
1175%feature("docstring",
1176 "
1177 Interface class for an optimzied network object. Optimized networks are obtained after running `Optimize` on
1178 an `INetwork` object.
1179 Optimized networks are passed to `EnqueueWorkload`.
1180
1181 Args:
1182 convolution2dDescriptor (DepthwiseConvolution2dDescriptor): Description of the 2D depthwise convolution layer.
1183 weights (ConstTensor): Tensor for the weights. Expected format: [channelMultiplier, inputChannels, height, width].
1184 biases (ConstTensor): Optional tensor for the bias data. If specified, must match the output tensor shape.
1185 name (str): Optional name for the layer.
1186
1187 Returns:
1188 IConnectableLayer: Interface for configuring the layer.
1189 ") IOptimizedNetwork;
1190%nodefaultctor IOptimizedNetwork;
1191%nodefaultdtor IOptimizedNetwork;
1192class IOptimizedNetwork
1193{
1194};
1195
1196%extend IOptimizedNetwork {
1197
1198 ~IOptimizedNetwork() {
1199 armnn::IOptimizedNetwork::Destroy($self);
1200 }
1201
1202 %feature("docstring",
1203 "
1204 Saves optimized network graph as dot file.
1205
1206 Args:
1207 fileName (str): File path to save to.
1208 Raises:
1209 RuntimeError: If serialization failure.
1210 ") SerializeToDot;
1211
1212 void SerializeToDot(const std::string& fileName) {
1213 std::ofstream dot;
1214 dot.open(fileName);
1215 if(!dot.is_open())
1216 {
1217 throw armnn::Exception("Failed to open dot file");
1218 } else {
1219 armnn::Status status = $self->SerializeToDot(dot);
1220 dot.close();
1221 if(status == armnn::Status::Failure)
1222 {
1223 throw armnn::Exception("Failed to serialize to dot");
1224 }
1225 }
1226 };
1227}
1228}
1229
1230%{
1231 std::pair<armnn::IOptimizedNetwork*, std::vector<std::string>> Optimize(const armnn::INetwork* network,
1232 const std::vector<armnn::BackendId>& backendPreferences,
1233 const armnn::IDeviceSpec& deviceSpec,
1234 const armnn::OptimizerOptions& options = armnn::OptimizerOptions())
1235 {
1236 std::vector<std::string> errorMessages;
1237 armnn::IOptimizedNetwork* optimizedNetwork = armnn::Optimize(*network, backendPreferences, deviceSpec,
1238 options, armnn::Optional<std::vector<std::string> &>(errorMessages)).release();
1239
1240 if(!optimizedNetwork)
1241 {
1242 std::string errorString;
1243
1244 for (auto error : errorMessages) {
1245 errorString.append(error);
1246 }
1247
1248 throw armnn::Exception(errorString);
1249 }
1250
1251 return std::make_pair(optimizedNetwork, errorMessages);
1252 };
1253%}
1254
1255%feature("docstring",
1256 "
1257 Create an optimized version of the given network. Should be called before loading a network into the runtime.
1258
1259 Examples:
1260 Optimize a loaded network ready for inference.
1261 >>> parser = ann.ITfLiteParser()
1262 >>> network = parser.CreateNetworkFromBinaryFile('./model.tflite')
1263 >>>
1264 >>> preferredBackends = [ann.BackendId('CpuAcc'), ann.BackendId('CpuRef')]
1265 >>> opt_network, messages = ann.Optimize(network, preferredBackends, runtime.GetDeviceSpec(), ann.OptimizerOptions())
1266
1267 Args:
1268 network (INetwork): INetwork description of the network to be optimized.
1269 backendPreferences (list): The choice of the backend ordered by user preferences. See `BackendId`.
1270 deviceSpec (IDeviceSpec): DeviceSpec object as queried from the runtime. See `IRuntime.GetDeviceSpec`.
1271 options (OptimizerOptions): Object with optimizer configuration options.
1272
1273 Returns:
1274 tuple: (`IOptimizedNetwork`, a tuple of failures or warnings).
1275
1276 Raises:
1277 RuntimeError: If process fails.
1278 ") Optimize;
1279
1280%optimize_typemap_out;
1281std::pair<armnn::IOptimizedNetwork*, std::vector<std::string>> Optimize(const armnn::INetwork* network,
1282 const std::vector<armnn::BackendId>& backendPreferences,
1283 const armnn::IDeviceSpec& deviceSpec,
1284 const armnn::OptimizerOptions& options = OptimizerOptions());
1285%clear_optimize_typemap_out;