Skip to content

Commit

Permalink
[Model] Update PPDetection RKNPU2 (PaddlePaddle#1323)
Browse files Browse the repository at this point in the history
* 更新docs

* 修正docs错误

* 更新docs

* 更新python example脚本和ppyoloe转换脚本
  • Loading branch information
Zheng-Bicheng authored Feb 14, 2023
1 parent 41c5f2d commit fc6edcc
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 126 deletions.
81 changes: 77 additions & 4 deletions examples/vision/detection/paddledetection/rknpu2/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

## 支持模型列表

目前FastDeploy使用RKNPU2支持如下PaddleDetection模型的部署:
在RKNPU2上已经通过测试的PaddleDetection模型如下:

- Picodet
- PPYOLOE
- PPYOLOE(int8)
- YOLOV8

如果你需要查看详细的速度信息,请查看[RKNPU2模型速度一览表](../../../../../docs/cn/faq/rknpu2/rknpu2.md)

## 准备PaddleDetection部署模型以及转换模型

RKNPU部署模型前需要将Paddle模型转换成RKNN模型,具体步骤如下:
Expand All @@ -20,8 +22,79 @@ RKNPU部署模型前需要将Paddle模型转换成RKNN模型,具体步骤如

## 模型转换example

- [Picodet RKNPU2模型转换文档](./picodet.md)
- [YOLOv8 RKNPU2模型转换文档](./yolov8.md)
### 注意点

PPDetection模型在RKNPU2上部署时要注意以下几点:

* 模型导出需要包含Decode
* 由于RKNPU2不支持NMS,因此输出节点必须裁剪至NMS之前
* 由于RKNPU2 Div算子的限制,模型的输出节点需要裁剪至Div算子之前

### Paddle模型转换为ONNX模型

由于Rockchip提供的rknn-toolkit2工具暂时不支持Paddle模型直接导出为RKNN模型,因此需要先将Paddle模型导出为ONNX模型,再将ONNX模型转为RKNN模型。

```bash
# 以Picodet为例
# 下载Paddle静态图模型并解压
wget https://paddledet.bj.bcebos.com/deploy/Inference/picodet_s_416_coco_lcnet.tar
tar xvf picodet_s_416_coco_lcnet.tar

# 静态图转ONNX模型,注意,这里的save_file请和压缩包名对齐
paddle2onnx --model_dir picodet_s_416_coco_lcnet \
--model_filename model.pdmodel \
--params_filename model.pdiparams \
--save_file picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx \
--enable_dev_version True

# 固定shape
python -m paddle2onnx.optimize --input_model picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx \
--output_model picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx \
--input_shape_dict "{'image':[1,3,416,416]}"
```

### 编写yaml文件

**修改normalize参数**

如果你需要在NPU上执行normalize操作,请根据你的模型配置normalize参数,例如:

```yaml
mean:
-
- 123.675
- 116.28
- 103.53
std:
-
- 58.395
- 57.12
- 57.375
```
**修改outputs参数**
由于Paddle2ONNX版本的不同,转换模型的输出节点名称也有所不同,请使用[Netron](https://netron.app)对模型进行可视化,并找到以下蓝色方框标记的NonMaxSuppression节点,红色方框的节点名称即为目标名称。
例如,使用Netron可视化后,得到以下图片:
![](https://user-images.githubusercontent.com/58363586/212599781-e1952da7-6eae-4951-8ca7-bab7e6940692.png)
找到蓝色方框标记的NonMaxSuppression节点,可以看到红色方框标记的两个节点名称为p2o.Div.79和p2o.Concat.9,因此需要修改outputs参数,修改后如下:
```yaml
outputs_nodes:
- 'p2o.Mul.179'
- 'p2o.Concat.9'
```
### ONNX模型转RKNN模型
为了方便大家使用,我们提供了python脚本,通过我们预配置的config文件,你将能够快速地转换ONNX模型到RKNN模型
```bash
python tools/rknpu2/export.py --config_path tools/rknpu2/config/picodet_s_416_coco_lcnet_unquantized.yaml \
--target_platform rk3588
```


## 其他链接
Expand Down
68 changes: 0 additions & 68 deletions examples/vision/detection/paddledetection/rknpu2/picodet.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ def parse_arguments():

# 配置runtime,加载模型
runtime_option = fd.RuntimeOption()
runtime_option.use_cpu()
runtime_option.use_rknpu2()

model = fd.vision.detection.PPYOLOE(
model_file,
params_file,
config_file,
runtime_option=runtime_option,
model_format=fd.ModelFormat.ONNX)

model_format=fd.ModelFormat.RKNN)
model.preprocessor.disable_normalize()
model.preprocessor.disable_permute()
model.postprocessor.apply_decode_and_nms()

# 预测图片分割结果
Expand Down
50 changes: 0 additions & 50 deletions examples/vision/detection/paddledetection/rknpu2/yolov8.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ std:
- 57.375
model_path: ./picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx
outputs_nodes:
- 'p2o.Div.79'
- 'p2o.Mul.179'
- 'p2o.Concat.9'
do_quantization: False
dataset:
Expand Down
17 changes: 17 additions & 0 deletions tools/rknpu2/config/ppyoloe_plus_crn_s_80e_coco_quantized.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
mean:
-
- 0
- 0
- 0
std:
-
- 255
- 255
- 255
model_path: ./ppyoloe_plus_crn_s_80e_coco/ppyoloe_plus_crn_s_80e_coco.onnx
outputs_nodes:
- 'p2o.Mul.224'
- 'p2o.Concat.29'
do_quantization: True
dataset: "./ppyoloe_plus_crn_s_80e_coco/dataset.txt"
output_folder: "./ppyoloe_plus_crn_s_80e_coco"

0 comments on commit fc6edcc

Please sign in to comment.