# sor4onnx
**S**imple **O**P **R**enamer for **ONNX**.
https://github.com/PINTO0309/simple-onnx-processing-tools
[](https://pepy.tech/project/sor4onnx)  [](https://pypi.org/project/sor4onnx/) [](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

### After

## 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/4d/8a/d930f6215383d530f042022f8cabb96d8e5b32c134a6f32baeafab96efbd/sor4onnx-1.0.7.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[](https://pepy.tech/project/sor4onnx)  [](https://pypi.org/project/sor4onnx/) [](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\n\n### After\n\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.7",
"project_urls": {
"Homepage": "https://github.com/PINTO0309/sor4onnx"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f1c42091efd5236c0a9f755f6de4dfec1985cb2dfd270f92237486c521815778",
"md5": "bf2fafa3102ed32047403f0d5adc09d1",
"sha256": "aca7a9b71bf0319415141332ccbd0c01fb8f7feb485e66a2342dda2104fd3e95"
},
"downloads": -1,
"filename": "sor4onnx-1.0.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bf2fafa3102ed32047403f0d5adc09d1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 7290,
"upload_time": "2024-05-28T23:38:57",
"upload_time_iso_8601": "2024-05-28T23:38:57.646035Z",
"url": "https://files.pythonhosted.org/packages/f1/c4/2091efd5236c0a9f755f6de4dfec1985cb2dfd270f92237486c521815778/sor4onnx-1.0.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4d8ad930f6215383d530f042022f8cabb96d8e5b32c134a6f32baeafab96efbd",
"md5": "efa3108f4b3d541616fe297b5b7d2b9b",
"sha256": "6a3e91e91da0b11aec86bce96a3f28f9f52ab000421b59a2ae689c10fef782be"
},
"downloads": -1,
"filename": "sor4onnx-1.0.7.tar.gz",
"has_sig": false,
"md5_digest": "efa3108f4b3d541616fe297b5b7d2b9b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 7801,
"upload_time": "2024-05-28T23:38:59",
"upload_time_iso_8601": "2024-05-28T23:38:59.193240Z",
"url": "https://files.pythonhosted.org/packages/4d/8a/d930f6215383d530f042022f8cabb96d8e5b32c134a6f32baeafab96efbd/sor4onnx-1.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-28 23:38:59",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "PINTO0309",
"github_project": "sor4onnx",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "sor4onnx"
}