Skip to content

Commit

Permalink
[Doc] Update RKYOLO Docs (PaddlePaddle#1330)
Browse files Browse the repository at this point in the history
* 更新docs

* 修正docs错误

* 更新docs

* 更新python example脚本和ppyoloe转换脚本

* 更新PaddleDetection文档

* 更新文档

* 更新文档

* 更新文档

* 更新文档

* 更新文档

* 更新RKYOLO系列模型文档

* 更新PaddleDetection python example
  • Loading branch information
Zheng-Bicheng authored Feb 15, 2023
1 parent da94fc4 commit 32af870
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 14 deletions.
15 changes: 13 additions & 2 deletions examples/vision/detection/paddledetection/rknpu2/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ paddle2onnx --model_dir picodet_s_416_coco_lcnet \
# 固定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]}"
--input_shape_dict "{'image':[1,3,416,416], 'scale_factor':[1,2]}"
```

### 编写yaml文件
Expand All @@ -73,11 +73,12 @@ std:
```
**修改outputs参数**
由于Paddle2ONNX版本的不同,转换模型的输出节点名称也有所不同,请使用[Netron](https://netron.app)对模型进行可视化,并找到以下蓝色方框标记的NonMaxSuppression节点,红色方框的节点名称即为目标名称。
例如,使用Netron可视化后,得到以下图片:
![](https://user-images.githubusercontent.com/58363586/212599781-e1952da7-6eae-4951-8ca7-bab7e6940692.png)
![](https://ai-studio-static-online.cdn.bcebos.com/8bce6b904a6b479e8b30da9f7c719fad57517ffb2f234aeca3b8ace0761754d5)
找到蓝色方框标记的NonMaxSuppression节点,可以看到红色方框标记的两个节点名称为p2o.Div.79和p2o.Concat.9,因此需要修改outputs参数,修改后如下:
Expand All @@ -96,6 +97,16 @@ python tools/rknpu2/export.py --config_path tools/rknpu2/config/picodet_s_416_co
--target_platform rk3588
```

## RKNN模型列表

为了方便大家测试,我们提供picodet和ppyoloe两个模型,解压后即可使用:

| 模型名称 | 下载地址 |
|-----------------------------|-----------------------------------------------------------------------------------|
| picodet_s_416_coco_lcnet | https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/picodet_s_416_coco_lcnet.zip |
| ppyoloe_plus_crn_s_80e_coco | https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/ppyoloe_plus_crn_s_80e_coco.zip |



## 其他链接

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ target_link_libraries(infer_picodet_demo ${FASTDEPLOY_LIBS})

add_executable(infer_yolov8_demo ${PROJECT_SOURCE_DIR}/infer_yolov8_demo.cc)
target_link_libraries(infer_yolov8_demo ${FASTDEPLOY_LIBS})

add_executable(infer_ppyoloe_demo ${PROJECT_SOURCE_DIR}/infer_ppyoloe_demo.cc)
target_link_libraries(infer_ppyoloe_demo ${FASTDEPLOY_LIBS})
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
以上步骤请参考[RK2代NPU部署库编译](../../../../../../docs/cn/build_and_install/rknpu2.md)实现

```bash
以picodet为例进行推理部署
# 以picodet为例进行推理部署

mkdir build
cd build
Expand All @@ -23,6 +23,8 @@ cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x
make -j

# 下载PPYOLOE模型文件和测试图片
wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/picodet_s_416_coco_lcnet.zip
unzip picodet_s_416_coco_lcnet.zip
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg

# CPU推理
Expand All @@ -31,13 +33,6 @@ wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/0000000
./infer_picodet_demo ./picodet_s_416_coco_lcnet 000000014439.jpg 1
```

## 运行例程

```bash
cd ./build/install
./infer_picodet model/picodet_s_416_coco_lcnet images/000000014439.jpg
```

## 文档导航

- [模型介绍](../../)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// 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 ONNXInfer(const std::string& model_dir, const std::string& image_file) {
std::string model_file = model_dir + "/yolov8_n_500e_coco.onnx";
std::string params_file;
std::string config_file = model_dir + "/infer_cfg.yml";
auto option = fastdeploy::RuntimeOption();
option.UseCpu();
auto format = fastdeploy::ModelFormat::ONNX;

auto model = fastdeploy::vision::detection::PPYOLOE(
model_file, params_file, config_file, option, format);

fastdeploy::TimeCounter tc;
tc.Start();
auto im = cv::imread(image_file);
fastdeploy::vision::DetectionResult res;
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("PPDet in ONNX");

std::cout << res.Str() << std::endl;
cv::imwrite("infer_onnx.jpg", vis_im);
std::cout << "Visualized result saved in ./infer_onnx.jpg" << std::endl;
}

void RKNPU2Infer(const std::string& model_dir, const std::string& image_file) {
auto model_file = model_dir + "/ppyoloe_plus_crn_s_80e_coco_rk3588_quantized.rknn";
auto params_file = "";
auto config_file = model_dir + "/infer_cfg.yml";

auto option = fastdeploy::RuntimeOption();
option.UseRKNPU2();

auto format = fastdeploy::ModelFormat::RKNN;

auto model = fastdeploy::vision::detection::PPYOLOE(
model_file, params_file, config_file, option, format);

model.GetPreprocessor().DisablePermute();
model.GetPreprocessor().DisableNormalize();
model.GetPostprocessor().ApplyDecodeAndNMS();

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;
}
tc.End();
tc.PrintInfo("PPDet in RKNPU2");

std::cout << res.Str() << std::endl;
auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
cv::imwrite("infer_rknpu2.jpg", vis_im);
std::cout << "Visualized result saved in ./infer_rknpu2.jpg" << std::endl;
}

int main(int argc, char* argv[]) {
if (argc < 4) {
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;
}

if (std::atoi(argv[3]) == 0) {
ONNXInfer(argv[1], argv[2]);
} else if (std::atoi(argv[3]) == 1) {
RKNPU2Infer(argv[1], argv[2]);
}
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument(
"--model_file",
default="./picodet_s_416_coco_lcnet_non_postprocess/picodet_xs_416_coco_lcnet.onnx",
default="./picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet_rk3588_unquantized.rknn",
help="Path of rknn model.")
parser.add_argument(
"--config_file",
default="./picodet_s_416_coco_lcnet_non_postprocess/infer_cfg.yml",
default="./picodet_s_416_coco_lcnet/infer_cfg.yml",
help="Path of config.")
parser.add_argument(
"--image",
Expand Down
14 changes: 12 additions & 2 deletions examples/vision/detection/rkyolo/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ RKYOLO参考[rknn_model_zoo](https://github.com/airockchip/rknn_model_zoo/tree/m

## 支持模型列表

FastDeploy目前支持以下三个模型的部署:

* RKYOLOV5
* RKYOLOX
* RKYOLOv7

为了方便大家测试,我们提供了三个转换过后的模型,大家可以直接下载使用。
如果你有转换模型的需求,请参考[RKNN_model_convert](https://github.com/airockchip/rknn_model_zoo/tree/main/models/CV/object_detection/yolo/RKNN_model_convert)

## 模型转换example
| 模型名称 | 下载地址 |
|--------------------|---------------------------------------------------------------------|
| yolov5-s-relu-int8 | https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/yolov5-s-relu.zip |
| yolov7-tiny-int8 | https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/yolov7-tiny.zip |
| yolox-s-int8 | https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/yolox-s.zip |

请参考[RKNN_model_convert](https://github.com/airockchip/rknn_model_zoo/tree/main/models/CV/object_detection/yolo/RKNN_model_convert)


## 其他链接
Expand Down

0 comments on commit 32af870

Please sign in to comment.