diff --git a/examples/vision/detection/paddledetection/rknpu2/README_CN.md b/examples/vision/detection/paddledetection/rknpu2/README_CN.md index 6a932fe3a..781368ddc 100644 --- a/examples/vision/detection/paddledetection/rknpu2/README_CN.md +++ b/examples/vision/detection/paddledetection/rknpu2/README_CN.md @@ -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文件 @@ -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参数,修改后如下: @@ -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 | + + ## 其他链接 diff --git a/examples/vision/detection/paddledetection/rknpu2/cpp/CMakeLists.txt b/examples/vision/detection/paddledetection/rknpu2/cpp/CMakeLists.txt index 41db4b136..6ecb3d52c 100644 --- a/examples/vision/detection/paddledetection/rknpu2/cpp/CMakeLists.txt +++ b/examples/vision/detection/paddledetection/rknpu2/cpp/CMakeLists.txt @@ -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}) diff --git a/examples/vision/detection/paddledetection/rknpu2/cpp/README_CN.md b/examples/vision/detection/paddledetection/rknpu2/cpp/README_CN.md index 18ddfa77a..b98f0632c 100644 --- a/examples/vision/detection/paddledetection/rknpu2/cpp/README_CN.md +++ b/examples/vision/detection/paddledetection/rknpu2/cpp/README_CN.md @@ -12,7 +12,7 @@ 以上步骤请参考[RK2代NPU部署库编译](../../../../../../docs/cn/build_and_install/rknpu2.md)实现 ```bash -以picodet为例进行推理部署 +# 以picodet为例进行推理部署 mkdir build cd build @@ -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推理 @@ -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 -``` - ## 文档导航 - [模型介绍](../../) diff --git a/examples/vision/detection/paddledetection/rknpu2/cpp/infer_ppyoloe_demo.cc b/examples/vision/detection/paddledetection/rknpu2/cpp/infer_ppyoloe_demo.cc new file mode 100644 index 000000000..098c6a44e --- /dev/null +++ b/examples/vision/detection/paddledetection/rknpu2/cpp/infer_ppyoloe_demo.cc @@ -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; +} diff --git a/examples/vision/detection/paddledetection/rknpu2/python/infer.py b/examples/vision/detection/paddledetection/rknpu2/python/infer.py index 2dfb54281..2617acd95 100644 --- a/examples/vision/detection/paddledetection/rknpu2/python/infer.py +++ b/examples/vision/detection/paddledetection/rknpu2/python/infer.py @@ -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", diff --git a/examples/vision/detection/rkyolo/README_CN.md b/examples/vision/detection/rkyolo/README_CN.md index 1cc44a920..982d0577f 100644 --- a/examples/vision/detection/rkyolo/README_CN.md +++ b/examples/vision/detection/rkyolo/README_CN.md @@ -6,11 +6,21 @@ RKYOLO参考[rknn_model_zoo](https://github.com/airockchip/rknn_model_zoo/tree/m ## 支持模型列表 +FastDeploy目前支持以下三个模型的部署: + * RKYOLOV5 +* RKYOLOX +* RKYOLOv7 -## 模型转换example +为了方便大家测试,我们提供了三个转换过后的模型,大家可以直接下载使用。 +如果你有转换模型的需求,请参考[RKNN_model_convert](https://github.com/airockchip/rknn_model_zoo/tree/main/models/CV/object_detection/yolo/RKNN_model_convert) + +| 模型名称 | 下载地址 | +|--------------------|---------------------------------------------------------------------| +| 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) ## 其他链接