赞
踩
- 虚拟机ubuntu20
- ROC-RK3588S-PC_Ubuntu20.04-Xfce-r3115_v1.3.0c_240131
- #安装依赖
- $ sudo apt install git cmake g++ python3-pip
- #获取源码
- $ cd ~/Downloads
- $ git clone https://github.com/PaddlePaddle/FastDeploy.git
- #压缩备份:
- $ 7z a FastDeploy_git_src_20240311.7z FastDeploy
-
- # 编译安装
-
- $ cd FastDeploy
- $ git checkout develop
- $ mkdir build && cd build
- $ cmake .. -DENABLE_ORT_BACKEND=ON \
- -DENABLE_VISION=ON \
- -DENABLE_RKNPU2_BACKEND=ON \
- -DRKNN2_TARGET_SOC=RK3588 \
- -DCMAKE_INSTALL_PREFIX=${PWD}/fastdeploy-dev
- $ make -j8
- $ make install
-
- # 准备交叉编译工具链
- sudo apt install cmake build-essential
- wget https://bj.bcebos.com/fastdeploy/third_libs/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu.tar.gz
- tar -xzvf gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu.tar.gz -C /path/to/save
-
- # 编译
- cd FastDeploy
- mkdir build && cd build
- cmake .. -DCMAKE_C_COMPILER=/home/xxjianvm/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc \
- -DCMAKE_CXX_COMPILER=/home/xxjianvm/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ \
- -DCMAKE_TOOLCHAIN_FILE=./../cmake/toolchain.cmake \
- -DTARGET_ABI=arm64 \
- -DENABLE_ORT_BACKEND=OFF \
- -DENABLE_RKNPU2_BACKEND=ON \
- -DENABLE_VISION=ON \
- -DRKNN2_TARGET_SOC=RK3588 \
- -DCMAKE_INSTALL_PREFIX=/home/xxjianvm/Downloads/FastDeploy/install
- make -j8
- make install
RKNN2_TARGET_SOC可以选择RK3588/RK356X
- # 依赖
- sudo apt install git cmake g++ python3-pip
- # 获取FastDeploy源码
- git clone https://github.com/PaddlePaddle/FastDeploy.git
- cd FastDeploy/python
- git checkout develop
- # 编译
- # Python通过export环境变量设置编译选项
- export ENABLE_ORT_BACKEND=ON
- export ENABLE_RKNPU2_BACKEND=ON
- export ENABLE_VISION=ON
- # 请根据你的开发版的不同,选择RK3588和RK356X
- export RKNN2_TARGET_SOC=RK3588
- # 如果你的核心板的运行内存大于等于8G,我们建议您执行以下命令进行编译。
- python3 setup.py build
- # 值得注意的是,如果你的核心板的运行内存小于8G,我们建议您执行以下命令进行编译。
- python3 setup.py build -j1
- # 安装
-
- python3 setup.py bdist_wheel
- cd dist
- pip3 install fastdeploy_python-0.0.0-cp38-cp38-linux_aarch64.whl
选项 | 说明 |
ENABLE_ORT_BACKEND | 默认OFF, 是否编译集成ONNX Runtime后端(CPU/GPU上推荐打开) |
ENABLE_LITE_BACKEND | 默认OFF,是否编译集成Paddle Lite后端(编译Android库时需要设置为ON) |
ENABLE_RKNPU2_BACKEND | 默认OFF,是否编译集成RKNPU2后端(RK3588/RK3568/RK3566上推荐打开) |
ENABLE_VISION | 默认OFF,是否编译集成视觉模型的部署模块 |
RKNN2_TARGET_SOC | ENABLE_RKNPU2_BACKEND时才需要使用这个编译选项。无默认值, 可输入值为RK3588/RK356X, 必须填入,否则 将编译失败 |
ORT_DIRECTORY | 当开启ONNX Runtime后端时,用于指定用户本地的ONNX Runtime库路径;如果不指定,编译过程会自动下载ONNX Runtime库 |
OPENCV_DIRECTORY | 当ENABLE_VISION=ON时,用于指定用户本地的OpenCV库路径;如果不指定,编译过程会自动下载OpenCV库 |
- # 这里测试直接下载Paddle静态图模型并解压
- cd ~/Downloads
- wget https://paddledet.bj.bcebos.com/deploy/Inference/picodet_s_416_coco_lcnet.tar
- tar xvf picodet_s_416_coco_lcnet.tar
3.1 [PC]模型转换 paddle2onnx
- #设置环境
- source /home/xxjianvm/Downloads/FastDeploy/install/fastdeploy_init.sh
- export PATH="$PATH:/home/xxjianvm/.local/bin"
-
- # 静态图模型转换onnx模型,
- paddle2onnx --model_dir picodet_s_416_coco_lcnet \
- --model_filename model.pdmodel \
- --params_filename model.pdiparams \
- --save_file picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx \
- --enable_dev_version True
问题:paddle2onnx: command not found
解决办法:通过pip3 install 得到的 paddle2onnx,默认路径在 ~/.local/bin
export PATH="$PATH:/home/xxjianvm/.local/bin"
# 固定shape
- python3 -m paddle2onnx.optimize --input_model picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx \
- --output_model picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx \
- --input_shape_dict "{'image':[1,3,416,416]}"
# 最后模型保存在当前目录下picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx
切换目录
cd FastDeploy/tools/rknpu2
把
~/Downloads/picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet
拷贝到
FastDeploy/tools/rknpu2/picodet_s_416_coco_lcnet
打开 netron
打开文件 ->
FastDeploy/tools/rknpu2/picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx
导出rknn模型
python3 export.py --config_path config/picodet_s_416_coco_lcnet_unquantized.yaml --target_platform rk3588
- # 依赖
- pip3 install opencv-python
- # 切换目录
- cd /home/firefly/Downloads/FastDeploy/examples/vision/detection/paddledetection/rknpu2/python
- # 获取模型文件
- 把带有 picodet_s_416_coco_lcnet_rk3588_unquantized.rknn 的文件夹 picodet_s_416_coco_lcnet 拷贝到当前目录
-
- # 获取测试图片
- wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
-
- # 运行推理程序,--model_file 指定模型文件,--config_file 指定配置文件, --image 指定需要推理的图片
- $ export LD_LIBRARY_PATH=/home/firefly/Downloads/FastDeploy/build/fastdeploy-dev/third_libs/install/opencv/lib
- $ python3 infer.py --model_file picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet_rk3588_unquantized.rknn --config_file picodet_s_416_coco_lcnet/infer_cfg.yml --image 000000014439.jpg
-
- # 切换目录
- cd /home/firefly/Downloads/FastDeploy/examples/vision/detection/paddledetection/rknpu2/cpp
- # 修改源码中的模型名
- auto model_file = model_dir + "/picodet_s_416_coco_lcnet_rk3588_unquantized.rknn";
- # 配置
- mkdir build && cd build
- cmake .. -DFASTDEPLOY_INSTALL_DIR=/home/firefly/Downloads/FastDeploy/build/fastdeploy-dev
- # 编译
- make -j8
- # 准备模型
- 把带有 picodet_s_416_coco_lcnet_rk3588_unquantized.rknn 的文件夹 picodet_s_416_coco_lcnet 拷贝到/home/firefly/Downloads/FastDeploy/examples/vision/detection/paddledetection/rknpu2/cpp
- # 准备测试图片
- cd /home/firefly/Downloads/FastDeploy/examples/vision/detection/paddledetection/rknpu2/cpp
- wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
- # 设置环境变量
- # export LD_LIBRARY_PATH=/home/firefly/Downloads/FastDeploy/build/fastdeploy-dev/third_libs/install/opencv/lib:/home/firefly/Downloads/FastDeploy/build/fastdeploy-dev/third_libs/install/onnxruntime/lib:/home/firefly/Downloads/FastDeploy/build/fastdeploy-dev/third_libs/install/paddle2onnx/lib
- source /home/firefly/Downloads/FastDeploy/build/fastdeploy-dev/fastdeploy_init.sh
- # 推理
- cd /home/firefly/Downloads/FastDeploy/examples/vision/detection/paddledetection/rknpu2/cpp/build
- ./infer_picodet_demo /home/firefly/Downloads/FastDeploy/examples/vision/detection/paddledetection/rknpu2/cpp/picodet_s_416_coco_lcnet ../000000014439.jpg 0
- ./infer_picodet_demo /home/firefly/Downloads/FastDeploy/examples/vision/detection/paddledetection/rknpu2/cpp/picodet_s_416_coco_lcnet ../000000014439.jpg 1
参考:
- [1]FastDeploy RKNPU2 导航文档,https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/rknpu2.md
- [2]3. 飞桨(PaddlePaddle) FastDeploy,https://doc.embedfire.com/linux/rk356x/Ai/zh/latest/lubancat_ai/example/paddlepaddle_fastdeploy.html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。