Skip to content

Commit

Permalink
[Backend] Add YOLOv5、PPYOLOE and PP-Liteseg for RV1126 (#647)
Browse files Browse the repository at this point in the history
* add yolov5 and ppyoloe for rk1126

* update code, rename rk1126 to rv1126

* add PP-Liteseg

* update lite lib

* updade doc for PPYOLOE

* update doc

* fix docs

* fix doc and examples

* update code

* uodate doc

* update doc

Co-authored-by: Jason <jiangjiajun@baidu.com>
  • Loading branch information
yeliang2258 and jiangjiajun committed Dec 5, 2022
1 parent 763da98 commit 104d965
Show file tree
Hide file tree
Showing 59 changed files with 804 additions and 987 deletions.
6 changes: 3 additions & 3 deletions README_CN.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@

<div id="fastdeploy-quick-start-python"></div>

<details close>
<details close>

<summary><b>Python SDK快速开始(点开查看详情)</b></summary><div>

#### 快速安装
Expand Down Expand Up @@ -131,7 +131,7 @@ cv2.imwrite("vis_image.jpg", vis_im)
<div id="fastdeploy-quick-start-cpp"></div>

<details close>

<summary><b>C++ SDK快速开始(点开查看详情)</b></summary><div>


Expand Down
Empty file modified README_EN.md
100644 → 100755
Empty file.
12 changes: 7 additions & 5 deletions cmake/opencv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ elseif(IOS)
else()
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
set(OPENCV_FILENAME "opencv-linux-aarch64-3.4.14")
elseif(TARGET_ABI MATCHES "armhf")
set(OPENCV_FILENAME "opencv-armv7hf")
else()
set(OPENCV_FILENAME "opencv-linux-x64-3.4.16")
if(ENABLE_TIMVX)
set(OPENCV_FILENAME "opencv-armv7hf")
else()
set(OPENCV_FILENAME "opencv-linux-x64-3.4.16")
endif()
endif()
if(ENABLE_OPENCV_CUDA)
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
Expand All @@ -57,7 +59,7 @@ endif()
set(OPENCV_INSTALL_DIR ${THIRD_PARTY_PATH}/install/)
if(ANDROID)
set(OPENCV_URL_PREFIX "https://bj.bcebos.com/fastdeploy/third_libs")
elseif(TARGET_ABI MATCHES "armhf")
elseif(ENABLE_TIMVX)
set(OPENCV_URL_PREFIX "https://bj.bcebos.com/fastdeploy/test")
else() # TODO: use fastdeploy/third_libs instead.
set(OPENCV_URL_PREFIX "https://bj.bcebos.com/paddle2onnx/libs")
Expand Down Expand Up @@ -185,7 +187,7 @@ else()
file(RENAME ${THIRD_PARTY_PATH}/install/${OPENCV_FILENAME}/ ${THIRD_PARTY_PATH}/install/opencv)
set(OPENCV_FILENAME opencv)
set(OpenCV_DIR ${THIRD_PARTY_PATH}/install/${OPENCV_FILENAME})
if(TARGET_ABI MATCHES "armhf")
if(ENABLE_TIMVX)
set(OpenCV_DIR ${OpenCV_DIR}/lib/cmake/opencv4)
endif()
if (WIN32)
Expand Down
8 changes: 5 additions & 3 deletions cmake/paddlelite.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ elseif(ANDROID)
else() # Linux
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
set(PADDLELITE_URL "${PADDLELITE_URL_PREFIX}/lite-linux-arm64-20220920.tgz")
elseif(TARGET_ABI MATCHES "armhf")
set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/test/lite-linux_armhf_1101.tgz")
else()
message(FATAL_ERROR "Only support Linux aarch64 now, x64 is not supported with backend Paddle Lite.")
if(ENABLE_TIMVX)
set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/test/lite-linux_armhf_1130.tgz")
else()
message(FATAL_ERROR "Only support Linux aarch64 or ENABLE_TIMVX now, x64 is not supported with backend Paddle Lite.")
endif()
endif()
endif()

Expand Down
3 changes: 1 addition & 2 deletions cmake/timvx.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
if (NOT DEFINED TARGET_ABI)
if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER "arm-linux-gnueabihf-gcc")
set(CMAKE_CXX_COMPILER "arm-linux-gnueabihf-g++")
set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 ${CMAKE_C_FLAGS}" )
set(TARGET_ABI armhf)
set(CMAKE_BUILD_TYPE MinSizeRel)
else()
if(NOT ${ENABLE_LITE_BACKEND})
Expand Down
5 changes: 3 additions & 2 deletions docs/cn/build_and_install/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
## 自行编译安装
- [GPU部署环境](gpu.md)
- [CPU部署环境](cpu.md)
- [CPU部署环境](ipu.md)
- [IPU部署环境](ipu.md)
- [Jetson部署环境](jetson.md)
- [Android平台部署环境](android.md)
- [瑞芯微RK1126部署环境](rk1126.md)
- [瑞芯微RV1126部署环境](rv1126.md)


## FastDeploy编译选项说明
Expand All @@ -22,6 +22,7 @@
| ENABLE_PADDLE_BACKEND | 默认OFF,是否编译集成Paddle Inference后端(CPU/GPU上推荐打开) |
| ENABLE_LITE_BACKEND | 默认OFF,是否编译集成Paddle Lite后端(编译Android库时需要设置为ON) |
| ENABLE_RKNPU2_BACKEND | 默认OFF,是否编译集成RKNPU2后端(RK3588/RK3568/RK3566上推荐打开) |
| ENABLE_TIMVX | 默认OFF,需要在RV1126/RV1109上部署时,需设置为ON |
| ENABLE_TRT_BACKEND | 默认OFF,是否编译集成TensorRT后端(GPU上推荐打开) |
| ENABLE_OPENVINO_BACKEND | 默认OFF,是否编译集成OpenVINO后端(CPU上推荐打开) |
| ENABLE_VISION | 默认OFF,是否编译集成视觉模型的部署模块 |
Expand Down
63 changes: 0 additions & 63 deletions docs/cn/build_and_install/rk1126.md

This file was deleted.

100 changes: 100 additions & 0 deletions docs/cn/build_and_install/rv1126.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# 瑞芯微 RV1126 部署环境编译安装

FastDeploy基于 Paddle-Lite 后端支持在瑞芯微(Rockchip)Soc 上进行部署推理。
更多详细的信息请参考:[PaddleLite部署示例](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html)

本文档介绍如何编译基于 PaddleLite 的 C++ FastDeploy 交叉编译库。

相关编译选项说明如下:
|编译选项|默认值|说明|备注|
|:---|:---|:---|:---|
|ENABLE_LITE_BACKEND|OFF|编译RK库时需要设置为ON| - |
|ENABLE_TIMVX|OFF|编译RK库时需要设置为ON| - |

更多编译选项请参考[FastDeploy编译选项说明](./README.md)

## 交叉编译环境搭建

### 宿主机环境需求
- os:Ubuntu == 16.04
- cmake: version >= 3.10.0

### 环境搭建
```bash
# 1. Install basic software
apt update
apt-get install -y --no-install-recommends \
gcc g++ git make wget python unzip

# 2. Install arm gcc toolchains
apt-get install -y --no-install-recommends \
g++-arm-linux-gnueabi gcc-arm-linux-gnueabi \
g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf \
gcc-aarch64-linux-gnu g++-aarch64-linux-gnu

# 3. Install cmake 3.10 or above
wget -c https://mms-res.cdn.bcebos.com/cmake-3.10.3-Linux-x86_64.tar.gz && \
tar xzf cmake-3.10.3-Linux-x86_64.tar.gz && \
mv cmake-3.10.3-Linux-x86_64 /opt/cmake-3.10 && \
ln -s /opt/cmake-3.10/bin/cmake /usr/bin/cmake && \
ln -s /opt/cmake-3.10/bin/ccmake /usr/bin/ccmake
```

## 基于 PaddleLite 的 FastDeploy 交叉编译库编译
搭建好交叉编译环境之后,编译命令如下:
```bash
# Download the latest source code
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy
mkdir build && cd build

# CMake configuration with RK toolchain
cmake -DCMAKE_TOOLCHAIN_FILE=./../cmake/timvx.cmake \
-DENABLE_TIMVX=ON \
-DCMAKE_INSTALL_PREFIX=fastdeploy-tmivx \
-DENABLE_VISION=ON \ # 是否编译集成视觉模型的部署模块,可选择开启
-Wno-dev ..

# Build FastDeploy RV1126 C++ SDK
make -j8
make install
```
编译完成之后,会生成 fastdeploy-tmivx 目录,表示基于 PadddleLite TIM-VX 的 FastDeploy 库编译完成。

## 准备设备运行环境
部署前要保证芯原 Linux Kernel NPU 驱动 galcore.so 版本及所适用的芯片型号与依赖库保持一致,在部署前,请登录开发板,并通过命令行输入以下命令查询 NPU 驱动版本,Rockchip建议的驱动版本为: 6.4.6.5
```bash
dmesg | grep Galcore
```

如果当前版本不符合上述,请用户仔细阅读以下内容,以保证底层 NPU 驱动环境正确。

有两种方式可以修改当前的 NPU 驱动版本:
1. 手动替换 NPU 驱动版本。(推荐)
2. 刷机,刷取 NPU 驱动版本符合要求的固件。

### 手动替换 NPU 驱动版本
1. 使用如下命令下载解压 PaddleLite demo,其中提供了现成的驱动文件
```bash
wget https://paddlelite-demo.bj.bcebos.com/devices/generic/PaddleLite-generic-demo.tar.gz
tar -xf PaddleLite-generic-demo.tar.gz
```
2. 使用 `uname -a` 查看 `Linux Kernel` 版本,确定为 `Linux` 系统 4.19.111 版本,
3.`PaddleLite-generic-demo/libs/PaddleLite/linux/armhf/lib/verisilicon_timvx/viv_sdk_6_4_6_5/lib/1126/4.19.111/` 路径下的 `galcore.ko` 上传至开发板。

4. 登录开发板,命令行输入 `sudo rmmod galcore` 来卸载原始驱动,输入 `sudo insmod galcore.ko` 来加载传上设备的驱动。(是否需要 sudo 根据开发板实际情况,部分 adb 链接的设备请提前 adb root)。此步骤如果操作失败,请跳转至方法 2。
5. 在开发板中输入 `dmesg | grep Galcore` 查询 NPU 驱动版本,确定为:6.4.6.5

### 刷机
根据具体的开发板型号,向开发板卖家或官网客服索要 6.4.6.5 版本 NPU 驱动对应的固件和刷机方法。

更多细节请参考:[PaddleLite准备设备环境](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html#zhunbeishebeihuanjing)

## 基于 FastDeploy 在 RV1126 上的部署示例
1. RV1126 上部署 PaddleClas 分类模型请参考:[PaddleClas 分类模型在 RV1126 上的 C++ 部署示例](../../../examples/vision/classification/paddleclas/rv1126/README.md)

2. RV1126 上部署 PPYOLOE 检测模型请参考:[PPYOLOE 检测模型在 RV1126 上的 C++ 部署示例](../../../examples/vision/detection/paddledetection/rv1126/README.md)

3. RV1126 上部署 YOLOv5 检测模型请参考:[YOLOv5 检测模型在 RV1126 上的 C++ 部署示例](../../../examples/vision/detection/yolov5/rv1126/README.md)

4. RV1126 上部署 PP-LiteSeg 分割模型请参考:[PP-LiteSeg 分割模型在 RV1126 上的 C++ 部署示例](../../../examples/vision/segmentation/paddleseg/rv1126/README.md)
2 changes: 1 addition & 1 deletion examples/vision/classification/paddleclas/quantize/README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工

## FastDeploy一键模型自动化压缩工具
FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化.
详细教程请见: [一键模型自动化压缩工具](../../../../../tools/auto_compression/)
详细教程请见: [一键模型自动化压缩工具](../../../../../tools/common_tools/auto_compression/)
注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的inference_cls.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可。

## 下载量化完成的PaddleClas模型
Expand Down
2 changes: 1 addition & 1 deletion examples/vision/classification/paddleclas/quantize/cpp/README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

### 量化模型准备
- 1. 用户可以直接使用由FastDeploy提供的量化模型进行部署.
- 2. 用户可以使用FastDeploy提供的[一键模型自动化压缩工具](../../../../../../tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的inference_cls.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.)
- 2. 用户可以使用FastDeploy提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的inference_cls.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.)

## 以量化后的ResNet50_Vd模型为例, 进行部署,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0)
在本目录执行如下命令即可完成编译,以及量化模型部署.
Expand Down
2 changes: 1 addition & 1 deletion examples/vision/classification/paddleclas/quantize/python/README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

### 量化模型准备
- 1. 用户可以直接使用由FastDeploy提供的量化模型进行部署.
- 2. 用户可以使用FastDeploy提供的[一键模型自动化压缩工具](../../../../../../tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的inference_cls.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.)
- 2. 用户可以使用FastDeploy提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的inference_cls.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.)


## 以量化后的ResNet50_Vd模型为例, 进行部署
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# PaddleClas 量化模型在 RK1126 上的部署
目前 FastDeploy 已经支持基于 PaddleLite 部署 PaddleClas 量化模型到 RK1126 上。
# PaddleClas 量化模型在 RV1126 上的部署
目前 FastDeploy 已经支持基于 PaddleLite 部署 PaddleClas 量化模型到 RV1126 上。

模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md)


## 详细部署文档

RK1126 上只支持 C++ 的部署。
RV1126 上只支持 C++ 的部署。

- [C++部署](cpp)
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# PaddleClas RK1126开发板 C++ 部署示例
本目录下提供的 `infer.cc`,可以帮助用户快速完成 PaddleClas 量化模型在 RK1126 上的部署推理加速。
# PaddleClas RV1126 开发板 C++ 部署示例
本目录下提供的 `infer.cc`,可以帮助用户快速完成 PaddleClas 量化模型在 RV1126 上的部署推理加速。

## 部署准备
### FastDeploy 交叉编译环境准备
- 1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/rk1126.md#交叉编译环境搭建)
- 1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/rv1126.md#交叉编译环境搭建)

### 量化模型准备
- 1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。
- 2. 用户可以使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的inference_cls.yaml文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从 FP32 模型文件夹下复制此 yaml 文件到量化后的模型文件夹内即可.)
- 2. 用户可以使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的inference_cls.yaml文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从 FP32 模型文件夹下复制此 yaml 文件到量化后的模型文件夹内即可.)
- 更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)

## RK1126 上部署量化后的 ResNet50_Vd 分类模型
请按照以下步骤完成在 RK1126 上部署 ResNet50_Vd 量化模型:
1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](../../../../../../docs/cn/build_and_install/rk1126.md#基于-paddlelite-的-fastdeploy-交叉编译库编译)
## RV1126 上部署量化后的 ResNet50_Vd 分类模型
请按照以下步骤完成在 RV1126 上部署 ResNet50_Vd 量化模型:
1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](../../../../../../docs/cn/build_and_install/rv1126.md#基于-paddlelite-的-fastdeploy-交叉编译库编译)

2. 将编译后的库拷贝到当前目录,可使用如下命令:
```bash
cp -r FastDeploy/build/fastdeploy-tmivx/ FastDeploy/examples/vision/classification/paddleclas/rk1126/cpp/
cp -r FastDeploy/build/fastdeploy-tmivx/ FastDeploy/examples/vision/classification/paddleclas/rv1126/cpp/
```

3. 在当前路径下载部署所需的模型和示例图片:
Expand All @@ -32,7 +32,7 @@ cp -r ILSVRC2012_val_00000010.jpeg images
4. 编译部署示例,可使入如下命令:
```bash
mkdir build && cd build
cmake -DCMAKE_TOOLCHAIN_FILE=../fastdeploy-tmivx/timvx.cmake -DFASTDEPLOY_INSTALL_DIR=fastdeploy-tmivx ..
cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-tmivx/timvx.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-tmivx ..
make -j8
make install
# 成功编译之后,会生成 install 文件夹,里面有一个运行 demo 和部署所需的库
Expand All @@ -41,7 +41,7 @@ make install
5. 基于 adb 工具部署 ResNet50_vd 分类模型到 Rockchip RV1126,可使用如下命令:
```bash
# 进入 install 目录
cd FastDeploy/examples/vision/classification/paddleclas/rk1126/cpp/build/install/
cd FastDeploy/examples/vision/classification/paddleclas/rv1126/cpp/build/install/
# 如下命令表示:bash run_with_adb.sh 需要运行的demo 模型路径 图片路径 设备的DEVICE_ID
bash run_with_adb.sh infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg $DEVICE_ID
```
Expand All @@ -50,4 +50,4 @@ bash run_with_adb.sh infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg $

<img width="640" src="https://user-images.githubusercontent.com/30516196/200767389-26519e50-9e4f-4fe1-8d52-260718f73476.png">

需要特别注意的是,在 RK1126 上部署的模型需要是量化后的模型,模型的量化请参考:[模型量化](../../../../../../docs/cn/quantize.md)
需要特别注意的是,在 RV1126 上部署的模型需要是量化后的模型,模型的量化请参考:[模型量化](../../../../../../docs/cn/quantize.md)
2 changes: 1 addition & 1 deletion examples/vision/detection/paddledetection/quantize/README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工

## FastDeploy一键模型自动化压缩工具
FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化.
详细教程请见: [一键模型自动化压缩工具](../../../../../tools/auto_compression/)
详细教程请见: [一键模型自动化压缩工具](../../../../../tools/common_tools/auto_compression/)

## 下载量化完成的PP-YOLOE-l模型
用户也可以直接下载下表中的量化模型进行部署.(点击模型名字即可下载)
Expand Down
Loading

0 comments on commit 104d965

Please sign in to comment.