-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Model] Add Solov2 For PaddleDetection #1435
Merged
Merged
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
129c9e5
update solov2
Zheng-Bicheng bc9530d
Repair note
Zheng-Bicheng d4d6d5a
update solov2 postprocess
Zheng-Bicheng cc9b6eb
update
Zheng-Bicheng 084f1ab
update solov2
Zheng-Bicheng 041c062
update solov2
Zheng-Bicheng 0a72360
fixed bug
Zheng-Bicheng 5ab6685
fixed bug
Zheng-Bicheng 1e70204
update solov2
Zheng-Bicheng b65d82d
Merge remote-tracking branch 'upstream/develop' into solov2
Zheng-Bicheng 837baee
update solov2
Zheng-Bicheng 9563742
fix build android bug
Zheng-Bicheng cc945ca
update docs
Zheng-Bicheng 1335768
update docs
Zheng-Bicheng 6b8380d
Merge remote-tracking branch 'upstream/develop' into solov2
Zheng-Bicheng 06fb7d3
update docs
Zheng-Bicheng 3ef065f
update
Zheng-Bicheng 76c1967
Merge remote-tracking branch 'upstream/develop' into solov2
Zheng-Bicheng e0e9cf8
update
Zheng-Bicheng 7792233
Merge remote-tracking branch 'upstream/develop' into solov2
Zheng-Bicheng 4ef9000
update arch and docs
Zheng-Bicheng 4650126
Merge branch 'develop' into solov2
Zheng-Bicheng 0ad0a70
update
Zheng-Bicheng 039109e
update
Zheng-Bicheng 5589877
Merge branch 'develop' into solov2
DefTruth 97c0038
update solov2 python
Zheng-Bicheng 77550c7
Merge remote-tracking branch 'upstream/develop' into solov2
Zheng-Bicheng 0c1685e
Merge remote-tracking branch 'origin/solov2' into solov2
Zheng-Bicheng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
examples/vision/detection/paddledetection/jetson/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
English | [简体中文](README_CN.md) | ||
|
||
# PaddleDetection Model Deployment | ||
|
||
FastDeploy supports the SOLOV2 model of [PaddleDetection version 2.6](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6). | ||
|
||
You can enter the following command to get the static diagram model of SOLOV2. | ||
|
||
```bash | ||
# install PaddleDetection | ||
git clone https://github.com/PaddlePaddle/PaddleDetection.git | ||
cd PaddleDetection | ||
|
||
python tools/export_model.py -c configs/solov2/solov2_r50_fpn_1x_coco.yml --output_dir=./inference_model \ | ||
-o weights=https://paddledet.bj.bcebos.com/models/solov2_r50_fpn_1x_coco.pdparams | ||
``` | ||
|
||
## Detailed Deployment Documents | ||
|
||
- [Python Deployment](python) | ||
- [C++ Deployment](cpp) |
20 changes: 20 additions & 0 deletions
20
examples/vision/detection/paddledetection/jetson/README_CN.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[English](README.md) | 简体中文 | ||
# PaddleDetection模型部署 | ||
|
||
FastDeploy支持[PaddleDetection 2.6](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.6)版本的SOLOv2模型, | ||
|
||
你可以输入以下命令得到SOLOv2的静态图模型。 | ||
|
||
```bash | ||
# install PaddleDetection | ||
git clone https://github.com/PaddlePaddle/PaddleDetection.git | ||
cd PaddleDetection | ||
|
||
python tools/export_model.py -c configs/solov2/solov2_r50_fpn_1x_coco.yml --output_dir=./inference_model \ | ||
-o weights=https://paddledet.bj.bcebos.com/models/solov2_r50_fpn_1x_coco.pdparams | ||
``` | ||
|
||
## 详细部署文档 | ||
|
||
- [Python部署](python) | ||
- [C++部署](cpp) |
11 changes: 11 additions & 0 deletions
11
examples/vision/detection/paddledetection/jetson/cpp/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
PROJECT(infer_demo C CXX) | ||
CMAKE_MINIMUM_REQUIRED (VERSION 3.10) | ||
|
||
option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.") | ||
|
||
include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake) | ||
|
||
include_directories(${FASTDEPLOY_INCS}) | ||
|
||
add_executable(infer_solov2_demo ${PROJECT_SOURCE_DIR}/infer_solov2.cc) | ||
target_link_libraries(infer_solov2_demo ${FASTDEPLOY_LIBS}) |
28 changes: 28 additions & 0 deletions
28
examples/vision/detection/paddledetection/jetson/cpp/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
English | [简体中文](README_CN.md) | ||
# PaddleDetection C++ Deployment Example | ||
|
||
This directory provides examples that `infer_xxx.cc` fast finishes the deployment of PaddleDetection models, including SOLOv2 on CPU/GPU and GPU accelerated by TensorRT. | ||
|
||
Before deployment, two steps require confirmation | ||
|
||
- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) | ||
- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) | ||
|
||
Taking inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. | ||
|
||
```bash | ||
mkdir build | ||
cd build | ||
|
||
# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 | ||
Zheng-Bicheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz | ||
tar xvf fastdeploy-linux-x64-x.x.x.tgz | ||
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x | ||
make -j | ||
|
||
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg | ||
# CPU推理 | ||
Zheng-Bicheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
./infer_solov2_demo ./solov2_r50_fpn_1x_coco 000000014439.jpg 0 | ||
# GPU推理 | ||
./infer_ppyoloe_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 1 | ||
``` |
29 changes: 29 additions & 0 deletions
29
examples/vision/detection/paddledetection/jetson/cpp/README_CN.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[English](README.md) | 简体中文 | ||
# PaddleDetection C++部署示例 | ||
|
||
本目录下提供`infer_xxx.cc`快速完成PaddleDetection模型包括SOLOv2在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 | ||
|
||
在部署前,需确认以下两个步骤 | ||
|
||
- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) | ||
- 2. 根据开发环境,下载预编译部署库和examples代码,参考[FastDeploy预编译库](../../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) | ||
|
||
以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) | ||
|
||
|
||
```bash | ||
mkdir build | ||
cd build | ||
|
||
# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 | ||
wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz | ||
tar xvf fastdeploy-linux-x64-x.x.x.tgz | ||
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x | ||
make -j | ||
|
||
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg | ||
# CPU推理 | ||
./infer_solov2_demo ./solov2_r50_fpn_1x_coco 000000014439.jpg 0 | ||
# GPU推理 | ||
./infer_ppyoloe_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 1 | ||
``` |
96 changes: 96 additions & 0 deletions
96
examples/vision/detection/paddledetection/jetson/cpp/infer_solov2.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// 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" | ||
|
||
#ifdef WIN32 | ||
const char sep = '\\'; | ||
#else | ||
const char sep = '/'; | ||
#endif | ||
|
||
void CpuInfer(const std::string& model_dir, const std::string& image_file) { | ||
auto model_file = model_dir + sep + "model.pdmodel"; | ||
auto params_file = model_dir + sep + "model.pdiparams"; | ||
auto config_file = model_dir + sep + "infer_cfg.yml"; | ||
auto option = fastdeploy::RuntimeOption(); | ||
option.UseCpu(); | ||
auto model = fastdeploy::vision::detection::SOLOv2(model_file, params_file, | ||
config_file, option); | ||
if (!model.Initialized()) { | ||
std::cerr << "Failed to initialize." << std::endl; | ||
return; | ||
} | ||
|
||
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, 0.5); | ||
cv::imwrite("vis_result.jpg", vis_im); | ||
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; | ||
} | ||
|
||
void GpuInfer(const std::string& model_dir, const std::string& image_file) { | ||
auto model_file = model_dir + sep + "model.pdmodel"; | ||
auto params_file = model_dir + sep + "model.pdiparams"; | ||
auto config_file = model_dir + sep + "infer_cfg.yml"; | ||
|
||
auto option = fastdeploy::RuntimeOption(); | ||
option.UseGpu(); | ||
auto model = fastdeploy::vision::detection::SOLOv2(model_file, params_file, | ||
config_file, option); | ||
if (!model.Initialized()) { | ||
std::cerr << "Failed to initialize." << std::endl; | ||
return; | ||
} | ||
|
||
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, 0.5); | ||
cv::imwrite("vis_result.jpg", vis_im); | ||
std::cout << "Visualized result saved in ./vis_result.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 ./ppyolo_dirname ./test.jpeg 0" | ||
<< std::endl; | ||
std::cout << "The data type of run_option is int, 0: run with cpu; 1: run " | ||
"with gpu; 2: run with kunlunxin." | ||
<< std::endl; | ||
return -1; | ||
} | ||
|
||
if (std::atoi(argv[3]) == 0) { | ||
CpuInfer(argv[1], argv[2]); | ||
} else if (std::atoi(argv[3]) == 1) { | ||
GpuInfer(argv[1], argv[2]); | ||
} | ||
return 0; | ||
} |
96 changes: 96 additions & 0 deletions
96
examples/vision/detection/paddledetection/jetson/python/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
English | [简体中文](README_CN.md) | ||
# PaddleDetection Python Deployment Example | ||
|
||
Before deployment, two steps require confirmation. | ||
|
||
- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) | ||
- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) | ||
|
||
This directory provides examples that `infer_xxx.py` fast finishes the deployment of PPYOLOE/PicoDet models on CPU/GPU and GPU accelerated by TensorRT. The script is as follows | ||
|
||
```bash | ||
# Download deployment example code | ||
git clone https://github.com/PaddlePaddle/FastDeploy.git | ||
cd FastDeploy/examples/vision/detection/paddledetection/python/ | ||
|
||
# Download the PPYOLOE model file and test images | ||
wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz | ||
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg | ||
tar xvf ppyoloe_crn_l_300e_coco.tgz | ||
|
||
# CPU inference | ||
python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device cpu | ||
# GPU inference | ||
python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device gpu | ||
# TensorRT inference on GPU (Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) | ||
python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device gpu --use_trt True | ||
# Kunlunxin XPU Inference | ||
python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device kunlunxin | ||
# Huawei Ascend Inference | ||
python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device ascend | ||
``` | ||
|
||
The visualized result after running is as follows | ||
<div align="center"> | ||
<img src="https://user-images.githubusercontent.com/19339784/184326520-7075e907-10ed-4fad-93f8-52d0e35d4964.jpg", width=480px, height=320px /> | ||
</div> | ||
|
||
## PaddleDetection Python Interface | ||
|
||
```python | ||
fastdeploy.vision.detection.PPYOLOE(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.PicoDet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.PaddleYOLOX(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.YOLOv3(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.PPYOLO(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.FasterRCNN(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.MaskRCNN(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.SSD(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.PaddleYOLOv5(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.PaddleYOLOv6(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.PaddleYOLOv7(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.RTMDet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
Zheng-Bicheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fastdeploy.vision.detection.CascadeRCNN(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.PSSDet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.RetinaNet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.PPYOLOESOD(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.FCOS(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.TTFNet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.TOOD(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.GFL(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
fastdeploy.vision.detection.SOLOv2(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) | ||
``` | ||
|
||
PaddleDetection model loading and initialization, among which model_file and params_file are the exported Paddle model format. config_file is the configuration yaml file exported by PaddleDetection simultaneously | ||
|
||
**Parameter** | ||
|
||
> * **model_file**(str): Model file path | ||
> * **params_file**(str): Parameter file path | ||
> * **config_file**(str): Inference configuration yaml file path | ||
> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default. (use the default configuration) | ||
> * **model_format**(ModelFormat): Model format. Paddle format by default | ||
|
||
### predict Function | ||
|
||
PaddleDetection models, including PPYOLOE/PicoDet/PaddleYOLOX/YOLOv3/PPYOLO/FasterRCNN, all provide the following member functions for image detection | ||
> ```python | ||
> PPYOLOE.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) | ||
> ``` | ||
> | ||
> Model prediction interface. Input images and output results directly. | ||
> | ||
> **Parameter** | ||
> | ||
> > * **image_data**(np.ndarray): Input data in HWC or BGR format | ||
|
||
> **Return** | ||
> | ||
> > Return `fastdeploy.vision.DetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. | ||
|
||
## Other Documents | ||
|
||
- [PaddleDetection Model Description](..) | ||
- [PaddleDetection C++ Deployment](../cpp) | ||
- [Model Prediction Results](../../../../../docs/api/vision_results/) | ||
- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么需要额外新增一个jetson的部署目录,复用原cpp目录不行么
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PaddlePaddle/Paddle#50631 (comment) 这里任务要求是放到这个目录