本章节介绍如何使用tools/export_model.py
脚本导出模型。
输入名称 | 输入形状 | 表示含义 |
---|---|---|
image | [None, 3, H, W] | 输入网络的图像,None表示batch维度,如果输入图像大小为变长,则H,W为None |
im_shape | [None, 2] | 图像经过resize后的大小,表示为H,W, None表示batch维度 |
scale_factor | [None, 2] | 输入图像大小比真实图像大小,表示为scale_y, scale_x |
注意具体预处理方式可参考配置文件中TestReader部分。
PaddleDetection中动转静导出模型输出统一为:
注意模型动转静导出不支持模型结构中包含numpy相关操作的情况。
FLAG | 用途 | 默认值 | 备注 |
---|---|---|---|
-c | 指定配置文件 | None | |
--output_dir | 模型保存路径 | ./output_inference |
模型默认保存在output/配置文件名/ 路径下 |
使用训练得到的模型进行试用,脚本如下
# 导出YOLOv3模型
python tools/export_model.py -c configs/yolov3/yolov3_darknet53_270e_coco.yml --output_dir=./inference_model \
-o weights=weights/yolov3_darknet53_270e_coco.pdparams
预测模型会导出到inference_model/yolov3_darknet53_270e_coco
目录下,分别为infer_cfg.yml
, model.pdiparams
, model.pdiparams.info
, model.pdmodel
。
使用Fluid-TensorRT进行预测时,由于<=TensorRT 5.1的版本仅支持定长输入,保存模型的data
层的图片大小需要和实际输入图片大小一致。而Fluid C++预测引擎没有此限制。设置TestReader中的image_shape
可以修改保存模型中的输入图片大小。示例如下:
# 导出YOLOv3模型,输入是3x640x640
python tools/export_model.py -c configs/yolov3/yolov3_darknet53_270e_coco.yml --output_dir=./inference_model \
-o weights=weights/yolov3_darknet53_270e_coco.pdparams TestReader.inputs_def.image_shape=[3,640,640]
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》