Skip to content
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

Develop #27

Merged
merged 5 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/quick_start/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ pip install fastdeploy-python
然后通过命令行管理工具,根据自己的硬件安装相应SDK

### 安装CPU Python SDK

```
fastdeploy --install cpu
```

### 安装GPU Python SDK

```
fastdeploy --install gpu
```
2 changes: 1 addition & 1 deletion docs/quick_start/requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 系统平台

- Linux x64/aarch64
- Linux x64
- Windows 10 x64
- Mac OSX (x86 10.0以上/ arm64 12.0以上)

Expand Down
11 changes: 5 additions & 6 deletions new_examples/vision/detection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

本目录下提供了各类视觉模型的部署,主要涵盖以下任务类型

| 任务类型 | 说明 | 预测结果结构体 |
| :------- | :----| :------------- |
| Detection | 目标检测,输入图像,检测图像中物体位置,并返回检测框坐标及类别和置信度 | DetectionResult |
| Segmentation | 语义分割,输入图像,给出图像中每个像素的分类及置信度 | SegmentationResult |
| Classification | 图像分类,输入图像,给出图像的分类结果和置信度 | ClassifyResult |

| 任务类型 | 说明 | 预测结果结构体 |
|:-------------- |:----------------------------------- |:-------------------------------------------------------------------------------- |
| Detection | 目标检测,输入图像,检测图像中物体位置,并返回检测框坐标及类别和置信度 | [DetectionResult](../../../../docs/api/vision_results/detection_result.md) |
| Segmentation | 语义分割,输入图像,给出图像中每个像素的分类及置信度 | [SegmentationResult](../../../../docs/api/vision_results/segmentation_result.md) |
| Classification | 图像分类,输入图像,给出图像的分类结果和置信度 | [ClassifyResult](../../../../docs/api/vision_results/classification_result.md) |

## FastDeploy API设计

Expand Down
22 changes: 12 additions & 10 deletions new_examples/vision/detection/yolov7/README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
# YOLOv7部署
# YOLOv7准备部署模型

## 版本依赖
## 模型版本说明

- [YOLOv7 0.1](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1)

- (1)[链接中](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1)的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署;
- (2)[链接中](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1)的*.onnx、*.trt和 *.pose模型不支持部署;
- (3)开发者基于自己数据训练的YOLOv7 0.1模型,可按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)后,完成部署。

## 导出ONNX模型

```
#下载yolov7模型文件
# 下载yolov7模型文件
wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt

# 导出onnx格式文件 (Tips: 对应 YOLOv7 release v0.1 代码)
python models/export.py --grid --dynamic --weights PATH/TO/yolov7.pt

# 如果您的代码版本中有支持NMS的ONNX文件导出,请使用如下命令导出ONNX文件(请暂时不要使用 "--end2end",我们后续将支持带有NMS的ONNX模型的部署)
python export.py --grid --dynamic --weights PATH/TO/yolov7.pt
python models/export.py --grid --dynamic --weights PATH/TO/yolov7.pt

# 移动onnx文件到demo目录
cp PATH/TO/yolov7.onnx PATH/TO/model_zoo/vision/yolov7/
```

## 预训练模型集合
## 下载预训练模型

为了方便开发者的测试,下面提供了YOLOv7导出的各系列模型,开发者可直接下载使用。

| 模型 | 大小 | 精度 |
| :--- | :--- | :--- |
| 模型 | 大小 | 精度 |
|:---------------------------------------------------------------- |:----- |:----- |
| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx) | 141MB | 51.4% |
| [YOLOv7-x] | 10MB | 51.4% |
| [YOLOv7-x] | 10MB | 51.4% |


## 其它文档
## 详细部署文档

- [Python部署](python)
- [C++部署](cpp)
24 changes: 18 additions & 6 deletions new_examples/vision/detection/yolov7/cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
在部署前,需确认以下两个步骤

- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/quick_start/requirements.md)
- 2. 根据开发环境,下载预编译部署库,参考[FastDeploy预编译库](../../../../../docs/compile/prebuild_libraries.md)
- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/compile/prebuild_libraries.md)

以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试

Expand All @@ -17,19 +17,31 @@ tar xvf fastdeploy-linux-x64-0.2.0.tgz
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-0.2.0
make -j

./infer_demo yolov7.onnx 000001.jpg
#下载官方转换好的yolov7模型文件和测试图片
wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000087038.jpg


# CPU推理
./infer_demo yolov7.onnx 000000087038.jpg 0
# GPU推理
./infer_demo yolov7.onnx 000000087038.jpg 1
# GPU上TensorRT推理
./infer_demo yolov7.onnx 000000087038.jpg 2
```

## YOLOv7 C++接口

### YOLOv7类

```
fastdeploy::vision::wongkinyiu::YOLOv7(
const string& model_file,
const string& params_file = "",
const RuntimeOption& runtime_option = RuntimeOption(),
const Frontend& model_format = Frontend::ONNX)
```

YOLOv7模型加载和初始化,其中model_file为导出的ONNX模型格式。

**参数**
Expand All @@ -40,26 +52,26 @@ YOLOv7模型加载和初始化,其中model_file为导出的ONNX模型格式。
> * **model_format**(Frontend): 模型格式,默认为ONNX格式

#### Predict函数

> ```
> YOLOv7::Predict(cv::Mat* im, DetectionResult* result,
> float conf_threshold = 0.25,
> float nms_iou_threshold = 0.5)
> ```
>
> 模型预测接口,输入图像直接输出检测结果。
>
>
> **参数**
>
>
> > * **im**: 输入图像,注意需为HWC,BGR格式
> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/)
> > * **conf_threshold**: 检测框置信度过滤阈值
> > * **nms_iou_threshold**: NMS处理过程中iou阈值


### 类成员变量

> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640]


- [模型介绍](../../)
- [Python部署](../python)
- [视觉模型预测结果](../../../../../docs/api/vision_results/)
20 changes: 14 additions & 6 deletions new_examples/vision/detection/yolov7/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
在部署前,需确认以下两个步骤

- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/quick_start/requirements.md)
- 2. FastDeploy Python安装,参考[FastDeploy Python安装](../../../../../docs/quick_start/install.md)
- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/quick_start/install.md)

本目录下提供`infer.py`快速完成YOLOv7在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成

Expand All @@ -12,12 +12,20 @@
wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000087038.jpg

#下载部署示例代码
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd examples/vison/detection/yolov7/python/

# CPU推理
python infer.py --model yolov7.onnx --image 000000087038.jpg --device cpu
# GPU推理
python infer.py --model yolov7.onnx --image 000000087038.jpg --device gpu
# GPU上使用TensorRT推理
python infer.py --model yolov7.onnx --image 000000087038.jpg --device gpu --use_trt True
```

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


## YOLOv7 Python接口

```
Expand All @@ -38,23 +46,23 @@ YOLOv7模型加载和初始化,其中model_file为导出的ONNX模型格式
> ```
> YOLOv7.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5)
> ```
>
> 模型预测结口,输入图像直接输出检测结果。
>
>
> **参数**
>
>
> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式
> > * **conf_threshold**(float): 检测框置信度过滤阈值
> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值

> **返回**
>
>
> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/)

### 类成员属性

> > * **size**(list | tuple): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640]


## 其它文档

- [YOLOv7 模型介绍](..)
Expand Down