Skip to content

Commit e2f5a9c

Browse files
[Model] Add picodet for RV1126 and A311D (#1549)
* add infer for picodet * update code * update lite lib --------- Co-authored-by: DefTruth <[email protected]>
1 parent cc4bbf2 commit e2f5a9c

File tree

16 files changed

+209
-50
lines changed

16 files changed

+209
-50
lines changed

cmake/toolchain.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (DEFINED TARGET_ABI)
1414
set(OPENCV_URL "https://bj.bcebos.com/fastdeploy/third_libs/opencv-linux-armv7hf-4.6.0.tgz")
1515
set(OPENCV_FILENAME "opencv-linux-armv7hf-4.6.0")
1616
if(WITH_TIMVX)
17-
set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-armhf-timvx-20221229.tgz")
17+
set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-armhf-timvx-20230316.tgz")
1818
else()
1919
message(STATUS "PADDLELITE_URL will be configured if WITH_TIMVX=ON.")
2020
endif()
@@ -33,7 +33,7 @@ if (DEFINED TARGET_ABI)
3333
set(OPENCV_URL "https://bj.bcebos.com/fastdeploy/third_libs/opencv-linux-aarch64-4.6.0.tgz")
3434
set(OPENCV_FILENAME "opencv-linux-aarch64-4.6.0")
3535
if(WITH_TIMVX)
36-
set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-aarch64-timvx-20221209.tgz")
36+
set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-aarch64-timvx-20230316.tgz")
3737
else()
3838
set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-arm64-20221209.tgz")
3939
endif()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
English | [简体中文](README_CN.md)
22
# Deploy PP-YOLOE Quantification Model on A311D
3-
Now FastDeploy supports the deployment of PP-YOLOE quantification model to A311D on Paddle Lite.
3+
Now FastDeploy supports the deployment of PP-YOLOE and PicoDet quantification model to A311D on Paddle Lite.
44

55
For model quantification and download, refer to [Model Quantification](../quantize/README.md)
66

77

88
## Detailed Deployment Tutorials
99

10-
Only C++ deployment is supported on A311D
10+
Only C++ deployment is supported on A311D
1111

1212
- [C++ deployment](cpp)

examples/vision/detection/paddledetection/a311d/README_CN.md

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[English](README.md) | 简体中文
22
# PP-YOLOE 量化模型在 A311D 上的部署
3-
目前 FastDeploy 已经支持基于 Paddle Lite 部署 PP-YOLOE 量化模型到 A311D 上。
3+
目前 FastDeploy 已经支持基于 Paddle Lite 部署 PP-YOLOE 和 PicoDet 量化模型到 A311D 上。
44

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

examples/vision/detection/paddledetection/a311d/cpp/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
1010
include_directories(${FASTDEPLOY_INCS})
1111
include_directories(${FastDeploy_INCLUDE_DIRS})
1212

13-
add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer_ppyoloe.cc)
13+
add_executable(ppyoloe_infer_demo ${PROJECT_SOURCE_DIR}/infer_ppyoloe.cc)
14+
add_executable(picodet_infer_demo ${PROJECT_SOURCE_DIR}/infer_picodet.cc)
1415
# 添加FastDeploy库依赖
15-
target_link_libraries(infer_demo ${FASTDEPLOY_LIBS})
16+
target_link_libraries(ppyoloe_infer_demo ${FASTDEPLOY_LIBS})
17+
target_link_libraries(picodet_infer_demo ${FASTDEPLOY_LIBS})
1618

1719
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/build/install)
1820

19-
install(TARGETS infer_demo DESTINATION ./)
21+
install(TARGETS ppyoloe_infer_demo DESTINATION ./)
22+
install(TARGETS picodet_infer_demo DESTINATION ./)
2023

2124
install(DIRECTORY models DESTINATION ./)
2225
install(DIRECTORY images DESTINATION ./)

examples/vision/detection/paddledetection/a311d/cpp/README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
English | [简体中文](README_CN.md)
2-
# PP-YOLOE Quantitative Model C++ Deployment Example
2+
# PP-YOLOE Quantitative Model C++ Deployment Example
33

4-
`infer.cc` in this directory can help you quickly complete the inference acceleration of PP-YOLOE quantization model deployment on A311D.
4+
`infer.cc` in this directory can help you quickly complete the inference acceleration of PP-YOLOE and PicoDet quantization model deployment on A311D.
55

66
## Deployment Preparations
77
### FastDeploy Cross-compile Environment Preparations
8-
1. For the software and hardware environment, and the cross-compile environment, please refer to [FastDeploy Cross-compile environment](../../../../../../docs/en/build_and_install/a311d.md#Cross-compilation-environment-construction)
8+
1. For the software and hardware environment, and the cross-compile environment, please refer to [Preparations for FastDeploy Cross-compile environment](../../../../../../docs/en/build_and_install/a311d.md#Cross-compilation-environment-construction).
99

1010
### Model Preparations
1111
1. You can directly use the quantized model provided by FastDeploy for deployment.
12-
2. You can use PaddleDetection to export Float32 models, note that you need to set the parameter when exporting model: use_shared_conv=False. For more information: [PP-YOLOE](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe).
12+
2. You can use PaddleDetection to export Float32 models, note that you need to set the parameter when exporting PP-YOLOE model: use_shared_conv=False. For more information: [PP-YOLOE](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe). For more information when exporting PicoDet model: [PicoDet](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/picodet).
1313
3. You can use [one-click automatical compression tool](../../../../../../tools/common_tools/auto_compression/) provided by FastDeploy to quantize model by yourself, and use the generated quantized model for deployment.(Note: The quantized classification model still needs the infer_cfg.yml file in the FP32 model folder. Self-quantized model folder does not contain this yaml file, you can copy it from the FP32 model folder to the quantized model folder.)
1414
4. The model requires heterogeneous computation. Please refer to: [Heterogeneous Computation](./../../../../../../docs/en/faq/heterogeneous_computing_on_timvx_npu.md). Since the model is already provided, you can test the heterogeneous file we provide first to verify whether the accuracy meets the requirements.
1515

1616
For more information, please refer to [Model Quantization](../../quantize/README.md)
1717

18-
## Deploying the Quantized PP-YOLOE Detection model on A311D
19-
Please follow these steps to complete the deployment of the PP-YOLOE quantization model on A311D.
20-
1. Cross-compile the FastDeploy library as described in [Cross-compile FastDeploy](../../../../../../docs/en/build_and_install/a311d.md#FastDeploy-cross-compilation-library-compilation-based-on-Paddle-Lite)
18+
## Deploying the Quantized PP-YOLOE and PicoDet Detection model on A311D
19+
Please follow these steps to complete the deployment of the PP-YOLOE and PicoDet quantization model on A311D.
20+
1. Cross-compile the FastDeploy library as described in [Cross-compile FastDeploy](../../../../../../docs/en/build_and_install/a311d.md#FastDeploy-cross-compilation-library-compilation-based-on-Paddle-Lite)
2121

2222
2. Copy the compiled library to the current directory. You can run this line:
2323
```bash
@@ -28,9 +28,14 @@ cp -r FastDeploy/build/fastdeploy-timvx/ FastDeploy/examples/vision/detection/pa
2828
```bash
2929
cd FastDeploy/examples/vision/detection/paddledetection/a311d/cpp
3030
mkdir models && mkdir images
31+
# download PP-YOLOE model
3132
wget https://bj.bcebos.com/fastdeploy/models/ppyoloe_noshare_qat.tar.gz
3233
tar -xvf ppyoloe_noshare_qat.tar.gz
3334
cp -r ppyoloe_noshare_qat models
35+
# download PicoDet model
36+
wget https://bj.bcebos.com/fastdeploy/models/picodet_withNMS_quant_qat.tar.gz
37+
tar -xvf picodet_withNMS_quant_qat.tar.gz
38+
cp -r picodet_withNMS_quant_qat models
3439
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
3540
cp -r 000000014439.jpg images
3641
```
@@ -45,12 +50,13 @@ make install
4550
# After success, an install folder will be created with a running demo and libraries required for deployment.
4651
```
4752

48-
5. Deploy the PP-YOLOE detection model to A311D based on adb.
53+
5. Deploy the PP-YOLOE and PicoDet detection model to A311D based on adb. You can run the following lines:
4954
```bash
5055
# Go to the install directory.
5156
cd FastDeploy/examples/vision/detection/paddledetection/a311d/cpp/build/install/
5257
# The following line represents: bash run_with_adb.sh, demo needed to run, model path, image path, DEVICE ID.
53-
bash run_with_adb.sh infer_demo ppyoloe_noshare_qat 000000014439.jpg $DEVICE_ID
58+
bash run_with_adb.sh ppyoloe_infer_demo ppyoloe_noshare_qat 000000014439.jpg $DEVICE_ID
59+
bash run_with_adb.sh picodet_infer_demo picodet_withNMS_quant_qat 000000014439.jpg $DEVICE_ID
5460
```
5561

5662
The output is:

examples/vision/detection/paddledetection/a311d/cpp/README_CN.md

100644100755
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
[English](README.md) | 简体中文
22
# PP-YOLOE 量化模型 C++ 部署示例
33

4-
本目录下提供的 `infer.cc`,可以帮助用户快速完成 PP-YOLOE 量化模型在 A311D 上的部署推理加速。
4+
本目录下提供的 `infer.cc`,可以帮助用户快速完成 PP-YOLOE 和 PicoDet 量化模型在 A311D 上的部署推理加速。
55

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

1010
### 模型准备
1111
1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。
12-
2. 用户可以先使用 PaddleDetection 自行导出 Float32 模型,注意导出模型模型时设置参数:use_shared_conv=False,更多细节请参考:[PP-YOLOE](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe)
12+
2. 用户可以先使用 PaddleDetection 自行导出 Float32 模型,注意导出 PP-YOLOE 模型时设置参数:use_shared_conv=False,更多细节请参考:[PP-YOLOE](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe),导出 PicoDet 请参考:[PicoDet](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/picodet)
1313
3. 用户可以使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。(注意: 推理量化后的检测模型仍然需要FP32模型文件夹下的 infer_cfg.yml 文件,自行量化的模型文件夹内不包含此 yaml 文件,用户从 FP32 模型文件夹下复制此yaml文件到量化后的模型文件夹内即可。)
1414
4. 模型需要异构计算,异构计算文件可以参考:[异构计算](./../../../../../../docs/cn/faq/heterogeneous_computing_on_timvx_npu.md),由于 FastDeploy 已经提供了模型,可以先测试我们提供的异构文件,验证精度是否符合要求。
1515

1616
更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
1717

18-
## 在 A311D 上部署量化后的 PP-YOLOE 检测模型
19-
请按照以下步骤完成在 A311D 上部署 PP-YOLOE 量化模型:
18+
## 在 A311D 上部署量化后的 PP-YOLOE 和 PicoDet 检测模型
19+
请按照以下步骤完成在 A311D 上部署 PP-YOLOE 和 PicoDet 量化模型:
2020
1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](../../../../../../docs/cn/build_and_install/a311d.md#基于-paddlelite-的-fastdeploy-交叉编译库编译)
2121

2222
2. 将编译后的库拷贝到当前目录,可使用如下命令:
@@ -28,9 +28,15 @@ cp -r FastDeploy/build/fastdeploy-timvx/ FastDeploy/examples/vision/detection/pa
2828
```bash
2929
cd FastDeploy/examples/vision/detection/paddledetection/a311d/cpp
3030
mkdir models && mkdir images
31+
# 下载 FastDeploy 准备的 PP-YOLOE 模型
3132
wget https://bj.bcebos.com/fastdeploy/models/ppyoloe_noshare_qat.tar.gz
3233
tar -xvf ppyoloe_noshare_qat.tar.gz
3334
cp -r ppyoloe_noshare_qat models
35+
# 下载 FastDeploy 准备的 PicoDet 模型
36+
wget https://bj.bcebos.com/fastdeploy/models/picodet_withNMS_quant_qat.tar.gz
37+
tar -xvf picodet_withNMS_quant_qat.tar.gz
38+
cp -r picodet_withNMS_quant_qat models
39+
# 下载 FastDeploy 准备的测试图片
3440
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
3541
cp -r 000000014439.jpg images
3642
```
@@ -45,12 +51,13 @@ make install
4551
# 成功编译之后,会生成 install 文件夹,里面有一个运行 demo 和部署所需的库
4652
```
4753

48-
5. 基于 adb 工具部署 PP-YOLOE 检测模型到晶晨 A311D
54+
5. 基于 adb 工具部署 PP-YOLOE 和 PicoDet 检测模型到 A311D,可使用如下命令:
4955
```bash
5056
# 进入 install 目录
5157
cd FastDeploy/examples/vision/detection/paddledetection/a311d/cpp/build/install/
5258
# 如下命令表示:bash run_with_adb.sh 需要运行的demo 模型路径 图片路径 设备的DEVICE_ID
53-
bash run_with_adb.sh infer_demo ppyoloe_noshare_qat 000000014439.jpg $DEVICE_ID
59+
bash run_with_adb.sh ppyoloe_infer_demo ppyoloe_noshare_qat 000000014439.jpg $DEVICE_ID
60+
bash run_with_adb.sh picodet_infer_demo picodet_withNMS_quant_qat 000000014439.jpg $DEVICE_ID
5461
```
5562

5663
部署成功后运行结果如下:
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "fastdeploy/vision.h"
16+
#ifdef WIN32
17+
const char sep = '\\';
18+
#else
19+
const char sep = '/';
20+
#endif
21+
22+
void InitAndInfer(const std::string& model_dir, const std::string& image_file) {
23+
auto model_file = model_dir + sep + "model.pdmodel";
24+
auto params_file = model_dir + sep + "model.pdiparams";
25+
auto config_file = model_dir + sep + "infer_cfg.yml";
26+
auto subgraph_file = model_dir + sep + "subgraph.txt";
27+
fastdeploy::vision::EnableFlyCV();
28+
fastdeploy::RuntimeOption option;
29+
option.UseTimVX();
30+
option.SetLiteSubgraphPartitionPath(subgraph_file);
31+
32+
auto model = fastdeploy::vision::detection::PicoDet(model_file, params_file,
33+
config_file, option);
34+
assert(model.Initialized());
35+
36+
auto im = cv::imread(image_file);
37+
38+
fastdeploy::vision::DetectionResult res;
39+
if (!model.Predict(im, &res)) {
40+
std::cerr << "Failed to predict." << std::endl;
41+
return;
42+
}
43+
44+
std::cout << res.Str() << std::endl;
45+
46+
auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.3);
47+
cv::imwrite("vis_result.jpg", vis_im);
48+
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
49+
}
50+
51+
int main(int argc, char* argv[]) {
52+
if (argc < 3) {
53+
std::cout << "Usage: picodet_infer_demo path/to/quant_model "
54+
"path/to/image "
55+
"e.g ./picodet_infer_demo ./picodet_ptq ./test.jpeg"
56+
<< std::endl;
57+
return -1;
58+
}
59+
60+
std::string model_dir = argv[1];
61+
std::string test_image = argv[2];
62+
InitAndInfer(model_dir, test_image);
63+
return 0;
64+
}

examples/vision/detection/paddledetection/a311d/cpp/infer_ppyoloe.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file) {
2424
auto params_file = model_dir + sep + "model.pdiparams";
2525
auto config_file = model_dir + sep + "infer_cfg.yml";
2626
auto subgraph_file = model_dir + sep + "subgraph.txt";
27-
fastdeploy::vision::EnableFlyCV();
27+
fastdeploy::vision::EnableFlyCV();
2828
fastdeploy::RuntimeOption option;
2929
option.UseTimVX();
3030
option.SetLiteSubgraphPartitionPath(subgraph_file);
@@ -46,14 +46,13 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file) {
4646
auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
4747
cv::imwrite("vis_result.jpg", vis_im);
4848
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
49-
5049
}
5150

5251
int main(int argc, char* argv[]) {
5352
if (argc < 3) {
54-
std::cout << "Usage: infer_demo path/to/quant_model "
53+
std::cout << "Usage: ppyoloe_infer_demo path/to/quant_model "
5554
"path/to/image "
56-
"e.g ./infer_demo ./PPYOLOE_L_quant ./test.jpeg"
55+
"e.g ./ppyoloe_infer_demo ./PPYOLOE_L_quant ./test.jpeg"
5756
<< std::endl;
5857
return -1;
5958
}

examples/vision/detection/paddledetection/rv1126/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
English | [简体中文](README_CN.md)
2-
# Deploy PP-YOLOE Quantification Model on RV1126
3-
Now FastDeploy supports the deployment of PP-YOLOE quantification model to RV1126 based on Paddle Lite.
2+
# Deploy PP-YOLOE and PicoDet Quantification Model on RV1126
3+
Now FastDeploy supports the deployment of PP-YOLOE and PicoDet quantification model to RV1126 based on Paddle Lite.
44

55
For model quantification and download, refer to [Model Quantification](../quantize/README.md)
66

examples/vision/detection/paddledetection/rv1126/README_CN.md

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[English](README.md) | 简体中文
2-
# PP-YOLOE 量化模型在 RV1126 上的部署
3-
目前 FastDeploy 已经支持基于 Paddle Lite 部署 PP-YOLOE 量化模型到 RV1126 上。
2+
# PP-YOLOE 和 PicoDet 量化模型在 RV1126 上的部署
3+
目前 FastDeploy 已经支持基于 Paddle Lite 部署 PP-YOLOE 和 PicoDet 量化模型到 RV1126 上。
44

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

0 commit comments

Comments
 (0)