基于凌蒙派开发板的FastDeploy适配 原创 精华

福州市凌睿智捷电子有限公司
发布于 2023-2-16 09:52
浏览
3收藏

FastDeploy简介

FastDeploy是一款全场景、易用灵活、极致高效的AI推理部署工具, 支持云边端部署。提供超过 160+
Text,Vision, Speech和跨模态模型开箱即用的部署体验,并实现端到端的推理性能优化。包括 物体检
测、字符识别(OCR)、人脸、人像扣图、多目标跟踪系统、NLP、Stable Difussion文图生成、TTS 等几十
种任务场景,满足开发者多场景、多硬件、多平台的产业部署需求。

准备工作

本文的FastDeploy适配过程需要准备如下:
凌蒙派-RK3568开发板(即需FastDeploy适配的设备终端)
Ubuntu(即建立于虚拟机的Linux编译环境)
目前,我已将FastDeploy适配到凌蒙派开发板上,可用于目标检测、人脸检测、人脸识别、人脸对齐、图像
分割、OCR等领域,这将大大提高凌蒙派开发板在边缘计算方面的能力。

编译步骤

我们推荐在PC上进行交叉编译(即在Ubuntu进行交叉编译)。

git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy
# 如果您使用的是develop分支输入以下命令
git checkout develop
mkdir build && cd build
cmake .. -DCMAKE_C_COMPILER=/home/zbc/opt/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-
linux-gnu/bin/aarch64-linux-gnu-gcc \
-DCMAKE_CXX_COMPILER=/home/zbc/opt/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=RK356X \
-DCMAKE_INSTALL_PREFIX=${PWD}/fastdeploy-0.0.0
make -j12
make install

目标检测模型速度表

为了方便大家选择最适合自己的模型,我们选取了目前最流行的几个模型,并整理了模型速度表供大家快速
浏览。以下测试速度均为端到端的速度。
基于凌蒙派开发板的FastDeploy适配-鸿蒙开发者社区

Demo演示

FastDeploy提供了统一的接口,可以快速的切换模型,这里以Yolov5为例子,展示如何在凌蒙派RK3568上
进行目标检测。

编写代码

// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "fastdeploy/vision.h"
void RKNPU2Infer(const std::string& model_file, const std::string& image_file) {
auto option = fastdeploy::RuntimeOption();
option.UseRKNPU2();
auto format = fastdeploy::ModelFormat::RKNN;
auto model = fastdeploy::vision::detection::RKYOLOV5(
model_file, option,format);
auto im = cv::imread(image_file);
fastdeploy::vision::DetectionResult res;
fastdeploy::TimeCounter tc;
tc.Start();
if (!model.Predict(im, &res)) {
std::cerr << "Failed to predict." << std::endl;
return;
}
auto vis_im = fastdeploy::vision::VisDetection(im, res,0.5);
tc.End();
tc.PrintInfo("RKYOLOV5 in RKNN");
std::cout << res.Str() << std::endl;
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
int main(int argc, char* argv[]) {
if (argc < 3) {
std::cout
<< "Usage: infer_demo path/to/model_dir path/to/image run_option, "
"e.g ./infer_model ./picodet_model_dir ./test.jpeg"
<< std::endl;
return -1;
}
RKNPU2Infer(argv[1], argv[2]);
return 0;
}

编译代码

# 编译
mkdir build
cd build
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-0.0.0
make -j4
# 下载图片
wget
https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
# 运行
./infer_rkyolov5 ../Model/yolov5-s-relu/yolov5s_relu_tk2_RK356X_i8.rknn
./000000014439.jpg

展示结果

输入图片

基于凌蒙派开发板的FastDeploy适配-鸿蒙开发者社区

输出图片

基于凌蒙派开发板的FastDeploy适配-鸿蒙开发者社区

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
5
收藏 3
回复
举报
4条回复
按时间正序
/
按时间倒序
红叶亦知秋
红叶亦知秋

几乎每个人都识别到了

回复
2023-2-16 10:16:05
福州市凌睿智捷电子有限公司
福州市凌睿智捷电子有限公司 回复了 红叶亦知秋
几乎每个人都识别到了

是的!感谢回复!

回复
2023-2-16 11:09:39
带带小老弟
带带小老弟

AI推理这种必须体验一下

回复
2023-2-17 14:33:23
福州市凌睿智捷电子有限公司
福州市凌睿智捷电子有限公司 回复了 带带小老弟
AI推理这种必须体验一下

感谢回复!

回复
2023-2-18 09:23:15
回复
    相关推荐