当前位置:   article > 正文

瑞芯微RK3588s部署百度飞桨fastdeploy_fastdeploy python安装 rk3588

fastdeploy python安装 rk3588

0. 环境

- 虚拟机ubuntu20
- ROC-RK3588S-PC_Ubuntu20.04-Xfce-r3115_v1.3.0c_240131

1. 编译C++

1.1 [DEV]编译

  1. #安装依赖
  2. $ sudo apt install git cmake g++ python3-pip
  3. #获取源码
  4. $ cd ~/Downloads
  5. $ git clone https://github.com/PaddlePaddle/FastDeploy.git
  6. #压缩备份:
  7. $ 7z a FastDeploy_git_src_20240311.7z FastDeploy
  8. # 编译安装
  9. $ cd FastDeploy
  10. $ git checkout develop
  11. $ mkdir build && cd build
  12. $ cmake .. -DENABLE_ORT_BACKEND=ON \
  13.          -DENABLE_VISION=ON \
  14.          -DENABLE_RKNPU2_BACKEND=ON \
  15.          -DRKNN2_TARGET_SOC=RK3588 \
  16.          -DCMAKE_INSTALL_PREFIX=${PWD}/fastdeploy-dev
  17. $ make -j8
  18. $ make install

1.2 [PC]交叉编译

  1. # 准备交叉编译工具链
  2. sudo apt install cmake build-essential
  3. wget https://bj.bcebos.com/fastdeploy/third_libs/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu.tar.gz
  4. tar -xzvf gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu.tar.gz -C /path/to/save
  5. # 编译
  6. cd FastDeploy
  7. mkdir build && cd build
  8. cmake ..  -DCMAKE_C_COMPILER=/home/xxjianvm/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc \
  9.           -DCMAKE_CXX_COMPILER=/home/xxjianvm/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ \
  10.           -DCMAKE_TOOLCHAIN_FILE=./../cmake/toolchain.cmake \
  11.           -DTARGET_ABI=arm64 \
  12.           -DENABLE_ORT_BACKEND=OFF \
  13.           -DENABLE_RKNPU2_BACKEND=ON \
  14.           -DENABLE_VISION=ON \
  15.           -DRKNN2_TARGET_SOC=RK3588 \
  16.           -DCMAKE_INSTALL_PREFIX=/home/xxjianvm/Downloads/FastDeploy/install
  17. make -j8
  18. make install

RKNN2_TARGET_SOC可以选择RK3588/RK356X

2. [DEV]编译Python安装包

  1. # 依赖
  2. sudo apt install git cmake g++ python3-pip
  3. # 获取FastDeploy源码
  4. git clone https://github.com/PaddlePaddle/FastDeploy.git
  5. cd FastDeploy/python
  6. git checkout develop
  7. # 编译
  8. #     Python通过export环境变量设置编译选项
  9. export ENABLE_ORT_BACKEND=ON
  10. export ENABLE_RKNPU2_BACKEND=ON
  11. export ENABLE_VISION=ON
  12. #     请根据你的开发版的不同,选择RK3588和RK356X
  13. export RKNN2_TARGET_SOC=RK3588
  14. #     如果你的核心板的运行内存大于等于8G,我们建议您执行以下命令进行编译。
  15. python3 setup.py build
  16. #     值得注意的是,如果你的核心板的运行内存小于8G,我们建议您执行以下命令进行编译。
  17. python3 setup.py build -j1
  1. # 安装
  2. python3 setup.py bdist_wheel
  3. cd dist
  4. 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_SOCENABLE_RKNPU2_BACKEND时才需要使用这个编译选项。无默认值, 可输入值为RK3588/RK356X, 必须填入,否则 将编译失败
ORT_DIRECTORY当开启ONNX Runtime后端时,用于指定用户本地的ONNX Runtime库路径;如果不指定,编译过程会自动下载ONNX Runtime库
OPENCV_DIRECTORY当ENABLE_VISION=ON时,用于指定用户本地的OpenCV库路径;如果不指定,编译过程会自动下载OpenCV库


3. 模型转换

  1. # 这里测试直接下载Paddle静态图模型并解压
  2. cd ~/Downloads
  3. wget https://paddledet.bj.bcebos.com/deploy/Inference/picodet_s_416_coco_lcnet.tar
  4. tar xvf picodet_s_416_coco_lcnet.tar

3.1 [PC]模型转换 paddle2onnx

  1. #设置环境
  2. source /home/xxjianvm/Downloads/FastDeploy/install/fastdeploy_init.sh 
  3. export PATH="$PATH:/home/xxjianvm/.local/bin"
  4. # 静态图模型转换onnx模型,
  5. paddle2onnx --model_dir picodet_s_416_coco_lcnet \
  6.         --model_filename model.pdmodel \
  7.         --params_filename model.pdiparams \
  8.         --save_file picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx \
  9.         --enable_dev_version True

问题:paddle2onnx: command not found
解决办法:通过pip3 install 得到的 paddle2onnx,默认路径在 ~/.local/bin

export PATH="$PATH:/home/xxjianvm/.local/bin"

# 固定shape

  1. python3 -m paddle2onnx.optimize --input_model picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx \
  2.                             --output_model picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx \
  3.                             --input_shape_dict "{'image':[1,3,416,416]}"

# 最后模型保存在当前目录下picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx

3.2 [PC]模型转换 onnx2rknn

切换目录

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

4. 推理

4.1 [DEV]推理测试 python

  1. # 依赖 
  2. pip3 install opencv-python
  3. # 切换目录
  4. cd /home/firefly/Downloads/FastDeploy/examples/vision/detection/paddledetection/rknpu2/python
  5. # 获取模型文件
  6. 把带有 picodet_s_416_coco_lcnet_rk3588_unquantized.rknn 的文件夹 picodet_s_416_coco_lcnet 拷贝到当前目录
  7. # 获取测试图片
  8. wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
  9. # 运行推理程序,--model_file 指定模型文件,--config_file 指定配置文件, --image 指定需要推理的图片
  10. $ export LD_LIBRARY_PATH=/home/firefly/Downloads/FastDeploy/build/fastdeploy-dev/third_libs/install/opencv/lib
  11. $ 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

 

4.2 [DEV]推理测试 c++

  1. # 切换目录
  2. cd /home/firefly/Downloads/FastDeploy/examples/vision/detection/paddledetection/rknpu2/cpp
  3. # 修改源码中的模型名
  4.   auto model_file = model_dir + "/picodet_s_416_coco_lcnet_rk3588_unquantized.rknn";
  5. # 配置
  6. mkdir build && cd build
  7. cmake .. -DFASTDEPLOY_INSTALL_DIR=/home/firefly/Downloads/FastDeploy/build/fastdeploy-dev
  8. # 编译
  9. make -j8
  10. # 准备模型
  11. 把带有 picodet_s_416_coco_lcnet_rk3588_unquantized.rknn 的文件夹 picodet_s_416_coco_lcnet 拷贝到/home/firefly/Downloads/FastDeploy/examples/vision/detection/paddledetection/rknpu2/cpp
  12. # 准备测试图片
  13. cd /home/firefly/Downloads/FastDeploy/examples/vision/detection/paddledetection/rknpu2/cpp
  14. wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
  15. # 设置环境变量
  16. # 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
  17. source /home/firefly/Downloads/FastDeploy/build/fastdeploy-dev/fastdeploy_init.sh 
  18. # 推理
  19. cd /home/firefly/Downloads/FastDeploy/examples/vision/detection/paddledetection/rknpu2/cpp/build
  20. ./infer_picodet_demo /home/firefly/Downloads/FastDeploy/examples/vision/detection/paddledetection/rknpu2/cpp/picodet_s_416_coco_lcnet ../000000014439.jpg 0
  21. ./infer_picodet_demo /home/firefly/Downloads/FastDeploy/examples/vision/detection/paddledetection/rknpu2/cpp/picodet_s_416_coco_lcnet ../000000014439.jpg 1

参考:

  1. [1]FastDeploy RKNPU2 导航文档,https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/rknpu2.md
  2. [2]3. 飞桨(PaddlePaddle) FastDeploy,https://doc.embedfire.com/linux/rk356x/Ai/zh/latest/lubancat_ai/example/paddlepaddle_fastdeploy.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/323030
推荐阅读
相关标签
  

闽ICP备14008679号