Skip to main content

A Python wrapper for Qualcomm QAIRT SDK

Project description

QAIRT Wrapper

一个用于高通QAIRT SDK的Python包装器。

安装

pip install qairt-wrapper

使用方法

环境设置

使用前,您需要确保已正确设置QAIRT SDK环境。有两种方式:

  1. 推荐方式: 运行SDK包中的环境设置脚本

    source /path/to/qairt/2.35.0.250530/bin/envsetup.sh
    

    这将自动设置QNN_SDK_ROOTSNPE_ROOT环境变量。

  2. 手动指定SDK路径: 如果无法设置环境变量,可以在代码中手动指定SDK路径。

代码示例

from qairt_wrapper import init_qairt, Model, Config, InterpreterBuilder, DataType, FrameworkType, AccelerateType

# 初始化SDK
try:
    # 自动检测环境变量
    init_qairt()
except ImportError as e:
    print(f"错误: {e}")
    # 手动指定路径
    sdk_path = input("请输入QAIRT SDK的lib/python路径: ")
    init_qairt(sdk_path)

# 创建模型实例
model = Model.create_instance("model.dlc")
model.set_model_properties(
    input_shapes=[[1, 224, 224, 3]],
    input_dtype=DataType.TYPE_FLOAT32,
    output_shapes=[[1, 1000]],
    output_dtype=DataType.TYPE_FLOAT32
)

# 创建配置
config = Config.create_instance()
config.framework_type = FrameworkType.TYPE_QNN
config.accelerate_type = AccelerateType.TYPE_CPU

# 构建解释器
interpreter = InterpreterBuilder.build_interpretper_from_model_and_config(model, config)

# 初始化解释器
ret = interpreter.init()
if ret != 0:
    print("初始化解释器失败")
    exit(1)

# 加载模型
ret = interpreter.load_model()
if ret != 0:
    print("加载模型失败")
    exit(1)

# 设置输入数据
import numpy as np
input_data = np.random.random((1, 224, 224, 3)).astype(np.float32)
interpreter.set_input_tensor(0, input_data)

# 执行推理
interpreter.invoke()

# 获取输出
output = interpreter.get_output_tensor(0)
print(f"输出形状: {output.shape}")

# 释放资源
interpreter.destory()

要求

  • 需要安装高通QAIRT SDK
  • 支持通过环境变量QNN_SDK_ROOTSNPE_ROOT自动检测SDK路径
  • 也可以手动指定SDK路径

版本信息

1.0.3:增加了SNPE可选GPU\CPU\DSP选项。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qairt_wrapper-1.0.7.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qairt_wrapper-1.0.7-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file qairt_wrapper-1.0.7.tar.gz.

File metadata

  • Download URL: qairt_wrapper-1.0.7.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for qairt_wrapper-1.0.7.tar.gz
Algorithm Hash digest
SHA256 4501de821f1c4457d3ee0271e1f7e0c9e29f7a36a69a876844a516e6739b994d
MD5 bffe71dd400d1003b010451c0336de2e
BLAKE2b-256 19e9c7674db34b056572a6cfae28cc32e22bfd51fa926d6f34f6bfcd0991c9e1

See more details on using hashes here.

File details

Details for the file qairt_wrapper-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: qairt_wrapper-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for qairt_wrapper-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 240667a17f5e366d04bd5b5867f9d6f841bdaa12e2778012c65d946edd06595f
MD5 cc7994d9633d240a824ba553a378c9fd
BLAKE2b-256 74fa162d0a6230864a04bc447749bb0ab0513f1ae17f95b20c0ebd3685f75366

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page