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

Migrate QARepVGG from YOLOv6 to MMYOLO #856

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_base_ = '../yolov6_v3_m_syncbn_fast_8xb32-300e_coco.py'

model = dict(
backbone=dict(block_cfg=dict(type='QARepVGGBlockV2')),
neck=dict(block_cfg=dict(type='QARepVGGBlockV2')))
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_base_ = '../yolov6_v3_n_syncbn_fast_8xb32-300e_coco.py'

model = dict(
backbone=dict(block_cfg=dict(type='QARepVGGBlockV2')),
neck=dict(block_cfg=dict(type='QARepVGGBlockV2')))
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_base_ = '../yolov6_v3_s_syncbn_fast_8xb32-300e_coco.py'

model = dict(
backbone=dict(block_cfg=dict(type='QARepVGGBlockV2')),
neck=dict(block_cfg=dict(type='QARepVGGBlockV2')))
10 changes: 5 additions & 5 deletions demo/15_minutes_object_detection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@
},
"outputs": [],
"source": [
"!python projects/easydeploy/tools/export.py \\\n",
"!python projects/easydeploy/tools/export_onnx.py \\\n",
"\t configs/yolov5/yolov5_s-v61_fast_1xb12-40e_cat.py \\\n",
"\t work_dirs/yolov5_s-v61_fast_1xb12-40e_cat/epoch_40.pth \\\n",
"\t --work-dir work_dirs/yolov5_s-v61_fast_1xb12-40e_cat \\\n",
Expand Down Expand Up @@ -842,7 +842,7 @@
"metadata": {},
"outputs": [],
"source": [
"!python projects/easydeploy/tools/image-demo.py \\\n",
"!python projects/easydeploy/tools/image_demo.py \\\n",
" data/cat/images/IMG_20210728_205312.jpg \\\n",
" configs/yolov5/yolov5_s-v61_fast_1xb12-40e_cat.py \\\n",
" work_dirs/yolov5_s-v61_fast_1xb12-40e_cat/end2end.onnx \\\n",
Expand Down Expand Up @@ -873,7 +873,7 @@
},
"outputs": [],
"source": [
"!python projects/easydeploy/tools/export.py \\\n",
"!python projects/easydeploy/tools/export_onnx.py \\\n",
" configs/yolov5/yolov5_s-v61_fast_1xb12-40e_cat.py \\\n",
" work_dirs/yolov5_s-v61_fast_1xb12-40e_cat/epoch_40.pth \\\n",
" --work-dir work_dirs/yolov5_s-v61_fast_1xb12-40e_cat \\\n",
Expand Down Expand Up @@ -941,7 +941,7 @@
"└── yolov5_s-v61_fast_1xb12-40e_cat.py\n",
"```\n",
"\n",
"Let's continue use `image-demo.py` for image inference:"
"Let's continue use `image_demo.py` for image inference:"
]
},
{
Expand All @@ -958,7 +958,7 @@
},
"outputs": [],
"source": [
"!python projects/easydeploy/tools/image-demo.py \\\n",
"!python projects/easydeploy/tools/image_demo.py \\\n",
" data/cat/images/IMG_20210728_205312.jpg \\\n",
" configs/yolov5/yolov5_s-v61_fast_1xb12-40e_cat.py \\\n",
" work_dirs/yolov5_s-v61_fast_1xb12-40e_cat/end2end.engine \\\n",
Expand Down
10 changes: 5 additions & 5 deletions docs/en/get_started/15_minutes_object_detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ pip install tensorrt # If you have GPU environment and need to output Ten
Once installed, you can use the following command to transform and deploy the trained model on the cat dataset with one click. The current ONNX version is 1.13.0 and TensorRT version is 8.5.3.1, so keep the `--opset` value of 11. The remaining parameters need to be adjusted according to the config used. Here we export the CPU version of ONNX with the `--backend` set to 1.

```shell
python projects/easydeploy/tools/export.py \
python projects/easydeploy/tools/export_onnx.py \
configs/yolov5/yolov5_s-v61_fast_1xb12-40e_cat.py \
work_dirs/yolov5_s-v61_fast_1xb12-40e_cat/epoch_40.pth \
--work-dir work_dirs/yolov5_s-v61_fast_1xb12-40e_cat \
Expand All @@ -453,7 +453,7 @@ On success, you will get the converted ONNX model under `work-dir`, which is nam
Let's use `end2end.onnx` model to perform a basic image inference:

```shell
python projects/easydeploy/tools/image-demo.py \
python projects/easydeploy/tools/image_demo.py \
data/cat/images/IMG_20210728_205312.jpg \
configs/yolov5/yolov5_s-v61_fast_1xb12-40e_cat.py \
work_dirs/yolov5_s-v61_fast_1xb12-40e_cat/end2end.onnx \
Expand All @@ -469,7 +469,7 @@ After successful inference, the result image will be generated in the `output` f
Let's go on to convert the engine file for TensorRT, because TensorRT needs to be specific to the current environment and deployment version, so make sure to export the parameters, here we export the TensorRT8 file, the `--backend` is 2.

```shell
python projects/easydeploy/tools/export.py \
python projects/easydeploy/tools/export_onnx.py \
configs/yolov5/yolov5_s-v61_fast_1xb12-40e_cat.py \
work_dirs/yolov5_s-v61_fast_1xb12-40e_cat/epoch_40.pth \
--work-dir work_dirs/yolov5_s-v61_fast_1xb12-40e_cat \
Expand Down Expand Up @@ -514,10 +514,10 @@ work_dirs/yolov5_s-v61_fast_1xb12-40e_cat
└── yolov5_s-v61_fast_1xb12-40e_cat.py
```

Let's continue use `image-demo.py` for image inference:
Let's continue use `image_demo.py` for image inference:

```shell
python projects/easydeploy/tools/image-demo.py \
python projects/easydeploy/tools/image_demo.py \
data/cat/images/IMG_20210728_205312.jpg \
configs/yolov5/yolov5_s-v61_fast_1xb12-40e_cat.py \
work_dirs/yolov5_s-v61_fast_1xb12-40e_cat/end2end.engine \
Expand Down
6 changes: 6 additions & 0 deletions docs/en/recommended_topics/deploy/easydeploy_guide.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# EasyDeploy Deployment

This project acts as a separate deployment project of MMYOLO, with the intention of divorcing the system of MMDeploy, and supporting the conversion and deployment functions of users once they finish the training of models, so as to reduce the learning and engineering costs of users.

Currently, it supports the conversion of ONNX format and TensorRT format, and will support other inference platforms in the future.

You can find more details about MMYOLO EasyDeploy in the [easydeploy document](../../../../projects/easydeploy/README.md).
6 changes: 3 additions & 3 deletions docs/en/recommended_topics/deploy/mmdeploy_yolov5.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ val_dataloader = dict(

We use `allow_scale_up=False` to control when the input small images will be upsampled or not in the initialization of `LetterResize`. At the same time, the default `use_mini_pad=False` turns off the minimum padding strategy of the image, and `val_dataloader['dataset']` is passed in` batch_shapes_cfg=batch_shapes_cfg` to ensure that the minimum padding is performed according to the input size in `batch`. These configs will change the dimensions of the input image, so the converted model can support dynamic inputs according to the above dataset loader when testing.

#### 2. Deployment Cofnig
#### 2. Deployment Config

To deploy the model to `ONNXRuntime`, please refer to the [`detection_onnxruntime_dynamic.py`](https://github.com/open-mmlab/mmyolo/blob/main/configs/deploy/detection_onnxruntime_dynamic.py) for more details.

Expand Down Expand Up @@ -271,11 +271,11 @@ python3 ${MMDEPLOY_DIR}/tools/deploy.py \

When convert the model using the above commands, you will find the following files under the `work_dir` folder:

![image](https://github.com/open-mmlab/mmdeploy/assets/110151316/760f3f7f-aa23-46cf-987c-717d3490246f)
![image](https://github-production-user-asset-6210df.s3.amazonaws.com/110151316/242459821-760f3f7f-aa23-46cf-987c-717d3490246f.png)

or

![image](https://github.com/open-mmlab/mmdeploy/assets/110151316/732bcd9a-fca0-40ba-b5af-540a47eb9c35)
![image](https://github-production-user-asset-6210df.s3.amazonaws.com/110151316/242460083-732bcd9a-fca0-40ba-b5af-540a47eb9c35.png)

After exporting to `onnxruntime`, you will get six files as shown in Figure 1, where `end2end.onnx` represents the exported `onnxruntime` model. The `xxx.json` are the meta info for `MMDeploy SDK` inference.

Expand Down
8 changes: 4 additions & 4 deletions docs/zh_cn/get_started/15_minutes_object_detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ python projects/easydeploy/tools/export_onnx.py \
接下来我们使用此 `end2end.onnx` 模型来进行一个基本的图片推理:

```shell
python projects/easydeploy/tools/image-demo.py \
python projects/easydeploy/tools/image_demo.py \
data/cat/images/IMG_20210728_205117.jpg \
configs/yolov5/yolov5_s-v61_fast_1xb12-40e_cat.py \
work_dirs/yolov5_s-v61_fast_1xb12-40e_cat/end2end.onnx \
Expand All @@ -467,7 +467,7 @@ python projects/easydeploy/tools/image-demo.py \
我们继续转换对应 TensorRT 的 engine 文件,因为 TensorRT 需要对应当前环境以及部署使用的版本进行,所以一定要确认导出参数,这里我们导出对应 TensorRT8 版本的文件,`--backend` 为 2。

```shell
python projects/easydeploy/tools/export.py \
python projects/easydeploy/tools/export_onnx.py \
configs/yolov5/yolov5_s-v61_fast_1xb12-40e_cat.py \
work_dirs/yolov5_s-v61_fast_1xb12-40e_cat/epoch_40.pth \
--work-dir work_dirs/yolov5_s-v61_fast_1xb12-40e_cat \
Expand Down Expand Up @@ -512,10 +512,10 @@ work_dirs/yolov5_s-v61_fast_1xb12-40e_cat
└── yolov5_s-v61_fast_1xb12-40e_cat.py
```

我们继续使用 `image-demo.py` 进行图片推理:
我们继续使用 `image_demo.py` 进行图片推理:

```shell
python projects/easydeploy/tools/image-demo.py \
python projects/easydeploy/tools/image_demo.py \
data/cat/images/IMG_20210728_205312.jpg \
configs/yolov5/yolov5_s-v61_fast_1xb12-40e_cat.py \
work_dirs/yolov5_s-v61_fast_1xb12-40e_cat/end2end.engine \
Expand Down
2 changes: 2 additions & 0 deletions docs/zh_cn/recommended_topics/deploy/easydeploy_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
本项目作为 MMYOLO 的部署 project 单独存在,意图剥离 MMDeploy 当前的体系,独自支持用户完成模型训练后的转换和部署功能,使用户的学习和工程成本下降。

当前支持对 ONNX 格式和 TensorRT 格式的转换,后续对其他推理平台也会支持起来。

更多内容可前往 [EasyDeploy 文档](../../../../projects/easydeploy/README_zh-CN.md) 查看。
8 changes: 5 additions & 3 deletions mmyolo/models/layers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
DarknetBottleneck, EELANBlock, EffectiveSELayer,
ELANBlock, ImplicitA, ImplicitM,
MaxPoolAndStrideConvBlock, PPYOLOEBasicBlock,
RepStageBlock, RepVGGBlock, SPPFBottleneck,
SPPFCSPBlock, TinyDownSampleBlock)
QARepVGGBlock, QARepVGGBlockV2, RepStageBlock,
RepVGGBlock, SPPFBottleneck, SPPFCSPBlock,
TinyDownSampleBlock)

__all__ = [
'SPPFBottleneck', 'RepVGGBlock', 'RepStageBlock', 'ExpMomentumEMA',
'ELANBlock', 'MaxPoolAndStrideConvBlock', 'SPPFCSPBlock',
'PPYOLOEBasicBlock', 'EffectiveSELayer', 'TinyDownSampleBlock',
'EELANBlock', 'ImplicitA', 'ImplicitM', 'BepC3StageBlock',
'CSPLayerWithTwoConv', 'DarknetBottleneck', 'BiFusion'
'CSPLayerWithTwoConv', 'DarknetBottleneck', 'BiFusion', 'QARepVGGBlock',
'QARepVGGBlockV2'
]
Loading