Skip to main content

Export PaddlePaddle to ONNX

Project description

Paddle2ONNX

简体中文 | English

1 Paddle2ONNX 简介

Paddle2ONNX 支持将 PaddlePaddle 模型格式转化到 ONNX 模型格式。通过 ONNX 可以完成将 Paddle 模型到多种推理引擎的部署,包括 TensorRT/OpenVINO/MNN/TNN/NCNN,以及其它对 ONNX 开源格式进行支持的推理引擎或硬件。

2 Paddle2ONNX 环境依赖

Paddle2ONNX 本身不依赖其他组件,但是我们建议您在以下环境下使用 Paddle2ONNX :

  • PaddlePaddle == 2.6.0
  • onnxruntime >= 1.10.0

3 安装 Paddle2ONNX

如果您只是想要安装 Paddle2ONNX 且没有二次开发的需求,你可以通过执行以下代码来快速安装 Paddle2ONNX

pip install paddle2onnx

如果你希望对 Paddle2ONNX 进行二次开发,请按照Github 源码安装方式编译Paddle2ONNX。

4 快速使用教程

4.1 获取PaddlePaddle部署模型

Paddle2ONNX 在导出模型时,需要传入部署模型格式,包括两个文件

  • model_name.pdmodel: 表示模型结构
  • model_name.pdiparams: 表示模型参数

4.2 调整Paddle模型

如果对Paddle模型的输入输出需要做调整,可以前往Paddle 相关工具查看教程。

4.3 使用命令行转换 PaddlePaddle 模型

你可以通过使用命令行并通过以下命令将Paddle模型转换为ONNX模型

paddle2onnx --model_dir model_dir \
            --model_filename inference.pdmodel \
            --params_filename inference.pdiparams \
            --save_file model.onnx

可调整的转换参数如下表:

参数 参数说明
--model_dir 配置包含 Paddle 模型的目录路径
--model_filename [可选] 配置位于 --model_dir 下存储网络结构的文件名
--params_filename [可选] 配置位于 --model_dir 下存储模型参数的文件名称
--save_file 指定转换后的模型保存目录路径
--opset_version [可选] 配置转换为 ONNX 的 OpSet 版本,目前支持 7~16 等多个版本,默认为 9
--enable_onnx_checker [可选] 配置是否检查导出为 ONNX 模型的正确性, 建议打开此开关, 默认为 True
--enable_auto_update_opset [可选] 是否开启 opset version 自动升级功能,当低版本 opset 无法转换时,自动选择更高版本的 opset进行转换, 默认为 True
--deploy_backend [可选] 量化模型部署的推理引擎,支持 onnxruntime/rknn/tensorrt, 默认为 onnxruntime
--save_calibration_file [可选] TensorRT 8.X版本部署量化模型需要读取的 cache 文件的保存路径,默认为 calibration.cache
--version [可选] 查看 paddle2onnx 版本
--external_filename [可选] 当导出的 ONNX 模型大于 2G 时,需要设置 external data 的存储路径,推荐设置为:external_data
--export_fp16_model [可选] 是否将导出的 ONNX 的模型转换为 FP16 格式,并用 ONNXRuntime-GPU 加速推理,默认为 False
--custom_ops [可选] 将 Paddle OP 导出为 ONNX 的 Custom OP,例如:--custom_ops '{"paddle_op":"onnx_op"},默认为 {}

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.

7 感谢捐赠

  • 感谢 PaddlePaddle 团队提供服务器支持 Paddle2ONNX 的 CI 建设。
  • 感谢社区用户 chenwhql, luotao1, goocody, jeff41404, jzhang553, ZhengBicheng 于2024年03月28日向 Paddle2ONNX PMC 捐赠共 10000 元人名币用于 Paddle2ONNX 的发展。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

paddle2onnx-1.3.0-cp312-cp312-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.12Windows x86-64

paddle2onnx-1.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

paddle2onnx-1.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

paddle2onnx-1.3.0-cp311-cp311-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.11Windows x86-64

paddle2onnx-1.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

paddle2onnx-1.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

paddle2onnx-1.3.0-cp310-cp310-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.10Windows x86-64

paddle2onnx-1.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

paddle2onnx-1.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

paddle2onnx-1.3.0-cp39-cp39-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.9Windows x86-64

paddle2onnx-1.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

paddle2onnx-1.3.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

paddle2onnx-1.3.0-cp38-cp38-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.8Windows x86-64

paddle2onnx-1.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

paddle2onnx-1.3.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.4 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

File details

Details for the file paddle2onnx-1.3.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for paddle2onnx-1.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9808c33c9acadf0ce3f7e83b2a2df6362346a631de10a097d6ae2c9d78872481
MD5 436d4f7856b8cee7c1ee3ec6936614ef
BLAKE2b-256 e40b67d027bd5dfbff4b6099f0043a81768ae8a00d90235e1090f91687c35ca7

See more details on using hashes here.

File details

Details for the file paddle2onnx-1.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for paddle2onnx-1.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 efd92254549697e4d076d4cd1f43180a722791875f1f42e54f536e3731c2d948
MD5 3d3a22d239e5a4ea5537f9c2cbdddd68
BLAKE2b-256 ccac60b11942ea5e5a406d6ebfe69e93fa1fa78e93ae1f62153f63c6ef2d630d

See more details on using hashes here.

File details

Details for the file paddle2onnx-1.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for paddle2onnx-1.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8617831ea714cba5354914465d5482518e9431d4b2cb2e234dae93fe16b22546
MD5 00af5d4a6ed7319cccb270a7137e394a
BLAKE2b-256 d0c6e21414bc814f73629395f6e5e40690374a6468bdcf71ac73ee18d693e0e9

See more details on using hashes here.

File details

Details for the file paddle2onnx-1.3.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for paddle2onnx-1.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c759bedc7fa42d6230d31ebccf7366cec9a222c33fe7669917967be02cefcda2
MD5 6add7c34af58c191511266ebdd09246f
BLAKE2b-256 9ea5dfa3bc89d2388ef11c29de0145a4f12cbd62aaa67f5c0205e5085f5d6e1f

See more details on using hashes here.

File details

Details for the file paddle2onnx-1.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for paddle2onnx-1.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4f893d93bf88f8624dff4ac55e9b513b3d916940692e7d5767f3030933e4692f
MD5 813d3862dee9eb10757e77a50a9474a6
BLAKE2b-256 de179bca43aa25c725a390e33133e81dd1f4f21c6fcd1d8fe99a28d93cddb1b6

See more details on using hashes here.

File details

Details for the file paddle2onnx-1.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for paddle2onnx-1.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b78d9322ac15fbe8dd6933b245a3885a81c210c8281574c70b2670b94a431d98
MD5 bf77908ead7e8f180c48d7685f170fc9
BLAKE2b-256 ca1d556bf9daaf7946806d751bdc4172c5428fe77f15d6dbb314341e22f3be2f

See more details on using hashes here.

File details

Details for the file paddle2onnx-1.3.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for paddle2onnx-1.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ceacfffa64109d4e0ecb6156c99fe1c0e9e2ded965954db6297483bb3bdfe663
MD5 213f69023e16e3c4f21b9e081298e72c
BLAKE2b-256 f0cb006a7d406fa721fa39ea11100ceb515b24c60d5bbfa26a22f0a4a5d12df9

See more details on using hashes here.

File details

Details for the file paddle2onnx-1.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for paddle2onnx-1.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 75260083289f2be09f95a5fa7c309bfd420820dfc3b33462db08c4fd79a2f9a3
MD5 3e57b02f155c75c241a006b731c6364d
BLAKE2b-256 97cd99f051444ad20bc7f588fe35fefc16d2bf412bab0a1744f90d6b35360174

See more details on using hashes here.

File details

Details for the file paddle2onnx-1.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for paddle2onnx-1.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 221a9c280383b05bdcc62c0fb83676d03ab25baadc18879a4a3099902003ce37
MD5 6d156d48d0333592569b4f15ed02d9e4
BLAKE2b-256 f20a822ec6eb02a35b566d93e1d67d84b25d90bf6aa02c9f57c85e488858d813

See more details on using hashes here.

File details

Details for the file paddle2onnx-1.3.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: paddle2onnx-1.3.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.13

File hashes

Hashes for paddle2onnx-1.3.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3d80a77a47d6eca0126f8c07b3ae186a5cea5329add89133af2d8d17c7194a99
MD5 9ae5df1252e705bb822381a1728a7ded
BLAKE2b-256 f23c181fca64a31fbbe825911a165a687c56634e7579786d09e5c6cf62b913c3

See more details on using hashes here.

File details

Details for the file paddle2onnx-1.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for paddle2onnx-1.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bcc39f3e3733d51d071ec4e57ef1be278b7bb59d58c2613c59830d17f20e70c1
MD5 068cae9470fef06e68f04266ae4312f8
BLAKE2b-256 580e15878f91524716bf80d1e8a94e973b15e0b48d5b427c54ac9a9a59b3788f

See more details on using hashes here.

File details

Details for the file paddle2onnx-1.3.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for paddle2onnx-1.3.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 654c05c7cac67764e067415370035b6f7b36ce8deb9a02a3cfc870f975f923c8
MD5 b0cbed80a81c8cf7bb9bb51a2e738ffd
BLAKE2b-256 046c6f16b0090b773ef0f128e722101e50c113547302801b3e63cbdec130457d

See more details on using hashes here.

File details

Details for the file paddle2onnx-1.3.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: paddle2onnx-1.3.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for paddle2onnx-1.3.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 28021381ab7eede77537863880b487c5ed9f6ab951b3b29966bd7edee808c663
MD5 fadbea8178009d437cc554752667bccd
BLAKE2b-256 db236216316391a59e9d4a4ec641b9ef3d4707516ddc6e5799691cfc5b968f9e

See more details on using hashes here.

File details

Details for the file paddle2onnx-1.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for paddle2onnx-1.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 92e5c7ce68102297513164e9e386aebe3d456ab0b3011427438b1e12fc34b3e3
MD5 778cb2d561dea2f7dfb2374b8a322c0f
BLAKE2b-256 3a5efd5f7dc5c7ba10b4db0a00d391a925ee8801d84f1a8a037948e7b2db6c0a

See more details on using hashes here.

File details

Details for the file paddle2onnx-1.3.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for paddle2onnx-1.3.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 45819ac82aac6c78b1ce2e043390cbd10a701b7dd6b4e59e9e93b9fb1ac4bd65
MD5 1e5935a8902373bbc7f2a9f534df0f1a
BLAKE2b-256 26c8001f2a439e060777990e098f8c9c0575da289bb6dd68f71df191c9724aa3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page