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