Ryan OShea | 7d1b1ca | 2023-08-01 17:15:24 +0100 | [diff] [blame] | 1 | # Copyright © 2020,2023 Arm Ltd. All rights reserved. |
Richard Burton | dc0c6ed | 2020-04-08 16:39:05 +0100 | [diff] [blame] | 2 | # SPDX-License-Identifier: MIT |
| 3 | import inspect |
| 4 | import sys |
| 5 | import logging |
| 6 | |
| 7 | from ._generated.pyarmnn_version import GetVersion, GetMajorVersion, GetMinorVersion |
| 8 | |
Ryan OShea | 7d1b1ca | 2023-08-01 17:15:24 +0100 | [diff] [blame] | 9 | print("WARNING: PyArmNN is deprecated. To use ArmNN on python, please use the tflite delegate. Expected to be removed in release 24.05.") |
| 10 | |
Richard Burton | dc0c6ed | 2020-04-08 16:39:05 +0100 | [diff] [blame] | 11 | # Parsers |
Richard Burton | dc0c6ed | 2020-04-08 16:39:05 +0100 | [diff] [blame] | 12 | |
| 13 | try: |
| 14 | from ._generated.pyarmnn_onnxparser import IOnnxParser |
| 15 | except ImportError as err: |
| 16 | logger = logging.getLogger(__name__) |
| 17 | message = "Your ArmNN library instance does not support Onnx models parser functionality. " |
| 18 | logger.warning("%s Skipped IOnnxParser import.", message) |
| 19 | logger.debug(str(err)) |
| 20 | |
| 21 | |
| 22 | def IOnnxParser(): |
| 23 | """In case people try importing without having Arm NN built with this parser.""" |
| 24 | raise RuntimeError(message) |
| 25 | |
| 26 | try: |
Jan Eilers | 841aca1 | 2020-08-12 14:59:06 +0100 | [diff] [blame] | 27 | from ._generated.pyarmnn_tfliteparser import ITfLiteParser, TfLiteParserOptions |
Richard Burton | dc0c6ed | 2020-04-08 16:39:05 +0100 | [diff] [blame] | 28 | except ImportError as err: |
| 29 | logger = logging.getLogger(__name__) |
| 30 | message = "Your ArmNN library instance does not support TF lite models parser functionality. " |
| 31 | logger.warning("%s Skipped ITfLiteParser import.", message) |
| 32 | logger.debug(str(err)) |
| 33 | |
| 34 | |
| 35 | def ITfLiteParser(): |
| 36 | """In case people try importing without having Arm NN built with this parser.""" |
| 37 | raise RuntimeError(message) |
| 38 | |
wangg | 5f960d9 | 2020-08-26 01:44:32 +0000 | [diff] [blame] | 39 | try: |
| 40 | from ._generated.pyarmnn_deserializer import IDeserializer |
| 41 | except ImportError as err: |
| 42 | logger = logging.getLogger(__name__) |
Francis Murtagh | bb6c649 | 2022-02-09 15:13:38 +0000 | [diff] [blame] | 43 | message = "Your ArmNN library instance does not have ArmNN model (.armnn) parser functionality. " |
wangg | 5f960d9 | 2020-08-26 01:44:32 +0000 | [diff] [blame] | 44 | logger.warning("%s Skipped IDeserializer import.", message) |
| 45 | logger.debug(str(err)) |
| 46 | |
| 47 | def IDeserializer(): |
| 48 | """In case people try importing without having ArmNN built with this parser.""" |
| 49 | raise RuntimeError(message) |
| 50 | |
Richard Burton | dc0c6ed | 2020-04-08 16:39:05 +0100 | [diff] [blame] | 51 | # Network |
| 52 | from ._generated.pyarmnn import Optimize, OptimizerOptions, IOptimizedNetwork, IInputSlot, \ |
| 53 | IOutputSlot, IConnectableLayer, INetwork |
| 54 | |
| 55 | # Backend |
| 56 | from ._generated.pyarmnn import BackendId |
| 57 | from ._generated.pyarmnn import IDeviceSpec |
alexander | 7301078 | 2021-10-18 19:17:24 +0100 | [diff] [blame] | 58 | from ._generated.pyarmnn import BackendOptions, BackendOption |
Richard Burton | dc0c6ed | 2020-04-08 16:39:05 +0100 | [diff] [blame] | 59 | |
| 60 | # Tensors |
| 61 | from ._generated.pyarmnn import TensorInfo, TensorShape |
| 62 | |
| 63 | # Runtime |
| 64 | from ._generated.pyarmnn import IRuntime, CreationOptions, INetworkProperties |
| 65 | |
| 66 | # Profiler |
| 67 | from ._generated.pyarmnn import IProfiler |
| 68 | |
| 69 | # Types |
| 70 | from ._generated.pyarmnn import DataType_Float16, DataType_Float32, DataType_QAsymmU8, DataType_Signed32, \ |
alexander | 7301078 | 2021-10-18 19:17:24 +0100 | [diff] [blame] | 71 | DataType_Boolean, DataType_QSymmS16, DataType_QSymmS8, DataType_QAsymmS8, ShapeInferenceMethod_ValidateOnly, \ |
| 72 | ShapeInferenceMethod_InferAndValidate |
Teresa Charlin | 1814733 | 2021-11-17 14:34:30 +0000 | [diff] [blame] | 73 | from ._generated.pyarmnn import DataLayout_NCHW, DataLayout_NHWC, DataLayout_NCDHW, DataLayout_NDHWC |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 74 | from ._generated.pyarmnn import MemorySource_Malloc, MemorySource_Undefined, MemorySource_DmaBuf, \ |
| 75 | MemorySource_DmaBufProtected |
| 76 | from ._generated.pyarmnn import ProfilingDetailsMethod_Undefined, ProfilingDetailsMethod_DetailsWithEvents, \ |
| 77 | ProfilingDetailsMethod_DetailsOnly |
Richard Burton | dc0c6ed | 2020-04-08 16:39:05 +0100 | [diff] [blame] | 78 | |
| 79 | from ._generated.pyarmnn import ActivationFunction_Abs, ActivationFunction_BoundedReLu, ActivationFunction_LeakyReLu, \ |
| 80 | ActivationFunction_Linear, ActivationFunction_ReLu, ActivationFunction_Sigmoid, ActivationFunction_SoftReLu, \ |
| 81 | ActivationFunction_Sqrt, ActivationFunction_Square, ActivationFunction_TanH, ActivationDescriptor |
| 82 | from ._generated.pyarmnn import ArgMinMaxFunction_Max, ArgMinMaxFunction_Min, ArgMinMaxDescriptor |
| 83 | from ._generated.pyarmnn import BatchNormalizationDescriptor, BatchToSpaceNdDescriptor |
Teresa Charlin | f7b5011 | 2021-11-18 15:24:50 +0000 | [diff] [blame] | 84 | from ._generated.pyarmnn import ChannelShuffleDescriptor, ComparisonDescriptor, ComparisonOperation_Equal, \ |
| 85 | ComparisonOperation_Greater, ComparisonOperation_GreaterOrEqual, ComparisonOperation_Less, \ |
Richard Burton | dc0c6ed | 2020-04-08 16:39:05 +0100 | [diff] [blame] | 86 | ComparisonOperation_LessOrEqual, ComparisonOperation_NotEqual |
| 87 | from ._generated.pyarmnn import UnaryOperation_Abs, UnaryOperation_Exp, UnaryOperation_Sqrt, UnaryOperation_Rsqrt, \ |
| 88 | UnaryOperation_Neg, ElementwiseUnaryDescriptor |
Cathal Corbett | f0836e0 | 2021-11-18 18:17:38 +0000 | [diff] [blame] | 89 | from ._generated.pyarmnn import LogicalBinaryOperation_LogicalAnd, LogicalBinaryOperation_LogicalOr, \ |
| 90 | LogicalBinaryDescriptor |
Teresa Charlin | 1814733 | 2021-11-17 14:34:30 +0000 | [diff] [blame] | 91 | from ._generated.pyarmnn import Convolution2dDescriptor, Convolution3dDescriptor, DepthToSpaceDescriptor, \ |
| 92 | DepthwiseConvolution2dDescriptor, DetectionPostProcessDescriptor, FakeQuantizationDescriptor, FillDescriptor, \ |
| 93 | FullyConnectedDescriptor, GatherDescriptor, InstanceNormalizationDescriptor, LstmDescriptor, \ |
| 94 | L2NormalizationDescriptor, MeanDescriptor |
Richard Burton | dc0c6ed | 2020-04-08 16:39:05 +0100 | [diff] [blame] | 95 | from ._generated.pyarmnn import NormalizationAlgorithmChannel_Across, NormalizationAlgorithmChannel_Within, \ |
| 96 | NormalizationAlgorithmMethod_LocalBrightness, NormalizationAlgorithmMethod_LocalContrast, NormalizationDescriptor |
Teresa Charlin | cd3fdae | 2021-11-18 15:51:36 +0000 | [diff] [blame] | 97 | from ._generated.pyarmnn import PaddingMode_Constant, PaddingMode_Reflect, PaddingMode_Symmetric, PadDescriptor |
Richard Burton | dc0c6ed | 2020-04-08 16:39:05 +0100 | [diff] [blame] | 98 | from ._generated.pyarmnn import PermutationVector, PermuteDescriptor |
| 99 | from ._generated.pyarmnn import OutputShapeRounding_Ceiling, OutputShapeRounding_Floor, \ |
| 100 | PaddingMethod_Exclude, PaddingMethod_IgnoreValue, PoolingAlgorithm_Average, PoolingAlgorithm_L2, \ |
Ryan OShea | 8965500 | 2022-03-09 02:07:24 +0000 | [diff] [blame] | 101 | PoolingAlgorithm_Max, Pooling2dDescriptor, Pooling3dDescriptor |
Ryan OShea | 09a0522 | 2021-11-18 16:52:41 +0000 | [diff] [blame] | 102 | from ._generated.pyarmnn import ReduceDescriptor, ReduceOperation_Prod, ReduceOperation_Max, ReduceOperation_Mean, \ |
| 103 | ReduceOperation_Min, ReduceOperation_Sum |
Richard Burton | dc0c6ed | 2020-04-08 16:39:05 +0100 | [diff] [blame] | 104 | from ._generated.pyarmnn import ResizeMethod_Bilinear, ResizeMethod_NearestNeighbor, ResizeDescriptor, \ |
| 105 | ReshapeDescriptor, SliceDescriptor, SpaceToBatchNdDescriptor, SpaceToDepthDescriptor, StandInDescriptor, \ |
| 106 | StackDescriptor, StridedSliceDescriptor, SoftmaxDescriptor, TransposeConvolution2dDescriptor, \ |
Cathal Corbett | 2b4182f | 2021-11-18 10:28:47 +0000 | [diff] [blame] | 107 | TransposeDescriptor, SplitterDescriptor |
Richard Burton | dc0c6ed | 2020-04-08 16:39:05 +0100 | [diff] [blame] | 108 | from ._generated.pyarmnn import ConcatDescriptor, CreateDescriptorForConcatenation |
| 109 | |
| 110 | from ._generated.pyarmnn import LstmInputParams, QuantizedLstmInputParams |
| 111 | |
| 112 | # Public API |
| 113 | # Quantization |
| 114 | from ._quantization.quantize_and_dequantize import quantize, dequantize |
| 115 | |
| 116 | # Tensor |
| 117 | from ._tensor.tensor import Tensor |
| 118 | from ._tensor.const_tensor import ConstTensor |
| 119 | from ._tensor.workload_tensors import make_input_tensors, make_output_tensors, workload_tensors_to_ndarray |
| 120 | |
| 121 | # Utilities |
| 122 | from ._utilities.profiling_helper import ProfilerData, get_profiling_data |
| 123 | |
| 124 | from ._version import __version__, __arm_ml_version__ |
| 125 | |
| 126 | ARMNN_VERSION = GetVersion() |
| 127 | |
| 128 | |
| 129 | def __check_version(): |
| 130 | from ._version import check_armnn_version |
| 131 | check_armnn_version(ARMNN_VERSION) |
| 132 | |
| 133 | |
| 134 | __check_version() |
| 135 | |
| 136 | __all__ = [] |
| 137 | |
| 138 | __private_api_names = ['__check_version'] |
| 139 | |
| 140 | for name, obj in inspect.getmembers(sys.modules[__name__]): |
| 141 | if inspect.isclass(obj) or inspect.isfunction(obj): |
| 142 | if name not in __private_api_names: |
| 143 | __all__.append(name) |