Simplify your ONNX model
Project description
ONNX Simplifier
ONNX is great, but sometimes too complicated.
Background
One day I wanted to export the following simple reshape operation to ONNX:
import torch
class JustReshape(torch.nn.Module):
def __init__(self):
super(JustReshape, self).__init__()
def forward(self, x):
return x.view((x.shape[0], x.shape[1], x.shape[3], x.shape[2]))
net = JustReshape()
model_name = 'just_reshape.onnx'
dummy_input = torch.randn(2, 3, 4, 5)
torch.onnx.export(net, dummy_input, model_name, input_names=['input'], output_names=['output'])
The input shape in this model is static, so what I expected is
However, I got the following complicated model instead:
Our solution
ONNX Simplifier is presented to simplify the ONNX model. It infers the whole computation graph and then replaces the redundant operators with their constant outputs (a.k.a. constant folding).
Web version
We have published ONNX Simplifier on convertmodel.com. It works out of the box and doesn't need any installation. Note that it runs in the browser locally and your model is completely safe.
Python version
pip3 install -U pip && pip3 install onnxsim
Then
onnxsim input_onnx_model output_onnx_model
For more advanced features, try the following command for help message
onnxsim -h
Demonstration
An overall comparison between a complicated model and its simplified version:
In-script workflow
If you would like to embed ONNX simplifier python package in another script, it is just that simple.
import onnx
from onnxsim import simplify
# load your predefined ONNX model
model = onnx.load(filename)
# convert model
model_simp, check = simplify(model)
assert check, "Simplified ONNX model could not be validated"
# use model_simp as a standard ONNX model object
You can see more details of the API in onnxsim/onnx_simplifier.py
Projects Using ONNX Simplifier
- MXNet
- MMDetection
- YOLOv5
- ncnn
- ...
Chat
We created a Chinese QQ group for ONNX!
ONNX QQ Group (Chinese): 1021964010, verification code: nndab. Welcome to join!
For English users, I'm active on the ONNX Slack. You can find and chat with me (daquexian) there.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file onnx-simplifier-0.4.36.tar.gz
.
File metadata
- Download URL: onnx-simplifier-0.4.36.tar.gz
- Upload date:
- Size: 21.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 661b7383d0a6182b96489b60b36b30852fd4f6066cfbb298b20b2f5455167ff6 |
|
MD5 | 9ba2171909a03ecf9fc8f735c8728a8f |
|
BLAKE2b-256 | 6a959d93b8cfdd9f57abe7000cd6b9e56e2c518ce0e6bf6b312b1cf37b4e68a8 |
File details
Details for the file onnx_simplifier-0.4.36-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: onnx_simplifier-0.4.36-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02a1a7d8573e9ef1c76cf9cad99a95d8dd508941518d0e00c00ef180f53783b4 |
|
MD5 | a9b9e10b14e68910ba784bc04e82aefb |
|
BLAKE2b-256 | ae3819ae776bd80556e7336cab972db7cd2f111b6b3809de7e8deb7bc8125202 |
File details
Details for the file onnx_simplifier-0.4.36-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: onnx_simplifier-0.4.36-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5d1c1f170fd9c07aa475d539e9e752aec352502aeaad7d5004fde7ffad2ca39 |
|
MD5 | 7a52502eaec3880a49e679d21ebac9c4 |
|
BLAKE2b-256 | 0616b19442a60f191f08ae3c4a04627faca12a06fcc9bb24b5accc446a5977b2 |
File details
Details for the file onnx_simplifier-0.4.36-cp311-cp311-macosx_10_15_universal2.whl
.
File metadata
- Download URL: onnx_simplifier-0.4.36-cp311-cp311-macosx_10_15_universal2.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.11, macOS 10.15+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bed97c8fce059abdc6935e2c3f7b65ef43866269ef0049c7ec09a990ae578676 |
|
MD5 | 1be0636f472443b93919e5df8d319a18 |
|
BLAKE2b-256 | b8e38b4743d51a1659da7f7058c8034d858ded88f288d0d8e0a7bd7b2b647ca2 |
File details
Details for the file onnx_simplifier-0.4.36-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: onnx_simplifier-0.4.36-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d360bc0b6a6393c6fd2066ab1e13176f2021b3e6211c05d68865091da0a17062 |
|
MD5 | be4732efdb5e081ee69030ddee1203ec |
|
BLAKE2b-256 | 154bf522b1cdaf44670183dd52475698b74531f1a012212342cf5f77369f9b30 |
File details
Details for the file onnx_simplifier-0.4.36-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: onnx_simplifier-0.4.36-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17a96fc4988bf9fc8a9ae1062e65fc67a905dd199c4094c1709b6972da1e3ef7 |
|
MD5 | 4bd89a58d3f6f906453629299b6b42e5 |
|
BLAKE2b-256 | fc8919043140183f932dd52dc3938d0fd310dd24144de04149c40c64f044d15c |
File details
Details for the file onnx_simplifier-0.4.36-cp310-cp310-macosx_10_15_universal2.whl
.
File metadata
- Download URL: onnx_simplifier-0.4.36-cp310-cp310-macosx_10_15_universal2.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.10, macOS 10.15+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 435e030a2247dda5f24cba0d1a44933a22d445f897477e0629104a897087f8ad |
|
MD5 | 6a4b762d89355d2ded887d6668943641 |
|
BLAKE2b-256 | 1e38d0cc8988ffe0fde0a83b21238558e5f4aaa19ddb73543537e4c7712ec20e |
File details
Details for the file onnx_simplifier-0.4.36-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: onnx_simplifier-0.4.36-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0b6bb9df73f4578a2f75311b0b077f791d027e7f555eeb6582db7d45388daaf |
|
MD5 | 4a8585088c4cde527f29c16a50256f01 |
|
BLAKE2b-256 | a77ff1765d3464ab12f7e0b90418f84e07e509619dae0f7f155c51cd7dd7e4f9 |
File details
Details for the file onnx_simplifier-0.4.36-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: onnx_simplifier-0.4.36-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cbfa793ebea08d0d25685aea291910863e5f7b8dfc2f065bb5f05b76bb8ccf6 |
|
MD5 | 390ac85b385ae60d2315f9d53f1e8d5c |
|
BLAKE2b-256 | d4a5ea7c4591080aa4f104e0c98334635e321c300542be6641a71d3b3e734741 |
File details
Details for the file onnx_simplifier-0.4.36-cp39-cp39-macosx_10_15_universal2.whl
.
File metadata
- Download URL: onnx_simplifier-0.4.36-cp39-cp39-macosx_10_15_universal2.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.9, macOS 10.15+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce57e54a7fe73a10feb698a35d7aa0e15dac8b5838a44a972a066ffeb5a75c6c |
|
MD5 | 51ecbc04692cb321fa839c3b34a849f4 |
|
BLAKE2b-256 | 255aaa97696e71f603eeea949b68a1497782c8922ec2e44ff3532ff32517f06c |
File details
Details for the file onnx_simplifier-0.4.36-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: onnx_simplifier-0.4.36-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 646d58721469e3a2cbb28e443c02f4eec1a61ceb0b0f27f61a6ad1415eb0d3c8 |
|
MD5 | cdd4ab765056c1b7aa265b00b03d97da |
|
BLAKE2b-256 | 3b63496174583084c9227b630ea1fcf044da6abce7657b0d4c767f15cbf8fa85 |
File details
Details for the file onnx_simplifier-0.4.36-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: onnx_simplifier-0.4.36-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27aaaee44fed3bd0d1c035c3e261939e2c10ed0bc5f19b396f2af5f2982eab52 |
|
MD5 | a0c5dbe07c60a0db9a28701e1b57afb3 |
|
BLAKE2b-256 | 0a24ed183f4aa7471b6378674172e13db69b136af718d4808fe7de0ae0a72bbd |
File details
Details for the file onnx_simplifier-0.4.36-cp38-cp38-macosx_10_15_universal2.whl
.
File metadata
- Download URL: onnx_simplifier-0.4.36-cp38-cp38-macosx_10_15_universal2.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.8, macOS 10.15+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 536785d665654eb0bf1c76c4778cc17770f58343afae8d5bfd441c55c3da7922 |
|
MD5 | ae5eaacd1a1b2504aeac22b27bcbf403 |
|
BLAKE2b-256 | ea79c317d6ba049de4f7cd2401f13ce93255914c7d5ca14076a5f95ab38435f1 |
File details
Details for the file onnx_simplifier-0.4.36-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: onnx_simplifier-0.4.36-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcf63bbc7f2135fe45f5d17c01e2ea3949427118fe64ecf970bd180c69b6cdd6 |
|
MD5 | fae394ccf178182a58feb3168f21e2e4 |
|
BLAKE2b-256 | bd258ba5df4c801866d4a77c0e4540fd9f0ae8a9859646369d77a0bd4a121312 |
File details
Details for the file onnx_simplifier-0.4.36-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: onnx_simplifier-0.4.36-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98256a79cfc7c4a6cf5ac93af567e7ebe14b933c535a9cc834245dce552b4901 |
|
MD5 | 9638e47b785c573be43168521b87a596 |
|
BLAKE2b-256 | 4552bf6c3cab13b88036bf363367c5caf87ffc33b2fbd23a2dbc2dff01c43da5 |