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