jetson arm

记录 hrnet windows 移植jetson 过程

by nineone, 2022-10-19


1. 安装onnxruntime

下载cuda对应onnxruntime版本https://github.com/microsoft/onnxruntime

如果是在Jetson板子上,其实要综合前面三个Provider的内容都得看看,然后根据自己的需要做合理的搭配,经过几次实验后,我在Jetson Nano上编译出了支持TensorRT和CUDA的支持多CPU核并行协同工作的build,下面说说步骤:

 首先如果你的板子上之前没安装过常用的支持包,可能需要做下面的步骤:
 
sudo apt-get update
sudo apt-get install -y \
    build-essential \
    curl \
    libcurl4-openssl-dev \
    libssl-dev \
    wget \
    python3 \
    python3-pip \
    git \
    tar
 
pip3 install --upgrade pip
pip3 install --upgrade setuptools
pip3 install --upgrade wheel
pip3 install numpy
 
sudo apt install -y --no-install-recommends \
  build-essential software-properties-common \ 
  libopenblas-dev libpython3.6-dev python3-pip python3-dev 

其次,保证你的Jetson板子上用的cmake版本符合要求:

大于等于3.1.3

不符合则下载源码编译安装一个比较高的版本:

wget https://cmake.org/files/v3.17/cmake-3.17.3.tar.gz;
tar zxf cmake-3.17.3.tar.gz
 
cd /code/cmake-3.17.3
./configure --system-curl  
#如果不嫌时间花的多,直接执行./configure也行
make
sudo make install

然后

 
sudo apt-get install protobuf-compiler libprotoc-dev
 
export PATH=/usr/local/cuda/bin:${PATH}
export CUDA_PATH=/usr/local/cuda
export cuDNN_PATH=/usr/lib/aarch64-linux-gnu
export CMAKE_ARGS="-DONNX_CUSTOM_PROTOC_EXECUTABLE=/usr/bin/protoc"
 
mkdir /code
cd /code
git clone --recursive https://github.com/Microsoft/onnxruntime
# git指定版本 git clone -b + 版本号 
# 例如 git clone -b 1.6.0  + 地址
# --recursive git所有子项目(当前项目包含的其他项目)
git submodule update --init --recursive --progress
cd /code/onnxruntime
 
./build.sh --update --config Release --enable_pybind --build_shared_lib --build --build_wheel \
--use_openmp --use_tensorrt --tensorrt_home /usr/src/tensorrt --cuda_home /usr/local/cuda --cudnn_home /usr/lib/aarch64-linux-gnu

注意加上--use_openmp这个选项,openmp用于单机上的多CPU/多核并行,Jetson板子上一般CPU都是多核的,加了这个选项才能用上多核,尤其是Provider设置为CPU时(默认,调用onnxruntim时不对Provider做任何设置,默认使用CPU推理)

如果要打印出模型网络的输入/输出节点,加上--cmake_extra_defines onnxruntime_DEBUG_NODE_INPUTS_OUTPUTS=1 ,不过不推荐,因为它这个不是在onnxruntime启动时打印,而是每次推理时都打印,稍有点影响性能。

编译完成后查看编译后库文件:

ls -l onnxruntime/build/Linux/MinSizeRel/*.so
ls -l onnxruntime/build/Linux/MinSizeRel/dist/*.whl

如果只python调用python版的onnxruntime,直接安装这个wheel文件即可,如果是需要使用C/C++编程调用onnxruntime,则需要在编译你的应用程序时把/include/onnxruntime/core下的头文件包含到include路径里并且把这些so文件链接到你的应用程序。


编译 onnxruntime 遇坑记录

1.报错No CMAKE_CUDA_COMPILER could be found.

并不是cuda 环境变量没有设置好
检查文件所有者(不能是root)

修改文件或目录所有者
chown -R 所有者 文件或目录

git submodule update --init 报错 hash值不对应

找到项目的.gitmodules文件
找到url对应的可访问地址

1.使用github镜像地址:https://github.com.cnpmjs.org
https://gitclone.com/github.com
2.在gitee上找别人fork好的对应项目的地址
这里我们使用第一种,将url的https://github.com换成https://github.com.cnpmjs.org

然后使用git submodule sync命令同步url
然后在执行git submodule update --init就ok了

还有可能原因:
尝试下面两条命令

git submodule deinit -f .
git submodule update --init

报错 E275 missing whitespace after keyword

PEP8 检查代码规范
根据报错内容,修改相应文件 即可

jetsononnxruntime

作者: nineone

2025 © typecho & elise 26 ms