From 3552e8dab6b4f90f138b29e01b026354f37d586d Mon Sep 17 00:00:00 2001 From: WJJ1995 Date: Wed, 16 Jun 2021 09:47:15 +0800 Subject: [PATCH] Add MMDetection2Paddle.md (#621) * add MMDetection2paddle.md * update MMDetection2paddle.md --- .../toolkits/MMDetection2paddle.md | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 docs/inference_model_convertor/toolkits/MMDetection2paddle.md diff --git a/docs/inference_model_convertor/toolkits/MMDetection2paddle.md b/docs/inference_model_convertor/toolkits/MMDetection2paddle.md new file mode 100644 index 0000000..b7d15fe --- /dev/null +++ b/docs/inference_model_convertor/toolkits/MMDetection2paddle.md @@ -0,0 +1,101 @@ +# MMDetection模型导出为Paddle模型教程 + +X2Paddle新增对MMDetection模型支持,目前测试支持的列表如下 +| 模型 | 来源 | OP版本 | 备注 | +| :---- | :---- | :----- | :--- | +| FCOS | [pytorch(mmdetection)](https://github.com/open-mmlab/mmdetection/blob/master/configs/fcos/fcos_r50_caffe_fpn_gn-head_1x_coco.py) | 11 | 仅支持batch=1推理;模型导出需固定shape | +| FSAF | [pytorch(mmdetection)](https://github.com/open-mmlab/mmdetection/blob/master/configs/fsaf/fsaf_r50_fpn_1x_coco.py) | 11 | 仅支持batch=1推理;模型导出需固定shape | +| RetinaNet | [pytorch(mmdetection)](https://github.com/open-mmlab/mmdetection/blob/master/configs/retinanet/retinanet_r50_fpn_1x_coco.py) | 11 | 仅支持batch=1推理;模型导出需固定shape | +| SSD | [pytorch(mmdetection)](https://github.com/open-mmlab/mmdetection/blob/master/configs/ssd/ssd300_coco.py) | 11 | 仅支持batch=1推理;模型导出需固定shape | +| YOLOv3 | [pytorch(mmdetection)](https://github.com/open-mmlab/mmdetection/blob/master/configs/yolo/yolov3_d53_mstrain-608_273e_coco.py) |11 | 仅支持batch=1推理;模型导出需固定shape | +| Faster R-CNN | [pytorch(mmdetection)](https://github.com/open-mmlab/mmdetection/blob/master/configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py) |11 | 仅支持batch=1推理;模型导出需固定shape | + +## 导出教程 + +### 步骤一、通过MMDetection导出ONNX模型 +导出步骤参考文档[MMDetection导出ONNX](https://mmdetection.readthedocs.io/en/latest/tutorials/pytorch2onnx.html),以COCO数据集训练的YOLOv3为例,导出示例如下 +```bash +python tools/deployment/pytorch2onnx.py \ + configs/yolo/yolov3_d53_mstrain-608_273e_coco.py \ + checkpoints/yolo/yolov3_d53_mstrain-608_273e_coco.pth \ + --output-file checkpoints/yolo/yolov3_d53_mstrain-608_273e_coco.onnx \ + --input-img demo/demo.jpg \ + --test-img tests/data/color.jpg \ + --shape 608 608 \ + --mean 0 0 0 \ + --std 255 255 255 \ + --show \ + --verify \ + --dynamic-export \ + --cfg-options \ + model.test_cfg.deploy_nms_pre=-1 \ +``` + +### 步骤二、通过X2Paddle将ONNX模型转换为Paddle格式 +安装X2Paddle最新版本 +``` +pip install x2paddle +``` +使用如下命令转换 +```shell +x2paddle --framework=onnx --model=onnx_model.onnx --save_dir=pd_model +``` +转换后的模型为paddle inference格式,保存在pd_model当中 + +## 结果测试 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ModelConfigMetricONNX RuntimePaddle
FCOSconfigs/fcos/fcos_r50_caffe_fpn_gn-head_4x4_1x_coco.pyBox AP3433.8
FSAFconfigs/fsaf/fsaf_r50_fpn_1x_coco.pyBox AP33.733.7
RetinaNetconfigs/retinanet/retinanet_r50_fpn_1x_coco.pyBox AP34.134.1
SSDconfigs/ssd/ssd300_coco.pyBox AP25.625.6
YOLOv3configs/yolo/yolov3_d53_mstrain-608_273e_coco.pyBox AP31.131.1
Faster R-CNNconfigs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.pyBox AP34.834.8
+ +Notes: + +- 上述AP均为固定shape进行测试,除SSD的shape为300x300、YOLOv3为608x608之外,其他shape均为800x1216 -- GitLab