Skip to content

Commit 61c4a46

Browse files
ziqi-jinjiangjiajunrootDefTruthfelixhjh
authored
Add external model's example code and Docs. (PaddlePaddle#102)
* first commit for yolov7 * pybind for yolov7 * CPP README.md * CPP README.md * modified yolov7.cc * README.md * python file modify * delete license in fastdeploy/ * repush the conflict part * README.md modified * README.md modified * file path modified * file path modified * file path modified * file path modified * file path modified * README modified * README modified * move some helpers to private * add examples for yolov7 * api.md modified * api.md modified * api.md modified * YOLOv7 * yolov7 release link * yolov7 release link * yolov7 release link * copyright * change some helpers to private * change variables to const and fix documents. * gitignore * Transfer some funtions to private member of class * Transfer some funtions to private member of class * Merge from develop (#9) * Fix compile problem in different python version (PaddlePaddle#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <[email protected]> * Add PaddleDetetion/PPYOLOE model support (PaddlePaddle#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (PaddlePaddle#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (PaddlePaddle#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: DefTruth <[email protected]> Co-authored-by: huangjianhui <[email protected]> * first commit for yolor * for merge * Develop (PaddlePaddle#11) * Fix compile problem in different python version (PaddlePaddle#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <[email protected]> * Add PaddleDetetion/PPYOLOE model support (PaddlePaddle#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (PaddlePaddle#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (PaddlePaddle#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: DefTruth <[email protected]> Co-authored-by: huangjianhui <[email protected]> * Yolor (PaddlePaddle#16) * Develop (PaddlePaddle#11) (PaddlePaddle#12) * Fix compile problem in different python version (PaddlePaddle#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <[email protected]> * Add PaddleDetetion/PPYOLOE model support (PaddlePaddle#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (PaddlePaddle#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (PaddlePaddle#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: DefTruth <[email protected]> Co-authored-by: huangjianhui <[email protected]> Co-authored-by: Jason <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: DefTruth <[email protected]> Co-authored-by: huangjianhui <[email protected]> * Develop (PaddlePaddle#13) * Fix compile problem in different python version (PaddlePaddle#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <[email protected]> * Add PaddleDetetion/PPYOLOE model support (PaddlePaddle#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (PaddlePaddle#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (PaddlePaddle#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: DefTruth <[email protected]> Co-authored-by: huangjianhui <[email protected]> * documents * documents * documents * documents * documents * documents * documents * documents * documents * documents * documents * documents * Develop (PaddlePaddle#14) * Fix compile problem in different python version (PaddlePaddle#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <[email protected]> * Add PaddleDetetion/PPYOLOE model support (PaddlePaddle#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (PaddlePaddle#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (PaddlePaddle#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: root <[email protected]> Co-authored-by: DefTruth <[email protected]> Co-authored-by: huangjianhui <[email protected]> Co-authored-by: Jason <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: DefTruth <[email protected]> Co-authored-by: huangjianhui <[email protected]> Co-authored-by: Jason <[email protected]> * add is_dynamic for YOLO series (PaddlePaddle#22) * first commit test photo * yolov7 doc * yolov7 doc * yolov7 doc * yolov7 doc * add yolov5 docs * modify yolov5 doc * first commit for retinaface * first commit for retinaface * firt commit for ultraface * firt commit for ultraface * firt commit for yolov5face * firt commit for modnet and arcface * firt commit for modnet and arcface * first commit for partial_fc * first commit for partial_fc * first commit for yolox * first commit for yolov6 * first commit for nano_det * first commit for scrfd * first commit for scrfd * first commit for retinaface * first commit for ultraface * first commit for yolov5face * first commit for yolox yolov6 nano * rm jpg * first commit for modnet and modify nano * yolor scaledyolov4 v5lite * first commit for insightface * first commit for insightface * first commit for insightface * docs * docs * docs * docs * docs * add print for detect and modify docs * docs * docs * docs * docs test for insightface * docs test for insightface again * docs test for insightface * modify all wrong expressions in docs * modify all wrong expressions in docs Co-authored-by: Jason <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: DefTruth <[email protected]> Co-authored-by: huangjianhui <[email protected]> Co-authored-by: Jason <[email protected]>
1 parent dd3d742 commit 61c4a46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+4100
-309
lines changed

docs/api/vision_results/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ FastDeploy根据视觉模型的任务类型,定义了不同的结构体(`csrcs
44

55
| 结构体 | 文档 | 说明 | 相应模型 |
66
| :----- | :--- | :---- | :------- |
7-
| ClassificationResult | [C++/Python文档](./classificiation_result.md) | 图像分类返回结果 | ResNet50、MobileNetV3等 |
7+
| ClassificationResult | [C++/Python文档](./classification_result.md) | 图像分类返回结果 | ResNet50、MobileNetV3等 |
88
| DetectionResult | [C++/Python文档](./detection_result.md) | 目标检测返回结果 | PPYOLOE、YOLOv7系列模型等 |
9+
| FaceDetectionResult | [C++/Python文档](./face_detection_result.md) | 目标检测返回结果 | PPYOLOE、YOLOv7系列模型等 |
10+
| MattingResult | [C++/Python文档](./matting_result.md) | 目标检测返回结果 | PPYOLOE、YOLOv7系列模型等 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# FaceDetectionResult 人脸检测结果
2+
3+
FaceDetectionResult 代码定义在`csrcs/fastdeploy/vision/common/result.h`中,用于表明图像检测出来的目标框、目标类别和目标置信度。
4+
5+
## C++ 结构体
6+
7+
`fastdeploy::vision::FaceDetectionResult`
8+
9+
```
10+
struct FaceDetectionResult {
11+
std::vector<std::array<float, 4>> boxes;
12+
std::vector<std::array<float, 2>> landmarks;
13+
std::vector<float> scores;
14+
ResultType type = ResultType::FACE_DETECTION;
15+
int landmarks_per_face;
16+
void Clear();
17+
std::string Str();
18+
};
19+
```
20+
21+
- **boxes**: 成员变量,表示单张图片检测出来的所有目标框坐标,`boxes.size()`表示框的个数,每个框以4个float数值依次表示xmin, ymin, xmax, ymax, 即左上角和右下角坐标
22+
- **scores**: 成员变量,表示单张图片检测出来的所有目标置信度,其元素个数与`boxes.size()`一致
23+
- **landmarks**: 成员变量,表示单张图片检测出来的所有人脸的关键点,其元素个数与`boxes.size()`一致
24+
- **landmarks_per_face**: 成员变量,表示每个人脸框中的关键点的数量。
25+
- **Clear()**: 成员函数,用于清除结构体中存储的结果
26+
- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug)
27+
28+
## Python结构体
29+
30+
`fastdeploy.vision.FaceDetectionResult`
31+
32+
- **boxes**(list of list(float)): 成员变量,表示单张图片检测出来的所有目标框坐标。boxes是一个list,其每个元素为一个长度为4的list, 表示为一个框,每个框以4个float数值依次表示xmin, ymin, xmax, ymax, 即左上角和右下角坐标
33+
- **scores**(list of float): 成员变量,表示单张图片检测出来的所有目标置信度
34+
- **landmarks**: 成员变量,表示单张图片检测出来的所有人脸的关键点
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# MattingResult 抠图结果
2+
3+
MattingResult 代码定义在`csrcs/fastdeploy/vision/common/result.h`中,用于表明图像检测出来的目标框、目标类别和目标置信度。
4+
5+
## C++ 结构体
6+
7+
`fastdeploy::vision::MattingResult`
8+
9+
```
10+
struct MattingResult {
11+
std::vector<float> alpha; // h x w
12+
std::vector<float> foreground; // h x w x c (c=3 default)
13+
std::vector<int64_t> shape;
14+
bool contain_foreground = false;
15+
void Clear();
16+
std::string Str();
17+
};
18+
```
19+
20+
- **alpha**: 是一维向量,为预测的alpha透明度的值,值域为[0.,1.],长度为hxw,h,w为输入图像的高和宽
21+
- **foreground**: 是一维向量,为预测的前景,值域为[0.,255.],长度为hxwxc,h,w为输入图像的高和宽,c一般为3,foreground不是一定有的,只有模型本身预测了前景,这个属性才会有效
22+
- **contain_foreground**: 表示预测的结果是否包含前景
23+
- **shape**: 表示输出结果的shape,当contain_foreground为false,shape只包含(h,w),当contain_foreground为true,shape包含(h,w,c), c一般为3
24+
- **Clear()**: 成员函数,用于清除结构体中存储的结果
25+
- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug)
26+
27+
28+
## Python结构体
29+
30+
`fastdeploy.vision.MattingResult`
31+
32+
- **alpha**: 是一维向量,为预测的alpha透明度的值,值域为[0.,1.],长度为hxw,h,w为输入图像的高和宽
33+
- **foreground**: 是一维向量,为预测的前景,值域为[0.,255.],长度为hxwxc,h,w为输入图像的高和宽,c一般为3,foreground不是一定有的,只有模型本身预测了前景,这个属性才会有效
34+
- **contain_foreground**: 表示预测的结果是否包含前景
35+
- **shape**: 表示输出结果的shape,当contain_foreground为false,shape只包含(h,w),当contain_foreground为true,shape包含(h,w,c), c一般为3

examples/vision/README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
| 任务类型 | 说明 | 预测结果结构体 |
66
|:-------------- |:----------------------------------- |:-------------------------------------------------------------------------------- |
7-
| Detection | 目标检测,输入图像,检测图像中物体位置,并返回检测框坐标及类别和置信度 | [DetectionResult](../../../../docs/api/vision_results/detection_result.md) |
8-
| Segmentation | 语义分割,输入图像,给出图像中每个像素的分类及置信度 | [SegmentationResult](../../../../docs/api/vision_results/segmentation_result.md) |
9-
| Classification | 图像分类,输入图像,给出图像的分类结果和置信度 | [ClassifyResult](../../../../docs/api/vision_results/classification_result.md) |
10-
7+
| Detection | 目标检测,输入图像,检测图像中物体位置,并返回检测框坐标及类别和置信度 | [DetectionResult](../../docs/api/vision_results/detection_result.md) |
8+
| Segmentation | 语义分割,输入图像,给出图像中每个像素的分类及置信度 | [SegmentationResult](../../docs/api/vision_results/segmentation_result.md) |
9+
| Classification | 图像分类,输入图像,给出图像的分类结果和置信度 | [ClassifyResult](../../docs/api/vision_results/classification_result.md) |
10+
| FaceDetection | 人脸检测,输入图像,检测图像中人脸位置,并返回检测框坐标及人脸关键点 | [FaceDetectionResult](../../docs/api/vision_results/face_detection_result.md) |
11+
| Matting | 抠图,输入图像,返回图片的前景每个像素点的Alpha值 | [MattingResult](../../docs/api/vision_results/matting_result.md) |
1112
## FastDeploy API设计
1213

1314
视觉模型具有较有统一任务范式,在设计API时(包括C++/Python),FastDeploy将视觉模型的部署拆分为四个步骤

examples/vision/classification/paddleclas/python/infer.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def build_option(args):
4343

4444
# 配置runtime,加载模型
4545
runtime_option = build_option(args)
46+
4647
model_file = os.path.join(args.model, "inference.pdmodel")
4748
params_file = os.path.join(args.model, "inference.pdiparams")
4849
config_file = os.path.join(args.model, "inference_cls.yaml")
@@ -51,5 +52,5 @@ def build_option(args):
5152

5253
# 预测图片分类结果
5354
im = cv2.imread(args.image)
54-
result = model.predict(im, args.topk)
55+
result = model.predict(im.copy(), args.topk)
5556
print(result)

examples/vision/detection/README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
# 目标检测模型
1+
人脸检测模型
22

33
FastDeploy目前支持如下目标检测模型部署
44

55
| 模型 | 说明 | 模型格式 | 版本 |
66
| :--- | :--- | :------- | :--- |
7-
| [PaddleDetection/PPYOLOE](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe) | PPYOLOE系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) |
8-
| [PaddleDetection/PicoDet](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe) | PicoDet系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) |
9-
| [PaddleDetection/YOLOX](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe) | Paddle版本的YOLOX系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) |
10-
| [PaddleDetection/YOLOv3](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe) | YOLOv3系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) |
11-
| [PaddleDetection/PPYOLO](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe) | PPYOLO系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) |
12-
| [PaddleDetection/FasterRCNN](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe) | FasterRCNN系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) |
13-
| [WongKinYiu/YOLOv7](https://github.com/WongKinYiu/yolov7) | YOLOv7、YOLOv7-X等系列模型 | ONNX | [v0.1](https://github.com/WongKinYiu/yolov7/tree/v0.1) |
7+
| [nanodet_plus](./nanodet_plus) | NanoDetPlus系列模型 | ONNX | Release/v1.0.0-alpha-1 |
8+
| [yolov5](./yolov5) | YOLOv5系列模型 | ONNX | Release/v6.0 |
9+
| [yolov5lite](./yolov5lite) | YOLOv5-Lite系列模型 | ONNX | Release/v1.4 |
10+
| [yolov6](./yolov6) | YOLOv6系列模型 | ONNX | Release/0.1.0 |
11+
| [yolov7](./yolov7) | YOLOv7系列模型 | ONNX | Release/0.1 |
12+
| [yolor](./yolor) | YOLOR系列模型 | ONNX | Release/weights |
13+
| [yolox](./yolox) | YOLOX系列模型 | ONNX | Release/v0.1.1 |
14+
| [scaledyolov4](./scaledyolov4) | ScaledYOLOv4系列模型 | ONNX | CommitID:6768003 |

examples/vision/detection/nanodet_plus/README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
## 模型版本说明
44

5-
- NanoDetPlus部署实现来自[NanoDetPlus v1.0.0-alpha-1](https://github.com/RangiLyu/nanodet/tree/v1.0.0-alpha-1) 分支代码,基于coco的[预训练模型](https://github.com/RangiLyu/nanodet/releases/tag/v1.0.0-alpha-1)
5+
- NanoDetPlus部署实现来自[NanoDetPlus](https://github.com/RangiLyu/nanodet/tree/v1.0.0-alpha-1) 的代码,基于coco的[预训练模型](https://github.com/RangiLyu/nanodet/releases/tag/v1.0.0-alpha-1)
66

77
- (1)[预训练模型](https://github.com/RangiLyu/nanodet/releases/tag/v1.0.0-alpha-1)*.onnx可直接进行部署;
8-
- (2)自己训练的模型,导出ONNX模型后,参考[详细部署教程](#详细部署文档)完成部署。
9-
8+
- (2)自己训练的模型,导出ONNX模型后,参考[详细部署文档](#详细部署文档)完成部署。
9+
1010
## 下载预训练ONNX模型
1111

1212
为了方便开发者的测试,下面提供了NanoDetPlus导出的各系列模型,开发者可直接下载使用。
@@ -21,3 +21,8 @@
2121

2222
- [Python部署](python)
2323
- [C++部署](cpp)
24+
25+
26+
## 版本说明
27+
28+
- 本版本文档和代码基于[NanoDetPlus v1.0.0-alpha-1](https://github.com/RangiLyu/nanodet/tree/v1.0.0-alpha-1) 编写

examples/vision/detection/nanodet_plus/cpp/README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
```
1313
mkdir build
1414
cd build
15-
wget https://xxx.tgz
15+
wget https://https://bj.bcebos.com/paddlehub/fastdeploy/cpp/fastdeploy-linux-x64-gpu-0.2.0.tgz
1616
tar xvf fastdeploy-linux-x64-0.2.0.tgz
1717
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-0.2.0
1818
make -j
@@ -32,7 +32,7 @@ wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/0000000
3232

3333
运行完成可视化结果如下图所示
3434

35-
<img width="640" src="https://user-images.githubusercontent.com/67993288/183847558-abcd9a57-9cd9-4891-b09a-710963c99b74.jpg">
35+
<img width="640" src="https://user-images.githubusercontent.com/67993288/184301689-87ee5205-2eff-4204-b615-24c400f01323.jpg">
3636

3737
## NanoDetPlus C++接口
3838

@@ -74,11 +74,14 @@ NanoDetPlus模型加载和初始化,其中model_file为导出的ONNX模型格
7474
7575
### 类成员变量
7676
77-
> > * **size**(vector&lt;int&gt;): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640]
78-
> > * **padding_value**(vector&lt;float&gt;): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114]
79-
> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false`
80-
> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false`
81-
> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32`
77+
#### 预处理参数
78+
用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果
79+
80+
> > * **size**(vector&lt;int&gt;): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[320, 320]
81+
> > * **padding_value**(vector&lt;float&gt;): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[0, 0, 0]
82+
> > * **keep_ratio**(bool): 通过此参数指定resize时是否保持宽高比例不变,默认是fasle.
83+
> > * **reg_max**(int): GFL回归中的reg_max参数,默认是7.
84+
> > * **downsample_strides**(vector&lt;int&gt;): 通过此参数可以修改生成anchor的特征图的下采样倍数, 包含三个整型元素, 分别表示默认的生成anchor的下采样倍数, 默认值为[8, 16, 32, 64]
8285
8386
- [模型介绍](../../)
8487
- [Python部署](../python)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "fastdeploy/vision.h"
16+
17+
void CpuInfer(const std::string& model_file, const std::string& image_file) {
18+
auto model = fastdeploy::vision::detection::NanoDetPlus(model_file);
19+
if (!model.Initialized()) {
20+
std::cerr << "Failed to initialize." << std::endl;
21+
return;
22+
}
23+
24+
auto im = cv::imread(image_file);
25+
auto im_bak = im.clone();
26+
27+
fastdeploy::vision::DetectionResult res;
28+
if (!model.Predict(&im, &res)) {
29+
std::cerr << "Failed to predict." << std::endl;
30+
return;
31+
}
32+
std::cout << res.Str() << std::endl;
33+
auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
34+
cv::imwrite("vis_result.jpg", vis_im);
35+
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
36+
}
37+
38+
void GpuInfer(const std::string& model_file, const std::string& image_file) {
39+
auto option = fastdeploy::RuntimeOption();
40+
option.UseGpu();
41+
auto model =
42+
fastdeploy::vision::detection::NanoDetPlus(model_file, "", option);
43+
if (!model.Initialized()) {
44+
std::cerr << "Failed to initialize." << std::endl;
45+
return;
46+
}
47+
48+
auto im = cv::imread(image_file);
49+
auto im_bak = im.clone();
50+
51+
fastdeploy::vision::DetectionResult res;
52+
if (!model.Predict(&im, &res)) {
53+
std::cerr << "Failed to predict." << std::endl;
54+
return;
55+
}
56+
std::cout << res.Str() << std::endl;
57+
58+
auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
59+
cv::imwrite("vis_result.jpg", vis_im);
60+
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
61+
}
62+
63+
void TrtInfer(const std::string& model_file, const std::string& image_file) {
64+
auto option = fastdeploy::RuntimeOption();
65+
option.UseGpu();
66+
option.UseTrtBackend();
67+
option.SetTrtInputShape("images", {1, 3, 320, 320});
68+
auto model =
69+
fastdeploy::vision::detection::NanoDetPlus(model_file, "", option);
70+
if (!model.Initialized()) {
71+
std::cerr << "Failed to initialize." << std::endl;
72+
return;
73+
}
74+
75+
auto im = cv::imread(image_file);
76+
auto im_bak = im.clone();
77+
78+
fastdeploy::vision::DetectionResult res;
79+
if (!model.Predict(&im, &res)) {
80+
std::cerr << "Failed to predict." << std::endl;
81+
return;
82+
}
83+
std::cout << res.Str() << std::endl;
84+
85+
auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
86+
cv::imwrite("vis_result.jpg", vis_im);
87+
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
88+
}
89+
90+
int main(int argc, char* argv[]) {
91+
if (argc < 4) {
92+
std::cout << "Usage: infer_demo path/to/model path/to/image run_option, "
93+
"e.g ./infer_model ./nanodet-plus-m_320.onnx ./test.jpeg 0"
94+
<< std::endl;
95+
std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
96+
"with gpu; 2: run with gpu and use tensorrt backend."
97+
<< std::endl;
98+
return -1;
99+
}
100+
101+
if (std::atoi(argv[3]) == 0) {
102+
CpuInfer(argv[1], argv[2]);
103+
} else if (std::atoi(argv[3]) == 1) {
104+
GpuInfer(argv[1], argv[2]);
105+
} else if (std::atoi(argv[3]) == 2) {
106+
TrtInfer(argv[1], argv[2]);
107+
}
108+
return 0;
109+
}

examples/vision/detection/nanodet_plus/python/README.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ python infer.py --model nanodet-plus-m_320.onnx --image 000000014439.jpg --devic
2626

2727
运行完成可视化结果如下图所示
2828

29-
<img width="640" src="https://user-images.githubusercontent.com/67993288/183847558-abcd9a57-9cd9-4891-b09a-710963c99b74.jpg">
29+
<img width="640" src="https://user-images.githubusercontent.com/67993288/184301689-87ee5205-2eff-4204-b615-24c400f01323.jpg">
3030

3131
## NanoDetPlus Python接口
3232

@@ -62,12 +62,14 @@ NanoDetPlus模型加载和初始化,其中model_file为导出的ONNX模型格
6262
> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/)
6363
6464
### 类成员属性
65-
66-
> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640]
67-
> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114]
68-
> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False`
69-
> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False`
70-
> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32`
65+
#### 预处理参数
66+
用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果
67+
68+
> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[320, 320]
69+
> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[0, 0, 0]
70+
> > * **keep_ratio**(bool): 通过此参数指定resize时是否保持宽高比例不变,默认是fasle.
71+
> > * **reg_max**(int): GFL回归中的reg_max参数,默认是7.
72+
> > * **downsample_strides**(list[int]): 通过此参数可以修改生成anchor的特征图的下采样倍数, 包含三个整型元素, 分别表示默认的生成anchor的下采样倍数, 默认值为[8, 16, 32, 64]
7173
7274
7375

0 commit comments

Comments
 (0)