SNPE环境配置

SNPE 简介

Snapdragon Neural Processing Engine (SNPE)
专为高通骁龙系列设计的 DNN 深度学习加速运行库

可以理解为一个在骁龙环境下可执行的机器学习后端,类比于 TensoRT 或 ONNX。

Step.1 安装 QPM

SNPE 现在的安装需要骁龙官方的包管理工具,因此首先需要安装 QPM。

到这个网址找对应的 QPM 包进行下载
https://qpm.qualcomm.com/#/main/tools/details/QPM3

安装 QPM

dpkg -i QualcommPackageManager3.3.0.88.3.Linux-x86.deb

Step.2 安装 SNPE

相关步骤可以参照官网链接
https://qpm.qualcomm.com/#/main/tools/details/qualcomm_neural_processing_sdk

按上述链接的下载会给予一个.qik文件,将其放置到环境内。

按照官方的说明需要 –login 和 –licence 操作,但我这边测试下来跳过这步也不会有什么影响。
执行下面的命令。

# 具体的 qik 文件名可能会有些许异同,请根据具体情况进行更改
qpm-cli --extract qualcomm_neural_processing_sdk.2.16.0.231029.Linux-AnyCPU.qik

SNPE 大部分的环境以及默认的安装位置可以参考运行过程中的 log

Accept and continue with installation [y/n] : y

[Info] : Config File Present
[Info] : Checking environment
[Info] : Checking previous version
[Info] : Checking dependencies
[Info] : Preparing system
[Info] : Extracting files
[Info] : Configuring system
[Info] : Finishing
[Info] : SUCCESS: Installed qualcomm_neural_processing_sdk.Core at /opt/qcom/aistack/snpe/2.16.0.231029

我刚开始安装的最新版2.22版本的, 后面在snpe-onnx-to-dlc执行的时候报错libpython3.10.so.1.0: cannot open shared object file: No such file or directory。之后我就重新回退到了2.16版本。

Step.3 SNPE linux和python相关环境依赖

我们不仅需要安装 SNPE,还需要让 python 或者本地的包管理工具找到 SNPE 库的位置。

Linux依赖环境

首先需要找到上文记录下来的 SNPE 的安装目录并执行下面的命令。

cd /opt/qcom/aistack/snpe/2.16.0.231029/bin # 请根据自己的情况调整路径
bash check-linux-dependency.sh

# 如果 node 安装过于缓慢,可以考虑这样指定镜像
# NODE_MIRROR=https://mirrors.bfsu.edu.cn/nodejs-release/ bash check-linux-dependency.sh

python依赖环境

如果需要使用 python 环境,需要准备好 python 3.8 + torch 的环境

# 以 torch 1.11.0 为例
conda create -n SNPE_test python=3.8
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch

# 换源,如果有需要
# pip config set global.index-url https://mirrors.bfsu.edu.cn/pypi/web/simple
cd /opt/qcom/aistack/snpe/2.16.0.231029/bin
./check-python-dependency

设置环境变量

最后,需要引入环境变量

source /opt/qcom/aistack/snpe/2.16.0.231029/bin/envsetup.sh

永久引入环境变量的方法

vim ~/.bashrc

# 在末尾添加下面一行
source /opt/qcom/aistack/snpe/2.16.0.231029/bin/envsetup.sh

Step.4 SNPE导出模型测试

1. 下载测试工程

https://github.com/quic/qidk/tree/master/Solutions/VisionSolution1-ObjectDetection-YoloNas

git clone https://github.com/quic/qidk.git

cd qidk/Solutions/VisionSolution1-ObjectDetection-YoloNas

2. 运行GenerateDLC.ipynb

(此处需要安装anaconda和jupyter,如果是在windows远程打开服务器端的jupyter,还需要进行端口配置)

2.1 安装super-gradients
!pip install super-gradients==3.1.2
2.2 获取预训练模型并导出onnx
## Downloading Model from git repo
import torch
# Load model with pretrained weights
from super_gradients.training import models
from super_gradients.common.object_names import Models

model = models.get(Models.YOLO_NAS_S, pretrained_weights="coco")

# Prepare model for conversion
# Input size is in format of [Batch x Channels x Width x Height] where 640 is the standard COCO dataset dimensions
model.eval()
model.prep_model_for_conversion(input_size=[1, 3, 320, 320])

# Create dummy_input
dummy_input = torch.randn([1, 3, 320, 320], device="cpu")

# Convert model to onnx
torch.onnx.export(model, dummy_input, "yolo_nas_s.onnx", opset_version=11)

输出如下:

[2024-05-14 17:06:02] WARNING - checkpoint_utils.py - :warning: The pre-trained models provided by SuperGradients may have their own licenses or terms and conditions derived from the dataset used for pre-training.
 It is your responsibility to determine whether you have permission to use the models for your use case.
 The model you have requested was pre-trained on the coco dataset, published under the following terms: https://cocodataset.org/#termsofuse
[2024-05-14 17:06:02] INFO - checkpoint_utils.py - License Notification: YOLO-NAS pre-trained weights are subjected to the specific license terms and conditions detailed in 
https://github.com/Deci-AI/super-gradients/blob/master/LICENSE.YOLONAS.md
By downloading the pre-trained weight files you agree to comply with these terms.
[2024-05-14 17:06:02] INFO - checkpoint_utils.py - Successfully loaded pretrained weights for architecture yolo_nas_s
  • 2.3 snpe-onnx-to-dlc
snpe-onnx-to-dlc -i yolo_nas_s.onnx -o yolo_nas_s.dlc

snpe-onnx-to-dlc这一步可能会遇到报错ImportError: libunwind.so.1: cannot open shared object file: No such file or directory,我最终是这样解决的,多亏了GPT和kimi chat

遇到的错误信息通常是由于程序所需的共享库缺失或无法访问导致的。具体地说,“libunwind.so.1” 库在指定的位置上找不到。

要解决这个问题,你可以按照以下步骤进行操作:

  1. 检查库是否已安装:在终端中运行以下命令,验证系统是否已安装了 “libunwind” 库:
   dpkg -l | grep libunwind

如果该库未列出,则需要进行安装。

  1. 检查后发现已经安装了libunwind,那就确定库的安装路径:在终端中运行以下命令,找到 “libunwind.so.1” 库的安装路径:
   dpkg -L libunwind

这将列出 “libunwind” 包中安装的文件及其对应的路径。请注意 “libunwind.so.1” 库的路径。

  1. 在我的路径下只能找到libunwind.so.8,进行软连接,将libunwind.so.8链接到libunwind.so.1
sudo ln -s /usr/lib/x86_64-linux-gnu/libunwind.so.8 /usr/lib/x86_64-linux-gnu/libunwind.so.1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值