diff --git a/examples/vision/detection/paddledetection/sophgo/README.md b/examples/vision/detection/paddledetection/sophgo/README.md index d574275df..20d30d386 100644 --- a/examples/vision/detection/paddledetection/sophgo/README.md +++ b/examples/vision/detection/paddledetection/sophgo/README.md @@ -5,8 +5,9 @@ 目前SOPHGO支持如下模型的部署 - [PP-YOLOE系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe) - [PicoDet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/picodet) +- [YOLOV8系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/) -## 准备PP-YOLOE或者PicoDet部署模型以及转换模型 +## 准备PP-YOLOE YOLOV8或者PicoDet部署模型以及转换模型 SOPHGO-TPU部署模型前需要将Paddle模型转换成bmodel模型,具体步骤如下: - Paddle动态图模型转换为ONNX模型,请参考[PaddleDetection导出模型](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.4/deploy/EXPORT_MODEL.md). @@ -14,7 +15,7 @@ SOPHGO-TPU部署模型前需要将Paddle模型转换成bmodel模型,具体步 ## 模型转换example -PP-YOLOE和PicoDet模型转换过程类似,下面以ppyoloe_crn_s_300e_coco为例子,教大家如何转换Paddle模型到SOPHGO-TPU模型 +PP-YOLOE YOLOV8和PicoDet模型转换过程类似,下面以ppyoloe_crn_s_300e_coco为例子,教大家如何转换Paddle模型到SOPHGO-TPU模型 ### 导出ONNX模型 ```shell diff --git a/examples/vision/detection/paddledetection/sophgo/cpp/CMakeLists.txt b/examples/vision/detection/paddledetection/sophgo/cpp/CMakeLists.txt index 8caaaed25..400f86387 100644 --- a/examples/vision/detection/paddledetection/sophgo/cpp/CMakeLists.txt +++ b/examples/vision/detection/paddledetection/sophgo/cpp/CMakeLists.txt @@ -14,6 +14,8 @@ include_directories(${FastDeploy_INCLUDE_DIRS}) add_executable(infer_ppyoloe ${PROJECT_SOURCE_DIR}/infer_ppyoloe.cc) add_executable(infer_picodet ${PROJECT_SOURCE_DIR}/infer_picodet.cc) +add_executable(infer_yolov8 ${PROJECT_SOURCE_DIR}/infer_yolov8.cc) # 添加FastDeploy库依赖 target_link_libraries(infer_ppyoloe ${FASTDEPLOY_LIBS}) target_link_libraries(infer_picodet ${FASTDEPLOY_LIBS}) +target_link_libraries(infer_yolov8 ${FASTDEPLOY_LIBS}) diff --git a/examples/vision/detection/paddledetection/sophgo/cpp/README.md b/examples/vision/detection/paddledetection/sophgo/cpp/README.md index 224b4b42a..49e719685 100644 --- a/examples/vision/detection/paddledetection/sophgo/cpp/README.md +++ b/examples/vision/detection/paddledetection/sophgo/cpp/README.md @@ -1,6 +1,6 @@ # PaddleDetection C++部署示例 -本目录下提供`infer_ppyoloe.cc`和`infer_picodet.cc`快速完成PP-YOLOE模型和PicoDet模型在SOPHGO BM1684x板子上加速部署的示例。 +本目录下提供`infer_ppyoloe.cc`,`infer_yolov8.cc`和`infer_picodet.cc`快速完成PP-YOLOE模型,YOLOV8模型和PicoDet模型在SOPHGO BM1684x板子上加速部署的示例。 在部署前,需确认以下两个步骤: @@ -19,6 +19,7 @@ ├── image # 存放图片的文件夹 ├── infer_ppyoloe.cc ├── infer_picodet.cc +├── infer_yolov8.cc └── model # 存放模型文件的文件夹 ``` diff --git a/examples/vision/detection/paddledetection/sophgo/cpp/infer_yolov8.cc b/examples/vision/detection/paddledetection/sophgo/cpp/infer_yolov8.cc new file mode 100644 index 000000000..2f0132a60 --- /dev/null +++ b/examples/vision/detection/paddledetection/sophgo/cpp/infer_yolov8.cc @@ -0,0 +1,59 @@ +// 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 + +#include +#include + +#include "fastdeploy/vision.h" + +void SophgoInfer(const std::string& model_dir, const std::string& image_file) { + auto model_file = model_dir + "/compilation.bmodel"; + auto params_file = ""; + auto config_file = model_dir + "/infer_cfg.yml"; + + auto option = fastdeploy::RuntimeOption(); + option.UseSophgo(); + + auto format = fastdeploy::ModelFormat::SOPHGO; + + auto model = fastdeploy::vision::detection::PaddleYOLOv8(model_file, params_file, config_file, option, format); + + model.GetPostprocessor().ApplyDecodeAndNMS(); + + auto im = cv::imread(image_file); + + fastdeploy::vision::DetectionResult res; + if (!model.Predict(im, &res)) { + std::cerr << "Failed to predict." << std::endl; + return; + } + + std::cout << res.Str() << std::endl; + auto vis_im = fastdeploy::vision::VisDetection(im, res); + cv::imwrite("infer_sophgo.jpg", vis_im); + std::cout << "Visualized result saved in ./infer_sophgo.jpg" << std::endl; +} + +int main(int argc, char* argv[]) { + if (argc < 3) { + std::cout + << "Usage: infer_demo path/to/model_dir path/to/image run_option, " + "e.g ./infer_model ./yolov8_model_dir ./test.jpeg" + << std::endl; + return -1; + } + SophgoInfer(argv[1], argv[2]); + return 0; +} diff --git a/examples/vision/detection/paddledetection/sophgo/python/README.md b/examples/vision/detection/paddledetection/sophgo/python/README.md index ee8c87464..f849cc622 100644 --- a/examples/vision/detection/paddledetection/sophgo/python/README.md +++ b/examples/vision/detection/paddledetection/sophgo/python/README.md @@ -4,7 +4,7 @@ - 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../../docs/cn/build_and_install/sophgo.md) -本目录下提供`infer_ppyoloe.py`和`infer_picodet.py`快速完成 PP-YOLOE 和 PicoDet 在SOPHGO TPU上部署的示例。执行如下脚本即可完成 +本目录下提供`infer_ppyoloe.py`,`infer_yolov8.py`和`infer_picodet.py`快速完成 PP-YOLOE ,PP-YOLOV8和 PicoDet 在SOPHGO TPU上部署的示例。执行如下脚本即可完成 ```bash # 下载部署示例代码 @@ -21,6 +21,8 @@ python3 infer_ppyoloe.py --model_file model/ppyoloe_crn_s_300e_coco_1684x_f32.bm #picodet推理示例 python3 infer_picodet.py --model_file model/picodet_s_416_coco_lcnet_1684x_f32.bmodel --config_file model/infer_cfg.yml --image ./000000014439.jpg +#yolov8推理示例 +python3 infer_yolov8.py --model_file model/yolov8s_s_300e_coco_1684x_f32.bmodel --config_file model/infer_cfg.yml --image ./000000014439.jpg # 运行完成后返回结果如下所示 可视化结果存储在sophgo_result.jpg中 ``` @@ -28,5 +30,7 @@ python3 infer_picodet.py --model_file model/picodet_s_416_coco_lcnet_1684x_f32.b ## 其它文档 - [PP-YOLOE C++部署](../cpp) - [PicoDet C++部署](../cpp) +- [YOLOV8 C++部署](../cpp) - [转换PicoDet SOPHGO模型文档](../README.md) - [转换PP-YOLOE SOPHGO模型文档](../README.md) +- [转换YOLOV8 SOPHGO模型文档](../README.md) diff --git a/examples/vision/detection/paddledetection/sophgo/python/infer_yolov8.py b/examples/vision/detection/paddledetection/sophgo/python/infer_yolov8.py new file mode 100644 index 000000000..8b53bd8fa --- /dev/null +++ b/examples/vision/detection/paddledetection/sophgo/python/infer_yolov8.py @@ -0,0 +1,59 @@ +# 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. +import fastdeploy as fd +import cv2 +import os + + +def parse_arguments(): + import argparse + import ast + parser = argparse.ArgumentParser() + parser.add_argument( + "--model_file", required=True, help="Path of sophgo model.") + parser.add_argument("--config_file", required=True, help="Path of config.") + parser.add_argument( + "--image", type=str, required=True, help="Path of test image file.") + return parser.parse_args() + + +if __name__ == "__main__": + args = parse_arguments() + + model_file = args.model_file + params_file = "" + config_file = args.config_file + + # 配置runtime,加载模型 + runtime_option = fd.RuntimeOption() + runtime_option.use_sophgo() + + model = fd.vision.detection.PaddleYOLOv8( + model_file, + params_file, + config_file, + runtime_option=runtime_option, + model_format=fd.ModelFormat.SOPHGO) + + model.postprocessor.apply_decode_and_nms() + + # 预测图片分割结果 + im = cv2.imread(args.image) + result = model.predict(im) + print(result) + + # 可视化结果 + vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5) + cv2.imwrite("sophgo_result.jpg", vis_im) + print("Visualized result save in ./sophgo_result.jpg") diff --git a/fastdeploy/vision/detection/ppdet/model.h b/fastdeploy/vision/detection/ppdet/model.h index 0e1690642..89ed168ee 100644 --- a/fastdeploy/vision/detection/ppdet/model.h +++ b/fastdeploy/vision/detection/ppdet/model.h @@ -260,6 +260,7 @@ class FASTDEPLOY_DECL PaddleYOLOv8 : public PPDetBase { valid_kunlunxin_backends = {Backend::LITE}; valid_rknpu_backends = {Backend::RKNPU2}; valid_ascend_backends = {Backend::LITE}; + valid_sophgonpu_backends = {Backend::SOPHGOTPU}; initialized = Initialize(); } diff --git a/python/fastdeploy/vision/detection/ppdet/__init__.py b/python/fastdeploy/vision/detection/ppdet/__init__.py index d525af85a..f43ab3576 100644 --- a/python/fastdeploy/vision/detection/ppdet/__init__.py +++ b/python/fastdeploy/vision/detection/ppdet/__init__.py @@ -519,7 +519,6 @@ class PaddleYOLOv8(PPYOLOE): super(PPYOLOE, self).__init__(runtime_option) - assert model_format == ModelFormat.PADDLE, "PaddleYOLOv8 model only support model format of ModelFormat.Paddle now." self._model = C.vision.detection.PaddleYOLOv8( model_file, params_file, config_file, self._runtime_option, model_format)