AidLite Python API
Model Data Type class DataType
For AidliteSDK, it is used to handle different models from different frameworks, and each model may have different input and output data types. When calling certain interfaces, you need to set the input and output data types of the model, so this data type enumeration is required.
| Member Variable Name | Type | Value | Description |
|---|---|---|---|
| TYPE_DEFAULT | int | 0 | Invalid data type |
| TYPE_UINT8 | int | 1 | Unsigned char data |
| TYPE_INT8 | int | 2 | Char data |
| TYPE_UINT32 | int | 3 | Unsigned int32 data |
| TYPE_FLOAT32 | int | 4 | Float data |
| TYPE_INT32 | int | 5 | Int32 data |
| TYPE_INT64 | int | 6 | Int64 data |
| TYPE_UINT64 | int | 7 | Unsigned int64 data |
| TYPE_INT16 | int | 8 | Int16 data |
| TYPE_UINT16 | int | 9 | Unsigned int16 data |
| TYPE_FLOAT16 | int | 10 | Float16 data |
| TYPE_BOOL | int | 11 | Bool data |
Inference Implementation Type class ImplementType
| Member Variable Name | Type | Value | Description |
|---|---|---|---|
| TYPE_DEFAULT | int | 0 | Invalid ImplementType type |
| TYPE_MMKV | int | 1 | Reserved in the C++ API; currently not exported in Python bindings and cannot be used directly |
| TYPE_REMOTE | int | 2 | Remote inference implementation |
| TYPE_FAST | int | 2 | Compatibility alias of TYPE_REMOTE; deprecated and not recommended for continued use |
| TYPE_LOCAL | int | 3 | Local inference implementation |
💡Note
Special notes:
The difference between TYPE_LOCAL and TYPE_REMOTE is that, for the Aplux integrated system, the former completes inference locally in the Linux environment without data transfer, while the latter exchanges data with the Android environment through IPC (inter-process communication), and the inference process runs in Android, so data transfer is involved. Therefore, TYPE_LOCAL is the preferred option for completing inference whenever possible.
Model Framework Type class FrameworkType
Because AidliteSDK integrates multiple deep learning inference frameworks, during use you need to specify which framework the current model belongs to, so this framework type enumeration is required.
| Member Variable Name | Type | Value | Description |
|---|---|---|---|
| TYPE_DEFAULT | int | 0 | Invalid FrameworkType type |
| TYPE_SNPE | int | 1 | SNPE 1.x (DLC) model |
| TYPE_TFLITE | int | 2 | TFLite model |
| TYPE_RKNN | int | 3 | RKNN model |
| TYPE_QNN | int | 4 | QNN model |
| TYPE_SNPE2 | int | 5 | SNPE 2.x (DLC) model |
| TYPE_NCNN | int | 6 | NCNN model |
| TYPE_MNN | int | 7 | MNN model |
| TYPE_TNN | int | 8 | TNN model |
| TYPE_PADDLE | int | 9 | Paddle model |
| TYPE_MS | int | 10 | MindSpore model |
| TYPE_ONNX | uint8_t | 11 | ONNX model |
| TYPE_QNN216 | uint8_t | 101 | QNN2.16 model |
| TYPE_SNPE216 | uint8_t | 102 | SNPE2.16 model |
| TYPE_QNN223 | uint8_t | 103 | QNN2.23 model |
| TYPE_SNPE223 | uint8_t | 104 | SNPE2.23 model |
| TYPE_QNN229 | uint8_t | 105 | QNN2.29 model |
| TYPE_SNPE229 | uint8_t | 106 | SNPE2.29 model |
| TYPE_QNN231 | uint8_t | 107 | QNN2.31 model |
| TYPE_QNN236 | uint8_t | 108 | QNN2.36 model |
| TYPE_QNN240 | uint8_t | 109 | QNN2.40 model |
💡Note
Special notes:
- If multiple backend implementation packages such as AidLite-QNN216, AidLite-QNN223, and AidLite-QNN231 are installed in the user environment, and FrameworkType in the code is set to TYPE_QNN (that is, no specific QNN backend version is explicitly selected), then the actual QNN backend used should be the one with the highest available QNN version, namely AidLite-QNN231. The same rule applies to SNPE2.
- Different QNN backend package versions cannot be used simultaneously within the same program. In other words, if TYPE_QNN216 is selected first for inference, then TYPE_QNN223 or TYPE_QNN231 cannot be used afterward in the same process. The same rule applies to SNPE2.
Inference Acceleration Hardware Type class AccelerateType
Each deep learning inference framework may support running on different acceleration devices, such as SNPE/QNN models running on DSP devices and RKNN models running on NPU devices. Therefore, during use you need to specify which device the current model is expected to run on, and this acceleration hardware enumeration is required.
| Member Variable Name | Type | Value | Description |
|---|---|---|---|
| TYPE_DEFAULT | int | 0 | Invalid AccelerateType type |
| TYPE_CPU | int | 1 | Run with CPU acceleration |
| TYPE_GPU | int | 2 | Run with GPU acceleration |
| TYPE_DSP | int | 3 | Run with DSP acceleration |
| TYPE_NPU | int | 4 | Run with NPU acceleration |
Log Level class LogLevel
AidliteSDK provides interfaces for configuring log output, which will be introduced later. If you need to specify the log level currently used by AidliteSDK, this log level enumeration is required.
| Member Variable Name | Type | Value | Description |
|---|---|---|---|
| INFO | int | 0 | Information |
| WARNING | int | 1 | Warning |
| ERROR | int | 2 | Error |
| FATAL | int | 3 | Fatal error |
Device Information class DeviceInfo
Starting from 2.3.1, Python bindings also provide the DeviceInfo type, which is used to describe available underlying inference devices. It is currently mainly used for device querying and custom device configuration in QNN DSP scenarios.
Member Variable List
| Member Variable Name | Type | Default Value | Description |
|---|---|---|---|
| id | int | 0 | Device ID |
| type | int | 0 | Device type number interpreted by the backend |
| cores_num | int | 1 | Number of cores included in the device |
| cores_id | list | Empty | List of device core IDs |
💡Note
The version field in the C++ structure is currently not exported in Python bindings. On the Python side, use the other four public fields directly.
Input/Output Information class TensorInfo
Each model has its own inputs and outputs. For models that developers are not very familiar with, it may be necessary during development to query the model's input and output Tensor information, so that pre-processing and post-processing for model inference can be implemented more conveniently. Aidlite provides interfaces for querying detailed input and output information, as well as the TensorInfo data type used to store these details.
Member Variable List
The TensorInfo object is used to store detailed information about model input and output Tensors, including the following parameters:
| Member | version |
| Type | uint32_t |
| Default | No default value |
| Description | This member identifies the TensorInfo version. If more information needs to be extended in the future, the version number will be updated |
| Member | index |
| Type | uint32_t |
| Default | No default value |
| Description | Index value of the Tensor |
| Member | name |
| Type | std::string |
| Default | No default value |
| Description | Name string of the Tensor |
| Member | element_count |
| Type | uint64_t |
| Default | 0 |
| Description | Number of data elements in the Tensor, not the number of bytes |
| Member | element_type |
| Type | enum DataType |
| Default | DataType::TYPE_DEFAULT |
| Description | Data type of elements in the Tensor |
| Member | dimensions |
| Type | uint32_t |
| Default | 0 |
| Description | Number of dimensions of data elements in the Tensor |
| Member | shape |
| Type | std::vector< uint64_t > |
| Default | No default value |
| Description | Shape description of data elements in the Tensor |
Model class Model
Before creating an inference interpreter, you need to configure detailed parameters related to the specific model. The Model class is mainly used to record model file information, structural information, and model-related content during runtime.
Create Empty Instance Object create_instance()
The current Python bindings also provide a no-argument overload, which allows an empty Model instance to be created first, and then the caller can supplement the model path or property information later in the workflow.
| API | create_instance |
| Description | Construct a Model instance object that does not carry a model file path |
| Parameters | None |
| Return | Normal: Model instance object |
| Exception: None |
Create Instance Object create_instance()
To configure detailed model information, you first need a model instance object. This function is used to create a Model instance object. If the model framework, such as SNPE or TFLite, requires only one model file, call this interface.
| API | create_instance |
| Description | Construct a Model type instance object by passing the path name of the model file |
| Parameters | model_path: Path name of the model file |
| Return | Normal: Model instance object |
| Exception: None |
# Use the inceptionv3_float32.dlc file in the current path to create a model object; report an error if the return value is empty
model = aidlite.Model.create_instance(model_path=r"./inceptionv3.dlc")
if model is None:
print("Create model failed.")
return FalseCreate Instance Object create_instance()
To configure detailed model information, you first need a model instance object. This function is used to create a Model instance object. If the model framework, such as NCNN or TNN, involves two model files, call this interface.
| API | create_instance |
| Description | Construct a Model type instance object by passing the path names of model files |
| Parameters | model_struct_path: Path name of the model structure file |
| model_weight_path: Path name of the model weight parameter file | |
| Return | Normal: Model instance object; Exception: None |
# Use the two NCNN model files in the current path to create a model object; report an error if the return value is empty
model = aidlite.Model.create_instance(
model_struct_path=r"./mobilenet_ssd_voc_ncnn.param",
model_weight_path=r"./mobilenet_ssd_voc_ncnn.bin")
if model is None:
print("Create model failed.")
return FalseSet Model Properties set_model_properties()
After the model instance object is created successfully, you need to set the input and output data types of the model and the shape information of input and output Tensor data.
| API | set_model_properties |
| Description | Set model properties, including input and output data shapes and data types. |
| Parameters | input_shapes: Shape array of input Tensors, a two-dimensional array structure. |
| input_data_type: Data type of input Tensors, of DataType enumeration type. | |
| output_shapes: Shape array of output Tensors, a two-dimensional array structure. | |
| output_data_type: Data type of output Tensors, of DataType enumeration type. | |
| Return | Normal: 0; Exception: non-zero |
| Note | 1. This interface needs to be called to set detailed input and output information if and only if ImplementType is REMOTE. 2. For SNPE and QNN inference frameworks, input and output data can only be float32. Therefore, this interface can only use aidlite.DataType.TYPE_FLOAT32 as the input parameter. For other inference frameworks, the input and output data types should remain consistent with the data types of the model file's input and output Tensors. |
# The data type uses the aforementioned DataType, and input/output shapes are two-dimensional arrays
input_shapes=[[1,640,640,3]]
output_shapes=[[1,10,10,255], [1,20,20,255], [1,40,40,255]]
model.set_model_properties( input_shapes=input_shapes,
input_data_type=aidlite.DataType.TYPE_FLOAT32,
output_shapes=output_shapes,
output_data_type=aidlite.DataType.TYPE_FLOAT32)Get Model Path get_model_absolute_path()
If the model framework, such as SNPE or TFLite, involves only one model file, then when the Model object is constructed successfully, the passed model file parameter will be converted to an absolute file path.
| API | get_model_absolute_path |
| Description | Used to obtain the existing path of the model file |
| Parameters | None |
| Return | Model file path string corresponding to the Model object |
Get Model Path get_model_struct_absolute_path()
If the model framework, such as NCNN or TNN, involves two model files, then when the Model object is constructed successfully, the passed model structure file parameter will be converted to an absolute file path.
| API | get_model_struct_absolute_path |
| Description | Used to obtain the existing path of the model structure file |
| Parameters | None |
| Return | Model structure file path string corresponding to the Model object |
Get Model Path get_model_weight_absolute_path()
If the model framework, such as NCNN or TNN, involves two model files, then when the Model object is constructed successfully, the passed model weight parameter file will be converted to an absolute file path.
| API | get_model_weight_absolute_path |
| Description | Used to obtain the existing path of the model weight parameter file |
| Parameters | None |
| Return | Model weight parameter file path string corresponding to the Model object |
Configuration class Config
Before creating an inference interpreter, in addition to setting specific Model information, you also need to set some configuration information used during inference. The Config class records configuration options that need to be set in advance, and these options will be used at runtime.
Create Instance Object create_instance()
To configure runtime information, you naturally need a configuration instance object first. This function is used to create a Config instance object.
| API | create_instance |
| Description | Used to construct an instance object of the Config class |
| Parameters | None |
| Return | Normal: Config instance object |
| Exception: None |
# Create a configuration instance object; report an error if the return value is None
config = aidlite.Config.create_instance()
if config is None:
print("Create config failed.")
return FalseMember Variable List
The Config object is used to set runtime configuration information, which includes the following parameters:
| Member | accelerate_type |
| Type | class AccelerateType |
| Default | AccelerateType.TYPE_CPU |
| Description | Type of acceleration hardware |
| Member | implement_type |
| Type | class ImplementType |
| Default | ImplementType.TYPE_DEFAULT |
| Description | Used to distinguish different environments of backend inference implementation |
| Note | Developers do not need to explicitly set this configuration item. AidliteSDK will derive a more suitable ImplementType according to factors such as the current system environment and model framework |
| Member | framework_type |
| Type | class FrameworkType |
| Default | FrameworkType.TYPE_DEFAULT |
| Description | Type of the underlying inference framework |
| Member | number_of_threads |
| Type | int |
| Default | -1 |
| Description | Number of threads; valid when greater than 0 |
| Note | This configuration item can be set optionally if and only if framework_type is TFLITE |
| Member | snpe_out_names |
| Type | list |
| Default | None |
| Description | List of model output node names |
| Note | This configuration item must be set if and only if framework_type is SNPE |
| Member | is_quantify_model |
| Type | int |
| Default | 0 |
| Description | Whether the model is quantized; 1 indicates a quantized model |
| Note | This configuration item must be set if and only if implement_type is REMOTE |
| Member | remote_timeout |
| Type | int |
| Default | -1 |
| Description | Interface timeout in milliseconds; valid when greater than 0 |
| Note | This configuration item can be set optionally if and only if implement_type is REMOTE |
| Member | fast_timeout |
| Type | int |
| Default | -1 |
| Description | Historical compatibility field of `remote_timeout`; it is still accessible in current Python bindings but is not recommended for continued use |
| Member | qnn_shared_buffer |
| Type | int |
| Default | 0 |
| Description | Whether to enable QNN shared buffer; currently mainly used in QNN DSP scenarios |
| Member | batch_invoke_size |
| Type | int |
| Default | 1 |
| Description | Backend batch inference configuration parameter; currently mainly used in QNN DSP scenarios |
| Member | backend_extension_config |
| Type | str |
| Default | Empty string |
| Description | Extension configuration file of the backend inference framework; currently mainly used in QNN DSP scenarios |
| Member | custom_device_info |
| Type | list[DeviceInfo] |
| Default | Empty |
| Description | Custom device information list used to specify the device set actually used by the backend |
| Member | reserved1 |
| Type | int |
| Default | 0 |
| Description | Reserved field. It currently has no business meaning, and callers do not need to set it explicitly |
💡Note
remote_timeout and fast_timeout correspond to the same timeout configuration. fast_timeout is only a historical compatibility field, and new code should consistently use remote_timeout.
config.framework_type = aidlite.FrameworkType.TYPE_QNN
config.accelerate_type = aidlite.AccelerateType.TYPE_DSP
# Set other configuration items as needed
# ... ...Context class Context
It is used to store the runtime context involved in execution, including the Model object and Config object. Runtime context data may be extended in the future.
Constructor Context()
| API | Context |
| Description | Construct a Context instance object |
| Parameters | model: Model instance object |
| config: Config instance object | |
| Return | Normal: Context instance object |
| Exception: None |
context = aidlite.Context(model=model, config=config)Get Model Member Variable get_model()
| API | get_model |
| Description | Get the Model object managed by context |
| Parameters | None |
| Return | Model object |
model = context.get_model()Get Config Member Variable get_config()
| API | get_config |
| Description | Get the Config object managed by context |
| Parameters | None |
| Return | Config object |
config = context.get_config()Interpreter class Interpreter
The Interpreter type instance is the主体 that executes inference operations and is used to carry out the actual inference process. After the interpreter object is created, all operations are based on the interpreter object, so it is the absolute core of AidliteSDK.
Create Instance Object create_instance
To perform inference-related operations, an inference interpreter is indispensable. This function is used to construct an instance object of the inference interpreter.
| API | create_instance |
| Description | Use the various data managed by the Context object to construct an Interpreter type object |
| Parameters | context: Context instance object |
| Return | Normal: Interpreter instance object |
| Exception: None |
# Create an interpreter object; report an error if the return value is None
interpreter = aidlite.Interpreter.create_instance(context=context)
if interpreter is None:
print("Create Interpreter failed.")
return FalseInitialize init()
After the interpreter object is created, some initialization operations need to be performed, such as environment checking and resource construction.
| API | init |
| Description | Complete initialization work required for inference |
| Parameters | None |
| Return | Normal: 0 |
| Exception: non-zero |
# Initialize the interpreter; report an error if the return value is non-zero
result = interpreter.init()
if result != 0:
print("sample : interpreter->init() failed.")
return FalseGet Device Information get_device_info()
Python bindings now also provide get_device_info(), which is used to query device information actually visible to the backend. This interface is supported from 2.3.1 onward and is currently mainly used in QNN DSP scenarios.
| API | get_device_info |
| Description | Get the backend device detail list |
| Return | Normal: List of DeviceInfo objects |
| Exception: raises an exception |
device_info_list = interpreter.get_device_info()
for device in device_info_list:
print(device.id, device.type, device.cores_num, device.cores_id)Load Model load_model()
After the interpreter object completes initialization, the required model file can be loaded into the interpreter. The subsequent inference process uses the loaded model resources.
| API | load_model |
| Description | Complete model loading related work. Since the model file path has already been configured in the Model object, the model loading operation can be executed directly |
| Parameters | None |
| Return | Normal: 0 |
| Exception: non-zero |
# Load the model with the interpreter; report an error if the return value is non-zero
result = interpreter.load_model()
if result != 0:
print("sample : interpreter->load_model() failed.")
return FalseGet Input Tensor Details get_input_tensor_info()
If you want to obtain detailed information about the model's input Tensors, you can use this interface.
| API | get_input_tensor_info |
| Description | Get detailed information about input Tensors in the model |
| Return | Normal: A two-dimensional array of TensorInfo type data |
| Exception: None | |
| Note | This interface is supported from AidliteSDK version 2.2.5 onward |
# Get detailed information about the model's input Tensor
input_tensor_info = onnx_interpreter.get_input_tensor_info()
if len(input_tensor_info) == 0 :
print("interpreter get_input_tensor_info() failed.")
return False
for gi, graph_tensor_info in enumerate(input_tensor_info):
for ti, tensor_info in enumerate(graph_tensor_info):
print( f"Input tensor : Graph[{gi}]-Tensor[{ti}]-name[{tensor_info.name}]"
f"-element_count[{tensor_info.element_count}]-element_type[{tensor_info.element_type}]"
f"-dimensions[{tensor_info.dimensions}]-shape{tensor_info.shape}")Get Output Tensor Details get_output_tensor_info()
If you want to obtain detailed information about the model's output Tensors, you can use this interface.
| API | get_output_tensor_info |
| Description | Get detailed information about output Tensors in the model |
| Return | Normal: A two-dimensional array of TensorInfo type data |
| Exception: None | |
| Note | This interface is supported from AidliteSDK version 2.2.5 onward |
# Get detailed information about the model's output Tensor
output_tensor_info = onnx_interpreter.get_output_tensor_info()
if len(output_tensor_info) == 0 :
print("interpreter get_output_tensor_info() failed.")
return False
for gi, graph_tensor_info in enumerate(output_tensor_info):
for ti, tensor_info in enumerate(graph_tensor_info):
print( f"Output tensor : Graph[{gi}]-Tensor[{ti}]-name[{tensor_info.name}]"
f"-element_count[{tensor_info.element_count}]-element_type[{tensor_info.element_type}]"
f"-dimensions[{tensor_info.dimensions}]-shape{tensor_info.shape}")Set Input Data set_input_tensor()
Before executing inference, the required input Tensor data must be provided. Before setting input data, different preprocessing steps are needed for different models in order to adapt to the specific model.
| API | set_input_tensor |
| Description | Set the input Tensor data required for inference |
| Parameters | in_tensor_tag: Index value or name string of the input Tensor, of type int or str |
| input_data: Input data supporting the buffer protocol, such as numpy.ndarray, memoryview, or bytes | |
| Optional Parameter | is_native: Whether the passed data should be treated as native backend data format. When `false`, quantization or dequantization is handled according to SDK default logic. When `true`, the raw format is passed directly. The default value is False |
| Return | Normal: 0 |
| Exception: non-zero | |
| Note | 1. The parameter in_tensor_tag supports Tensor name strings from AidliteSDK version 2.2.5 onward 2. For numpy.ndarray and memoryview, a C-contiguous memory layout is required; non-contiguous arrays or views will raise an exception 3. For SNPE and QNN frameworks, input data is typically processed as float32 by default. If the native-format interface is used, the user must ensure the data format matches backend requirements. |
# Set inference input data; report an error if the return value is non-zero
result = interpreter.set_input_tensor(in_tensor_tag=1, input_data=obj)
# result = interpreter.set_input_tensor(in_tensor_tag="input_tensor_name", input_data=obj)
# result = interpreter.set_input_tensor(in_tensor_tag=1, input_data=obj, is_native=True)
if result != 0:
print("interpreter->set_input_tensor() failed.")
return FalseExecute Inference invoke()
After input data is set, the next step is naturally to execute inference on that input data.
| API | invoke |
| Description | Execute the inference computation process |
| Parameters | None |
| Return | Normal: 0 |
| Exception: non-zero |
# Execute inference; report an error if the return value is non-zero
result = interpreter.invoke()
if result != 0:
print("sample : interpreter->invoke() failed.")
return FalseGet Output Data get_output_tensor()
After inference is completed, the result data produced by inference needs to be obtained. Once the result data is retrieved, it can be processed further to determine whether the result is correct.
| API | get_output_tensor |
| Description | Obtain inference result data after successful inference |
| Parameters | out_tensor_tag: Index value or name string of the result output Tensor, of type int or str |
| output_type: Target data type of the result output. This is optional. If omitted, it defaults to aidlite.DataType.TYPE_FLOAT32 | |
| Optional Parameter | is_native: Whether to return the underlying output byte view directly in the backend's native data format. The default value is False |
| Return | Normal: numpy.ndarray result data. |
| Exception: None. | |
| Note | 1. The parameter out_tensor_tag supports strings from AidliteSDK version 2.2.5 onward 2. `output_type` is used to reinterpret underlying `uint8` results as the target data type and does not perform an extra data copy 3. For SNPE and QNN, the default interface usually returns data with float32 semantics. If the native-format interface is used, the user must parse the actual backend output format manually. |
# Get inference result data; the return value is a numpy.ndarray
out_data = interpreter.get_output_tensor(out_tensor_tag=1, output_type=aidlite.DataType.TYPE_INT32)
# out_data = interpreter.get_output_tensor(out_tensor_tag="output_tensor_name", output_type=aidlite.DataType.TYPE_INT32)
# out_data = interpreter.get_output_tensor(out_tensor_tag=1, is_native=True)
if out_data is None:
print("interpreter->get_output_tensor() failed.")
return FalseResource Release destroy()
As mentioned earlier, the interpreter object needs to perform init() initialization and load_model() model loading. Correspondingly, the interpreter also needs to perform cleanup operations to destroy the resources created earlier.
| API | destroy |
| Description | Complete the necessary cleanup operations |
| Parameters | None |
| Return | Normal: 0 |
| Exception: non-zero |
# Release the interpreter; report an error if the return value is non-zero
result = interpreter.destroy()
if result != 0:
print("sample : interpreter-> destroy() failed.")
return FalseInterpreter Builder class InterpreterBuilder
This class provides unified creation functions for Interpreter objects and is used to create the required interpreter object.
Build Interpreter build_interpreter_from_path()
When building an inference interpreter object, different parameters can be provided. The simplest way is to provide only the path and name of the model file. If the model framework, such as SNPE or TFLite, requires only one model file, call this interface.
| API | build_interpreter_from_path |
| Description | Directly create the corresponding interpreter object from the path name of the model file |
| Parameters | model_path: Path name of the model file |
| Return | Normal: Interpreter object instance |
| Exception: None |
# Build an interpreter from the Model file path; report an error if the return value is None
interpreter = aidlite.InterpreterBuilder.build_interpreter_from_path(model_path=r"./640.dlc")
if interpreter is None:
print("Create Interpreter failed !")
return FalseBuild Interpreter build_interpreter_from_path()
When building an inference interpreter object, different parameters can be provided. The simplest way is to provide only the path and name of the model file. If the model framework, such as NCNN or TNN, involves two model files, call this interface.
| API | build_interpreter_from_path |
| Description | Directly create the corresponding interpreter object from the path names of the model files |
| Parameters | model_struct_path: Path name of the model structure file |
| model_weight_path: Path name of the model weight parameter file | |
| Return | Normal: Interpreter object instance |
| Exception: None |
Build Interpreter build_interpreter_from_model()
In addition to providing model file paths, you can also provide a Model object when building an inference interpreter object. This allows not only the model file path to be set, but also the model's input and output data types and the shapes of input and output data.
| API | build_interpreter_from_model |
| Description | Create the corresponding interpreter object by passing a Model object. Config-related parameters all use default values |
| Parameters | model: Model type object containing model-related data |
| Return | Normal: Interpreter object instance |
| Exception: None |
# Build an interpreter from the Model object; report an error if the return value is None
interpreter = aidlite.InterpreterBuilder.build_interpreter_from_model(model=model)
if interpreter is None:
print("Create Interpreter failed !")
return FalseBuild Interpreter build_interpreter_from_model_and_config()
In addition to the previous methods, an inference interpreter object can also be built by providing both a Model object and a Config object, so that model-related information and more runtime configuration parameters can both be supplied.
| API | build_interpreter_from_model_and_config |
| Description | Create the corresponding interpreter object by passing a Model object and Config. |
| Parameters | model: Model type object containing model-related data |
| config: Config type object containing some configuration parameters | |
| Return | Normal: Interpreter object instance |
| Exception: None |
# Build an interpreter from Model and Config objects; report an error if the return value is None
interpreter = aidlite.InterpreterBuilder.build_interpreter_from_model_and_config(model=model, config=config)
if interpreter is None:
print("Create Interpreter failed.")
return FalseOther Methods
Get SDK Version Information get_library_version()
| API | get_library_version |
| Description | Used to obtain version-related information of the current Aidlite-SDK |
| Parameters | None |
| Return | The returned value is the current Aidlite-SDK version information string |
Get Python SDK Version Information get_py_library_version()
| API | get_py_library_version |
| Description | Used to obtain version-related information of the current Py-Aidlite-SDK |
| Parameters | None |
| Return | The returned value is the current Py-Aidlite-SDK version information string |
Set Log Level set_log_level()
| API | set_log_level |
| Description | Set the current minimum log level and output log data at or above that level. By default, logs at WARNING level and above are printed. |
| Parameters | log_level: Value of type LogLevel |
| Return | Returns 0 by default |
Log Output to Standard Terminal log_to_stderr()
| API | log_to_stderr |
| Description | Set log output to the standard error terminal |
| Parameters | None |
| Return | Returns 0 by default |
Log Output to Text File log_to_file()
| API | log_to_file |
| Description | Set log output to the specified text file |
| Parameters | path_and_prefix: Storage path and name prefix of the log file |
| also_to_stderr: Whether to also output logs to the stderr terminal. The default value is False | |
| Return | Normal: 0 |
| Exception: non-zero |
Get Latest Log Information last_log_msg()
| API | last_log_msg |
| Description | Get the latest log information of the specified log level, usually used to obtain the latest error information |
| Parameters | log_level: Value of type LogLevel |
| Return | Latest log information |