sor4onnx
Simple OP Renamer for ONNX.
https://github.com/PINTO0309/simple-onnx-processing-tools
Key concept
- 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
### 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
>>> 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
$ 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
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
- https://github.com/onnx/onnx/blob/main/docs/Operators.md
- https://docs.nvidia.com/deeplearning/tensorrt/onnx-graphsurgeon/docs/index.html
- https://github.com/NVIDIA/TensorRT/tree/main/tools/onnx-graphsurgeon
- https://github.com/PINTO0309/simple-onnx-processing-tools
- https://github.com/PINTO0309/PINTO_model_zoo
8. Issues
https://github.com/PINTO0309/simple-onnx-processing-tools/issues
Metadata
Release files for sor4onnx 1.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sor4onnx-1.0.7.tar.gz | 7.8 kB | Without provenance | Details for sor4onnx-1.0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sor4onnx-1.0.7-py3-none-any.whl | Python 3 | none | any | Details for sor4onnx-1.0.7-py3-none-any.whl |
Total release size: 15.1 kB
Release files / sor4onnx-1.0.7.tar.gz
| Download URL | sor4onnx-1.0.7.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a3e91e91da0b11aec86bce96a3f28f9f52ab000421b59a2ae689c10fef782be
|
|
BLAKE2b-256 checksum How to use checksums |
4d8ad930f6215383d530f042022f8cabb96d8e5b32c134a6f32baeafab96efbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|
Release files / sor4onnx-1.0.7-py3-none-any.whl
| Download URL | sor4onnx-1.0.7-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aca7a9b71bf0319415141332ccbd0c01fb8f7feb485e66a2342dda2104fd3e95
|
|
BLAKE2b-256 checksum How to use checksums |
f1c42091efd5236c0a9f755f6de4dfec1985cb2dfd270f92237486c521815778
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|
Security for sor4onnx 1.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.