一、主机模型转换
采用FastDeploy来部署应用深度学习模型到OK3588板卡上
进入主机Ubuntu的虚拟环境
conda activate ok3588
主机环境搭建可以参考上一篇 《OK3588板卡实现人像抠图(十二)》
转换成RKNN模型
cd FastDeploy
wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/scrfd_500m_bnkps_shape640x640.zip
unzip scrfd_500m_bnkps_shape640x640.zip
python tools/rknpu2/export.py \
--config_path tools/rknpu2/config/scrfd_unquantized.yaml \
--target_platform rk3588
得到scrfd_500m_bnkps_shape640x640_rk3588_unquantized.rknn 放到OK3588板卡上
二、板卡模型部署
进入虚拟环境
conda activate ok3588
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy
# 如果您使用的是develop分支输入以下命令
git checkout develop
mkdir build && cd build
cmake .. -DENABLE_ORT_BACKEND=OFF \
-DENABLE_RKNPU2_BACKEND=ON \
-DENABLE_VISION=ON \
-DRKNN2_TARGET_SOC=RK3588 \
-DCMAKE_INSTALL_PREFIX=${PWD}/fastdeploy-0.0.0
make -j2
make install
#为了方便大家配置环境变量,FastDeploy提供了一键配置环境变量的脚本
source fastdeploy-0.0.0/fastdeploy_init.sh
sudo cp fastdeploy-0.0.0/fastdeploy_libs.conf /etc/ld.so.conf.d/
sudo ldconfig
cd FastDeploy/examples/vision/facedet/scrfd/rknpu2/cpp
mkdir build
cd build
cmake .. -DFASTDEPLOY_INSTALL_DIR=/home/forlinx/FastDeploy/build/fastdeploy-0.0.0/
make -j
得到了编译后的文件 infer_demo
三、执行推理
把scrfd_500m_bnkps_shape640x640_rk3588_unquantized.rknn放在build里面
NPU推理
找一张测试图片
wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg
./infer_demo scrfd_500m_bnkps_shape640x640_rk3588_unquantized.rknn test_lite_face_detector_3.jpg 1
推理结果展示