依赖 PaddlePaddle 3.0.0 和 onnxruntime >= 1.10.0,版本不匹配会出问题;转换前需准备 json 结构和 pdiparams 参数两个部署模型文件,普通训练权重不行;低版本 opset 转换失败时需依赖自动升级或手动指定更高 opset
把 PaddlePaddle 模型转成 ONNX,方便部署到 TensorRT、OpenVINO、MNN 等推理引擎
把 PaddlePaddle 训练好的模型导出成 ONNX 格式,方便用 ONNX Runtime 等推理引擎部署,覆盖分类、检测、OCR 等模型。
核心能力
- 将 Paddle 部署模型(json+pdiparams)导出为 ONNX 格式
- 支持 opset 7~19,默认 9 并可自动升级版本
- 导出时默认开启 ONNX 正确性检查
- 可选拆解组合算子、用 onnxoptimizer 等工具优化
- 推荐配合 onnxslim 进一步精简 ONNX 模型
容易踩的坑
- v2.1.0最新正式版2026-01-12 · 2026-01-12 02:14 UTC
What's Changed
- Support compilation on windows by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1561
- Fix the issue with optimize tools by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1563
- [Optimizer] Check ONNX model after optimization by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1565
- Update version number by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1566
- [Release] Add more windows release by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1567
- [Debug] Record debug info for exporting op by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1568
- Add Conv2D_Dropout test by @zhanghonggeng in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1569
- [Fix] Fix the issue with mapper of tile op by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1571
- Use
shutil.whichinstead of deprecatedfind_executableby @emmanuel-ferdman in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1572 - Support conversion of hardswish using opset 7 by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1574
- Update validation of paddle by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1576
- Update version number by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1577
- Limit package version of
onnxby @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1579 - Update version number by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1582
- support dynamic shape in repeat_interleave op by @zhanghonggeng in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1589
- Fix the issue with full_with_tensor, sum by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1594
- Add support for PP-DocLayoutV2 by @alex-dinh in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1619
- update version number by @jzhang533 in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1621
New Contributors
- @emmanuel-ferdman made their first contribution in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1572
- @alex-dinh made their first contribution in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1619
Full Changelog: https://github.com/PaddlePaddle/Paddle2ONNX/compare/v2.0.1...v2.1.0
- v2.0.2rc3Paddle2ONNX v2.0.2rc3pre-release2025-05-27 · 2025-05-27 03:52 UTC
查看更新说明
What's Changed
- Limit package version of
onnxby @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1579
Full Changelog: https://github.com/PaddlePaddle/Paddle2ONNX/compare/v2.0.2rc2...v2.0.2rc3
- Limit package version of
- v2.0.2rc2Paddle2ONNX v2.0.2rc2pre-release2025-05-22 · 2025-05-22 11:13 UTC
查看更新说明
What's Changed
- [Debug] Record debug info for exporting op by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1568
- Add Conv2D_Dropout test by @zhanghonggeng in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1569
- [Fix] Fix the issue with mapper of tile op by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1571
- Use
shutil.whichinstead of deprecatedfind_executableby @emmanuel-ferdman in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1572 - Support conversion of hardswish using opset 7 by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1574
- Update validation of paddle by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1576
New Contributors
- @emmanuel-ferdman made their first contribution in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1572
Full Changelog: https://github.com/PaddlePaddle/Paddle2ONNX/compare/v2.0.2rc1...v2.0.2rc2
- v2.0.2rc1Paddle2ONNX v2.0.2rc1pre-release2025-04-27 · 2025-04-27 13:39 UTC
查看更新说明
What's Changed
- Support compilation on windows by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1561
- Fix the issue with optimize tools by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1563
- [Optimizer] Check ONNX model after optimization by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1565
Full Changelog: https://github.com/PaddlePaddle/Paddle2ONNX/compare/v2.0.1...v2.0.2rc1
- v2.0.1Paddle2ONNX v2.0.12025-04-18 · 2025-04-18 06:11 UTC
查看更新说明
What's Changed
- make libpaddle2onnx.so link libpaddle.so and include paddle_include direcotory by @risemeup1 in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1352
- support pir mode in paddle2onnx by @risemeup1 in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1354
- Support pir by @qzylalala in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1389
- Get input/output/attrvar interface by @risemeup1 in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1380
- Conversion of ResNet50 model under PIR by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1382
- [PIR] Use paddlepaddle==3.0.0.dev20240904 in CI of test_pir by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1395
- [PIR] Completion of unit testing in PIR mode by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1394
- [OSPP][PIR] support mobilenet v2 by @qzylalala in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1397
- Automatic mapping of operator variable names to indices by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1401
- [PIR] Adjust some interfaces in PIR && Support conversion of builtin.combine and builtin.split by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1402
- Support op concat, split, split_with_num, transpose by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1403
- [OSPP][PIR] support dropout and squeeze by @qzylalala in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1406
- [PIR]support if op by @risemeup1 in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1407
- support some ops in pir by @qzylalala in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1416
- Support some operations by @qzylalala in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1419
- Support while op in pir mode by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1426
- Support some ops in PIR by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1435
- Merge PR#1434 by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1437
- support some ops by @qzylalala in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1434
- Improved the mechanism, added the conversion of some ops, and fixed some issues. by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1444
- Improve some operations to support more scenarios by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1450
- Fix issues with inference of LaTeX_OCR_rec model by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1452
- Merge the develop branch into the test_pir branch by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1455
- Fix the issue with multiclass_nms3 op by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1456
- Support compilation and loading on macOS by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1462
- Support compilation and loading on Windows by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1465
- Add patch for compilaition on Windows by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1470
- Update usage documentation by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1473
- Enhance monitoring for macOS and Windows platforms using github action by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1469
- Fix issues with inference of onnx models converted from paddlex by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1484
- Fix the issue with determining whether operators in control flow are registered. by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1485
- Support phi::DataType::UNDEFINED by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1486
- Improve the mechanism by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1487
- Update CI and README by @0x3878f in https://github.com/PaddlePaddle/Paddle2ONNX/pull/1492
- Update the package release workflow by @0x3878f in https://github.com/
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Paddle2ONNX
简体中文 | English
1 Paddle2ONNX 简介
Paddle2ONNX 支持将 PaddlePaddle 模型格式转化到 ONNX 模型格式。通过 ONNX 可以完成将 Paddle 模型到多种推理引擎的部署,包括 TensorRT/OpenVINO/MNN/TNN/NCNN,以及其它对 ONNX 开源格式进行支持的推理引擎或硬件。
2 Paddle2ONNX 环境依赖
Paddle2ONNX 依赖PaddlePaddle3.0,我们建议您在以下环境下使用 Paddle2ONNX :
- PaddlePaddle == 3.0.0
- onnxruntime >= 1.10.0
3 安装 Paddle2ONNX
如果您只是想要安装 Paddle2ONNX 且没有二次开发的需求,你可以通过执行以下代码来快速安装 Paddle2ONNX
pip install paddle2onnx
如果你希望对 Paddle2ONNX 进行二次开发,请按照Github 源码安装方式编译Paddle2ONNX。
4 快速使用教程
4.1 获取PaddlePaddle部署模型
Paddle2ONNX 在导出模型时,需要传入部署模型格式,包括两个文件
model_name.json: 表示模型结构model_name.pdiparams: 表示模型参数
4.2 调整Paddle模型
如果对Paddle模型的输入输出需要做调整,可以前往Paddle 相关工具查看教程。
4.3 使用命令行转换 PaddlePaddle 模型
你可以通过使用命令行并通过以下命令将Paddle模型转换为ONNX模型
paddle2onnx --model_dir model_dir \
--model_filename model.json \
--params_filename model.pdiparams \
--save_file model.onnx
可调整的转换参数如下表:
| 参数 | 参数说明 |
|---|---|
| --model_dir | 配置包含 Paddle 模型的目录路径 |
| --model_filename | [可选] 配置位于 --model_dir 下存储网络结构的文件名 |
| --params_filename | [可选] 配置位于 --model_dir 下存储模型参数的文件名 |
| --save_file | 指定转换后的模型保存目录路径 |
| --opset_version | [可选] 配置转换为ONNX的OpSet版本,目前支持7~19等多个版本,默认为 9 |
| --enable_auto_update_opset | [可选] 是否开启opset version自动升级功能,当低版本opset无法转换时,自动选择更高版本的opset进行转换, 默认为 True |
| --enable_onnx_checker | [可选] 配置是否检查导出为 ONNX 模型的正确性, 建议打开此开关, 默认为 True |
| --enable_dist_prim_all | [可选] 是否开启组合算子拆解,默为 False |
| --optimize_tool | [可选] ONNX模型优化工具,可选择onnxoptimizer、polygraphy、None, 默认为 onnxoptimizer |
| --enable_verbose | [可选] 是否打印更更详细的日志信息,默认为 False |
| --version | [可选] 查看 paddle2onnx 版本 |
4.4 裁剪ONNX
如果你需要调整 ONNX 模型,请参考 ONNX 相关工具
4.5 优化ONNX
如你对导出的 ONNX 模型有优化的需求,推荐使用 onnxslim 对模型进行优化:
pip install onnxslim
onnxslim model.onnx slim.onnx
5 代码贡献
繁荣的生态需要大家的携手共建,开发者可以参考 Paddle2ONNX 贡献指南 来为 Paddle2ONNX 贡献代码。
6 License
Provided under the Apache-2.0 license.