{"id":13438793,"url":"https://github.com/daquexian/onnx-simplifier","last_synced_at":"2025-05-13T19:02:49.129Z","repository":{"id":37664070,"uuid":"178837505","full_name":"daquexian/onnx-simplifier","owner":"daquexian","description":"Simplify your onnx model","archived":false,"fork":false,"pushed_at":"2024-09-03T22:43:22.000Z","size":430,"stargazers_count":4067,"open_issues_count":169,"forks_count":396,"subscribers_count":48,"default_branch":"master","last_synced_at":"2025-05-06T21:11:58.264Z","etag":null,"topics":["deep-learning","onnx","pytorch"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daquexian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-01T10:12:34.000Z","updated_at":"2025-05-06T10:06:16.000Z","dependencies_parsed_at":"2023-02-19T16:05:16.320Z","dependency_job_id":"e82fb0f8-2fb0-4809-bc18-b4f583dc109a","html_url":"https://github.com/daquexian/onnx-simplifier","commit_stats":{"total_commits":283,"total_committers":15,"mean_commits":"18.866666666666667","dds":0.09893992932862195,"last_synced_commit":"72c1706bf59353506cf373bfc16d272c7d3082bc"},"previous_names":[],"tags_count":84,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daquexian%2Fonnx-simplifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daquexian%2Fonnx-simplifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daquexian%2Fonnx-simplifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daquexian%2Fonnx-simplifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daquexian","download_url":"https://codeload.github.com/daquexian/onnx-simplifier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254010792,"owners_count":21998993,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","onnx","pytorch"],"created_at":"2024-07-31T03:01:08.485Z","updated_at":"2025-05-13T19:02:49.110Z","avatar_url":"https://github.com/daquexian.png","language":"C++","funding_links":[],"categories":["C++","🛠️ Tools \u0026 Utilities"],"sub_categories":["🔄 Model Conversion \u0026 Editing"],"readme":"# ONNX Simplifier\n\n[![PyPI version](https://img.shields.io/pypi/v/onnx-simplifier.svg)](https://pypi.python.org/pypi/onnx-simplifier/)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/onnx-simplifier.svg)](https://pypi.python.org/pypi/onnx-simplifier/)\n[![PyPI license](https://img.shields.io/pypi/l/onnx-simplifier.svg)](https://pypi.python.org/pypi/onnx-simplifier/)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/daquexian/onnx-simplifier/pulls)\n\n_ONNX is great, but sometimes too complicated._\n\n## Background\n\nOne day I wanted to export the following simple reshape operation to ONNX:\n\n```python\nimport torch\n\n\nclass JustReshape(torch.nn.Module):\n    def __init__(self):\n        super(JustReshape, self).__init__()\n\n    def forward(self, x):\n        return x.view((x.shape[0], x.shape[1], x.shape[3], x.shape[2]))\n\n\nnet = JustReshape()\nmodel_name = 'just_reshape.onnx'\ndummy_input = torch.randn(2, 3, 4, 5)\ntorch.onnx.export(net, dummy_input, model_name, input_names=['input'], output_names=['output'])\n```\n\nThe input shape in this model is static, so what I expected is\n\n![simple_reshape](imgs/simple_reshape.png)\n\nHowever, I got the following complicated model instead:\n\n![complicated_reshape](imgs/complicated_reshape.png)\n\n## Our solution\n\nONNX Simplifier is presented to simplify the ONNX model. It infers the whole computation graph\nand then replaces the redundant operators with their constant outputs (a.k.a. constant folding).\n\n### Web version\n\nWe have published ONNX Simplifier on [convertmodel.com](https://www.convertmodel.com/#input=onnx\u0026output=onnx). 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.\n\n### Python version\n\n\n```\npip3 install -U pip \u0026\u0026 pip3 install onnxsim\n```\n\nThen\n\n```\nonnxsim input_onnx_model output_onnx_model\n```\n\nFor more advanced features, try the following command for help message\n\n```\nonnxsim -h\n```\n\n## Demonstration\n\nAn overall comparison between\n[a complicated model](https://github.com/JDAI-CV/DNNLibrary/issues/17#issuecomment-455934190)\nand its simplified version:\n\n![Comparison between old model and new model](imgs/comparison.png)\n\n## In-script workflow\n\nIf you would like to embed ONNX simplifier python package in another script, it is just that simple.\n\n```python\nimport onnx\nfrom onnxsim import simplify\n\n# load your predefined ONNX model\nmodel = onnx.load(filename)\n\n# convert model\nmodel_simp, check = simplify(model)\n\nassert check, \"Simplified ONNX model could not be validated\"\n\n# use model_simp as a standard ONNX model object\n```\n\nYou can see more details of the API in [onnxsim/onnx_simplifier.py](onnxsim/onnx_simplifier.py)\n\n## Projects Using ONNX Simplifier\n\n* [MXNet](https://mxnet.apache.org/versions/1.9.1/api/python/docs/tutorials/deploy/export/onnx.html#Simplify-the-exported-ONNX-model)\n* [MMDetection](https://github.com/open-mmlab/mmdetection)\n* [YOLOv5](https://github.com/ultralytics/yolov5)\n* [ncnn](https://github.com/Tencent/ncnn)\n* ...\n\n## Chat\n\nWe created a Chinese QQ group for ONNX!\n\nONNX QQ Group (Chinese): 1021964010, verification code: nndab. Welcome to join!\n\nFor English users, I'm active on the [ONNX Slack](https://github.com/onnx/onnx#discuss). You can find and chat with me (daquexian) there.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaquexian%2Fonnx-simplifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaquexian%2Fonnx-simplifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaquexian%2Fonnx-simplifier/lists"}