{"id":15677822,"url":"https://github.com/pinto0309/sne4onnx","last_synced_at":"2026-02-24T14:14:57.476Z","repository":{"id":40442740,"uuid":"478618112","full_name":"PINTO0309/sne4onnx","owner":"PINTO0309","description":"A very simple tool for situations where optimization with onnx-simplifier would exceed the Protocol Buffers upper file size limit of 2GB, or simply to separate onnx files to any size you want.","archived":false,"fork":false,"pushed_at":"2024-05-07T06:05:47.000Z","size":31,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-12T13:42:39.944Z","etag":null,"topics":["cli","model-converter","models","onnx","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PINTO0309.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":"2022-04-06T15:25:30.000Z","updated_at":"2025-02-11T09:08:39.000Z","dependencies_parsed_at":"2024-05-07T07:26:07.164Z","dependency_job_id":"2152f9d4-7abc-4481-9da3-b3139d701fc6","html_url":"https://github.com/PINTO0309/sne4onnx","commit_stats":{"total_commits":30,"total_committers":1,"mean_commits":30.0,"dds":0.0,"last_synced_commit":"fdb1caefa3137383dbfd0ad516799126a4f5daa8"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Fsne4onnx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Fsne4onnx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Fsne4onnx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Fsne4onnx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PINTO0309","download_url":"https://codeload.github.com/PINTO0309/sne4onnx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248914541,"owners_count":21182435,"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":["cli","model-converter","models","onnx","python"],"created_at":"2024-10-03T16:12:24.503Z","updated_at":"2026-02-24T14:14:57.471Z","avatar_url":"https://github.com/PINTO0309.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sne4onnx\nA very simple tool for situations where optimization with onnx-simplifier would exceed the Protocol Buffers upper file size limit of 2GB, or simply to separate onnx files to any size you want. **S**imple **N**etwork **E**xtraction for **ONNX**.\n\nhttps://github.com/PINTO0309/simple-onnx-processing-tools\n\n[![Downloads](https://static.pepy.tech/personalized-badge/sne4onnx?period=total\u0026units=none\u0026left_color=grey\u0026right_color=brightgreen\u0026left_text=Downloads)](https://pepy.tech/project/sne4onnx) ![GitHub](https://img.shields.io/github/license/PINTO0309/sne4onnx?color=2BAF2B) [![PyPI](https://img.shields.io/pypi/v/sne4onnx?color=2BAF2B)](https://pypi.org/project/sne4onnx/) [![CodeQL](https://github.com/PINTO0309/sne4onnx/workflows/CodeQL/badge.svg)](https://github.com/PINTO0309/sne4onnx/actions?query=workflow%3ACodeQL)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/33194443/170151483-f99b2b70-9b69-48b7-8690-0ddfa8fb8989.png\" /\u003e\n\u003c/p\u003e\n\n# Key concept\n- [x] If INPUT OP name and OUTPUT OP name are specified, the onnx graph within the range of the specified OP name is extracted and .onnx is generated.\n- [x] I do not use `onnx.utils.extractor.extract_model` because it is very slow and I implement my own model separation logic.\n\n## 1. Setup\n### 1-1. HostPC\n```bash\n### option\n$ echo export PATH=\"~/.local/bin:$PATH\" \u003e\u003e ~/.bashrc \\\n\u0026\u0026 source ~/.bashrc\n\n### run\n$ pip install -U onnx sne4onnx\n```\n### 1-2. Docker\nhttps://github.com/PINTO0309/simple-onnx-processing-tools#docker\n\n## 2. CLI Usage\n```bash\n$ sne4onnx -h\n\nusage:\n    sne4onnx [-h]\n    -if INPUT_ONNX_FILE_PATH\n    -ion INPUT_OP_NAMES\n    -oon OUTPUT_OP_NAMES\n    [-of OUTPUT_ONNX_FILE_PATH]\n    [-n]\n\noptional arguments:\n  -h, --help\n    show this help message and exit\n\n  -if INPUT_ONNX_FILE_PATH, --input_onnx_file_path INPUT_ONNX_FILE_PATH\n    Input onnx file path.\n\n  -ion INPUT_OP_NAMES [INPUT_OP_NAMES ...], --input_op_names INPUT_OP_NAMES [INPUT_OP_NAMES ...]\n    List of OP names to specify for the input layer of the model.\n    e.g. --input_op_names aaa bbb ccc\n\n  -oon OUTPUT_OP_NAMES [OUTPUT_OP_NAMES ...], --output_op_names OUTPUT_OP_NAMES [OUTPUT_OP_NAMES ...]\n    List of OP names to specify for the output layer of the model.\n    e.g. --output_op_names ddd eee fff\n\n  -of OUTPUT_ONNX_FILE_PATH, --output_onnx_file_path OUTPUT_ONNX_FILE_PATH\n    Output onnx file path. If not specified, extracted.onnx is output.\n\n  -n, --non_verbose\n    Do not show all information logs. Only error logs are displayed.\n```\n\n## 3. In-script Usage\n```bash\n$ python\n\u003e\u003e\u003e from sne4onnx import extraction\n\u003e\u003e\u003e help(extraction)\n\nHelp on function extraction in module sne4onnx.onnx_network_extraction:\n\nextraction(\n    input_op_names: List[str],\n    output_op_names: List[str],\n    input_onnx_file_path: Union[str, NoneType] = '',\n    onnx_graph: Union[onnx.onnx_ml_pb2.ModelProto, NoneType] = None,\n    output_onnx_file_path: Union[str, NoneType] = '',\n    non_verbose: Optional[bool] = False\n) -\u003e onnx.onnx_ml_pb2.ModelProto\n\n    Parameters\n    ----------\n    input_op_names: List[str]\n        List of OP names to specify for the input layer of the model.\n        e.g. ['aaa','bbb','ccc']\n\n    output_op_names: List[str]\n        List of OP names to specify for the output layer of the model.\n        e.g. ['ddd','eee','fff']\n\n    input_onnx_file_path: Optional[str]\n        Input onnx file path.\n        Either input_onnx_file_path or onnx_graph must be specified.\n        onnx_graph If specified, ignore input_onnx_file_path and process onnx_graph.\n\n    onnx_graph: Optional[onnx.ModelProto]\n        onnx.ModelProto.\n        Either input_onnx_file_path or onnx_graph must be specified.\n        onnx_graph If specified, ignore input_onnx_file_path and process onnx_graph.\n\n    output_onnx_file_path: Optional[str]\n        Output onnx file path.\n        If not specified, .onnx is not output.\n        Default: ''\n\n    non_verbose: Optional[bool]\n        Do not show all information logs. Only error logs are displayed.\n        Default: False\n\n    Returns\n    -------\n    extracted_graph: onnx.ModelProto\n        Extracted onnx ModelProto\n```\n\n## 4. CLI Execution\n```bash\n$ sne4onnx \\\n--input_onnx_file_path input.onnx \\\n--input_op_names aaa bbb ccc \\\n--output_op_names ddd eee fff \\\n--output_onnx_file_path output.onnx\n```\n\n## 5. In-script Execution\n### 5-1. Use ONNX files\n```python\nfrom sne4onnx import extraction\n\nextracted_graph = extraction(\n  input_op_names=['aaa','bbb','ccc'],\n  output_op_names=['ddd','eee','fff'],\n  input_onnx_file_path='input.onnx',\n  output_onnx_file_path='output.onnx',\n)\n```\n### 5-2. Use onnx.ModelProto\n```python\nfrom sne4onnx import extraction\n\nextracted_graph = extraction(\n  input_op_names=['aaa','bbb','ccc'],\n  output_op_names=['ddd','eee','fff'],\n  onnx_graph=graph,\n  output_onnx_file_path='output.onnx',\n)\n```\n\n## 6. Samples\n### 6-1. Pre-extraction\n![image](https://user-images.githubusercontent.com/33194443/162101010-13662cb6-a93b-4ebb-ad46-96da055a56a4.png)\n![image](https://user-images.githubusercontent.com/33194443/162100392-71d58154-ea75-4a39-88a5-930a6e7a5d6a.png)\n![image](https://user-images.githubusercontent.com/33194443/162100741-89e5cf0e-de21-469c-a060-1a05a3a2ce1b.png)\n\n### 6-2.  Extraction\n```bash\n$ sne4onnx \\\n--input_onnx_file_path hitnet_sf_finalpass_720x1280.onnx \\\n--input_op_names 0 1 \\\n--output_op_names 497 785 \\\n--output_onnx_file_path hitnet_sf_finalpass_720x960_head.onnx\n```\n\n### 6-3. Extracted\n![image](https://user-images.githubusercontent.com/33194443/162101435-a9e1209b-8b87-4c85-b66e-517e26aab9ba.png)\n![image](https://user-images.githubusercontent.com/33194443/162101596-ba0cd103-3daa-4a2b-98d4-cf4d72074f64.png)\n![image](https://user-images.githubusercontent.com/33194443/162101783-45e0fde7-2d9a-4625-a0f8-95efa7f79473.png)\n\n## 7. Reference\n1. https://github.com/onnx/onnx/blob/main/docs/PythonAPIOverview.md\n2. https://docs.nvidia.com/deeplearning/tensorrt/onnx-graphsurgeon/docs/index.html\n3. https://github.com/NVIDIA/TensorRT/tree/main/tools/onnx-graphsurgeon\n4. https://github.com/PINTO0309/snd4onnx\n5. https://github.com/PINTO0309/scs4onnx\n6. https://github.com/PINTO0309/snc4onnx\n7. https://github.com/PINTO0309/sog4onnx\n8. https://github.com/PINTO0309/PINTO_model_zoo\n\n## 8. Issues\nhttps://github.com/PINTO0309/simple-onnx-processing-tools/issues\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinto0309%2Fsne4onnx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpinto0309%2Fsne4onnx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinto0309%2Fsne4onnx/lists"}