# sor4onnx
**S**imple **O**P **R**enamer for **ONNX**.
https://github.com/PINTO0309/simple-onnx-processing-tools
[![Downloads](https://static.pepy.tech/personalized-badge/sor4onnx?period=total&units=none&left_color=grey&right_color=brightgreen&left_text=Downloads)](https://pepy.tech/project/sor4onnx) ![GitHub](https://img.shields.io/github/license/PINTO0309/sor4onnx?color=2BAF2B) [![PyPI](https://img.shields.io/pypi/v/sor4onnx?color=2BAF2B)](https://pypi.org/project/sor4onnx/) [![CodeQL](https://github.com/PINTO0309/sor4onnx/workflows/CodeQL/badge.svg)](https://github.com/PINTO0309/sor4onnx/actions?query=workflow%3ACodeQL)
<p align="center">
<img src="https://user-images.githubusercontent.com/33194443/170158065-9a81787b-86ad-4971-857d-5f4185dfcf0b.png" />
</p>
# Key concept
- [x] Performs a partial match search on the specified string and replaces all input and output names with the specified string.
## 1. Setup
### 1-1. HostPC
```bash
### option
$ echo export PATH="~/.local/bin:$PATH" >> ~/.bashrc \
&& source ~/.bashrc
### run
$ pip install -U onnx \
&& python3 -m pip install -U onnx_graphsurgeon --index-url https://pypi.ngc.nvidia.com \
&& pip install -U sor4onnx
```
### 1-2. Docker
https://github.com/PINTO0309/simple-onnx-processing-tools#docker
## 2. CLI Usage
```
$ sor4onnx -h
usage:
sor4onnx [-h]
-if INPUT_ONNX_FILE_PATH
-on OLD_NEW OLD_NEW
-of OUTPUT_ONNX_FILE_PATH
[-m {full,inputs,outputs}]
[-sm {exact_match,partial_match,prefix_match,suffix_match}]
[-n]
optional arguments:
-h, --help
show this help message and exit.
-if INPUT_ONNX_FILE_PATH, --input_onnx_file_path INPUT_ONNX_FILE_PATH
Input onnx file path.
-on OLD_NEW OLD_NEW, --old_new OLD_NEW OLD_NEW
All occurrences of substring old replaced by new.
e.g. --old_new "onnx::" ""
-of OUTPUT_ONNX_FILE_PATH, --output_onnx_file_path OUTPUT_ONNX_FILE_PATH
Output onnx file path.
-m {full,inputs,outputs}, --mode {full,inputs,outputs}
Specifies the type of node to be replaced.
full or inputs or outputs.
full: Rename all nodes.
inputs: Rename only the input node.
outputs: Rename only the output node.
Default: full
-sm {exact_match,partial_match,prefix_match,suffix_match}, --search_mode {exact_match,partial_match,prefix_match,suffix_match}
OP name search mode.
exact_match or partial_match or prefix_match or suffix_match.
exact_match: Exact match search for OP name.
partial_match: Partial match search for OP name.
prefix_match: Prefix match search for OP name.
suffix_match: Suffix match search for OP name.
Default: exact_match
-n, --non_verbose
Do not show all information logs. Only error logs are displayed.
```
## 3. In-script Usage
```python
>>> from sor4onnx import rename
>>> help(rename)
Help on function rename in module sor4onnx.onnx_opname_renamer:
rename(
old_new: List[str],
input_onnx_file_path: Union[str, NoneType] = '',
onnx_graph: Union[onnx.onnx_ml_pb2.ModelProto, NoneType] = None,
output_onnx_file_path: Union[str, NoneType] = '',
mode: Union[str, NoneType] = 'full',
search_mode: Union[str, NoneType] = 'exact_match',
non_verbose: Union[bool, NoneType] = False
) -> onnx.onnx_ml_pb2.ModelProto
Parameters
----------
old_new: List[str]
All occurrences of substring old replaced by new.
e.g.
old_new = ["onnx::", ""]
input_onnx_file_path: Optional[str]
Input onnx file path.
Either input_onnx_file_path or onnx_graph must be specified.
Default: ''
onnx_graph: Optional[onnx.ModelProto]
onnx.ModelProto.
Either input_onnx_file_path or onnx_graph must be specified.
onnx_graph If specified, ignore input_onnx_file_path and process onnx_graph.
output_onnx_file_path: Optional[str]
Output onnx file path. If not specified, no ONNX file is output.
Default: ''
mode: Optional[str]
Specifies the type of node to be replaced.
full or inputs or outputs.
full: Rename all nodes.
inputs: Rename only the input node.
outputs: Rename only the output node.
Default: full
search_mode: Optional[str]
OP name search mode.
exact_match or partial_match or prefix_match or suffix_match.
exact_match: Exact match search for OP name.
partial_match: Partial match search for OP name.
prefix_match: Prefix match search for OP name.
suffix_match: Suffix match search for OP name.
Default: exact_match
non_verbose: Optional[bool]
Do not show all information logs. Only error logs are displayed.
Default: False
Returns
-------
renamed_graph: onnx.ModelProto
Renamed onnx ModelProto.
```
## 4. CLI Execution
```bash
$ sor4onnx \
--input_onnx_file_path fusionnet_180x320.onnx \
--old_new "onnx::" "" \
--mode full \
--search_mode prefix_match \
--output_onnx_file_path fusionnet_180x320_renamed.onnx
```
## 5. In-script Execution
```python
from sor4onnx import rename
onnx_graph = rename(
old_new=["onnx::", ""],
input_onnx_file_path="fusionnet_180x320.onnx",
output_onnx_file_path="fusionnet_180x320_renamed.onnx",
mode="full",
search_mode="prefix_match",
)
# or
onnx_graph = rename(
old_new=["onnx::", ""],
onnx_graph=graph,
mode="full",
search_mode="prefix_match",
)
```
## 6. Sample
### Before
![image](https://user-images.githubusercontent.com/33194443/166736425-54b19eab-b025-441c-a1ce-79c075a9b26f.png)
### After
![image](https://user-images.githubusercontent.com/33194443/166736670-a784850b-bec3-4d74-95a4-dd67738ac481.png)
## 7. Reference
1. https://github.com/onnx/onnx/blob/main/docs/Operators.md
2. https://docs.nvidia.com/deeplearning/tensorrt/onnx-graphsurgeon/docs/index.html
3. https://github.com/NVIDIA/TensorRT/tree/main/tools/onnx-graphsurgeon
4. https://github.com/PINTO0309/simple-onnx-processing-tools
5. https://github.com/PINTO0309/PINTO_model_zoo
## 8. Issues
https://github.com/PINTO0309/simple-onnx-processing-tools/issues
Raw data
{
"_id": null,
"home_page": "https://github.com/PINTO0309/sor4onnx",
"name": "sor4onnx",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": "Katsuya Hyodo",
"author_email": "rmsdh122@yahoo.co.jp",
"download_url": "https://files.pythonhosted.org/packages/e3/f5/e904a7bfd1a36f9cabd8e09a04159ea81b216b8e3cea549bc9e5147b4686/sor4onnx-1.0.6.tar.gz",
"platform": "linux",
"description": "# sor4onnx\n**S**imple **O**P **R**enamer for **ONNX**.\n\nhttps://github.com/PINTO0309/simple-onnx-processing-tools\n\n[![Downloads](https://static.pepy.tech/personalized-badge/sor4onnx?period=total&units=none&left_color=grey&right_color=brightgreen&left_text=Downloads)](https://pepy.tech/project/sor4onnx) ![GitHub](https://img.shields.io/github/license/PINTO0309/sor4onnx?color=2BAF2B) [![PyPI](https://img.shields.io/pypi/v/sor4onnx?color=2BAF2B)](https://pypi.org/project/sor4onnx/) [![CodeQL](https://github.com/PINTO0309/sor4onnx/workflows/CodeQL/badge.svg)](https://github.com/PINTO0309/sor4onnx/actions?query=workflow%3ACodeQL)\n\n<p align=\"center\">\n <img src=\"https://user-images.githubusercontent.com/33194443/170158065-9a81787b-86ad-4971-857d-5f4185dfcf0b.png\" />\n</p>\n\n# Key concept\n\n\n- [x] Performs a partial match search on the specified string and replaces all input and output names with the specified string.\n\n## 1. Setup\n### 1-1. HostPC\n```bash\n### option\n$ echo export PATH=\"~/.local/bin:$PATH\" >> ~/.bashrc \\\n&& source ~/.bashrc\n\n### run\n$ pip install -U onnx \\\n&& python3 -m pip install -U onnx_graphsurgeon --index-url https://pypi.ngc.nvidia.com \\\n&& pip install -U sor4onnx\n```\n### 1-2. Docker\nhttps://github.com/PINTO0309/simple-onnx-processing-tools#docker\n\n## 2. CLI Usage\n```\n$ sor4onnx -h\n\nusage:\n sor4onnx [-h]\n -if INPUT_ONNX_FILE_PATH\n -on OLD_NEW OLD_NEW\n -of OUTPUT_ONNX_FILE_PATH\n [-m {full,inputs,outputs}]\n [-sm {exact_match,partial_match,prefix_match,suffix_match}]\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 -on OLD_NEW OLD_NEW, --old_new OLD_NEW OLD_NEW\n All occurrences of substring old replaced by new.\n e.g. --old_new \"onnx::\" \"\"\n\n -of OUTPUT_ONNX_FILE_PATH, --output_onnx_file_path OUTPUT_ONNX_FILE_PATH\n Output onnx file path.\n\n -m {full,inputs,outputs}, --mode {full,inputs,outputs}\n Specifies the type of node to be replaced.\n full or inputs or outputs.\n full: Rename all nodes.\n inputs: Rename only the input node.\n outputs: Rename only the output node.\n Default: full\n\n -sm {exact_match,partial_match,prefix_match,suffix_match}, --search_mode {exact_match,partial_match,prefix_match,suffix_match}\n OP name search mode.\n exact_match or partial_match or prefix_match or suffix_match.\n exact_match: Exact match search for OP name.\n partial_match: Partial match search for OP name.\n prefix_match: Prefix match search for OP name.\n suffix_match: Suffix match search for OP name.\n Default: exact_match\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```python\n>>> from sor4onnx import rename\n>>> help(rename)\n\nHelp on function rename in module sor4onnx.onnx_opname_renamer:\n\nrename(\n old_new: 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 mode: Union[str, NoneType] = 'full',\n search_mode: Union[str, NoneType] = 'exact_match',\n non_verbose: Union[bool, NoneType] = False\n) -> onnx.onnx_ml_pb2.ModelProto\n\n Parameters\n ----------\n old_new: List[str]\n All occurrences of substring old replaced by new.\n e.g.\n old_new = [\"onnx::\", \"\"]\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 Default: ''\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. If not specified, no ONNX file is output.\n Default: ''\n\n mode: Optional[str]\n Specifies the type of node to be replaced.\n full or inputs or outputs.\n full: Rename all nodes.\n inputs: Rename only the input node.\n outputs: Rename only the output node.\n Default: full\n\n search_mode: Optional[str]\n OP name search mode.\n exact_match or partial_match or prefix_match or suffix_match.\n exact_match: Exact match search for OP name.\n partial_match: Partial match search for OP name.\n prefix_match: Prefix match search for OP name.\n suffix_match: Suffix match search for OP name.\n Default: exact_match\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 renamed_graph: onnx.ModelProto\n Renamed onnx ModelProto.\n```\n\n## 4. CLI Execution\n```bash\n$ sor4onnx \\\n--input_onnx_file_path fusionnet_180x320.onnx \\\n--old_new \"onnx::\" \"\" \\\n--mode full \\\n--search_mode prefix_match \\\n--output_onnx_file_path fusionnet_180x320_renamed.onnx\n```\n\n## 5. In-script Execution\n```python\nfrom sor4onnx import rename\n\nonnx_graph = rename(\n old_new=[\"onnx::\", \"\"],\n input_onnx_file_path=\"fusionnet_180x320.onnx\",\n output_onnx_file_path=\"fusionnet_180x320_renamed.onnx\",\n mode=\"full\",\n search_mode=\"prefix_match\",\n)\n\n# or\n\nonnx_graph = rename(\n old_new=[\"onnx::\", \"\"],\n onnx_graph=graph,\n mode=\"full\",\n search_mode=\"prefix_match\",\n)\n```\n\n## 6. Sample\n### Before\n![image](https://user-images.githubusercontent.com/33194443/166736425-54b19eab-b025-441c-a1ce-79c075a9b26f.png)\n\n### After\n![image](https://user-images.githubusercontent.com/33194443/166736670-a784850b-bec3-4d74-95a4-dd67738ac481.png)\n\n## 7. Reference\n1. https://github.com/onnx/onnx/blob/main/docs/Operators.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/simple-onnx-processing-tools\n5. https://github.com/PINTO0309/PINTO_model_zoo\n\n## 8. Issues\nhttps://github.com/PINTO0309/simple-onnx-processing-tools/issues\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Simple OP Renamer for ONNX.",
"version": "1.0.6",
"project_urls": {
"Homepage": "https://github.com/PINTO0309/sor4onnx"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "be126821c9b633ffbc1329a9edb4555a7b19623f7d194c60d012b80b45081695",
"md5": "69ce07865fe5a317009b3a5a4f770ed9",
"sha256": "38dd704a1733ddcebe22400dfa6fcba76a5cda2776f881689cbe02dc0d1ad979"
},
"downloads": -1,
"filename": "sor4onnx-1.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "69ce07865fe5a317009b3a5a4f770ed9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 7217,
"upload_time": "2024-04-30T06:35:08",
"upload_time_iso_8601": "2024-04-30T06:35:08.203824Z",
"url": "https://files.pythonhosted.org/packages/be/12/6821c9b633ffbc1329a9edb4555a7b19623f7d194c60d012b80b45081695/sor4onnx-1.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e3f5e904a7bfd1a36f9cabd8e09a04159ea81b216b8e3cea549bc9e5147b4686",
"md5": "c2205f6b0bdd9c3bca181f53f2c154d1",
"sha256": "c46423e343ad218831b7227e67dc83f23cd1534ae69e177945db2f0cc1606cf4"
},
"downloads": -1,
"filename": "sor4onnx-1.0.6.tar.gz",
"has_sig": false,
"md5_digest": "c2205f6b0bdd9c3bca181f53f2c154d1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 7729,
"upload_time": "2024-04-30T06:35:09",
"upload_time_iso_8601": "2024-04-30T06:35:09.623335Z",
"url": "https://files.pythonhosted.org/packages/e3/f5/e904a7bfd1a36f9cabd8e09a04159ea81b216b8e3cea549bc9e5147b4686/sor4onnx-1.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-30 06:35:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "PINTO0309",
"github_project": "sor4onnx",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "sor4onnx"
}