Simple OP Renamer for ONNX.
Project description
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]
--input_onnx_file_path INPUT_ONNX_FILE_PATH
--old_new OLD_NEW OLD_NEW
--output_onnx_file_path OUTPUT_ONNX_FILE_PATH
[--mode {full,inputs,outputs}]
[--non_verbose]
optional arguments:
-h, --help
show this help message and exit.
--input_onnx_file_path INPUT_ONNX_FILE_PATH
Input onnx file path.
--old_new OLD_NEW OLD_NEW
All occurrences of substring old replaced by new.
e.g. --old_new "onnx::" ""
--output_onnx_file_path OUTPUT_ONNX_FILE_PATH
Output onnx file path.
--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
--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',
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
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::" "" \
--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",
)
# or
onnx_graph = rename(
old_new=["onnx::", ""],
onnx_graph=graph,
)
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sor4onnx-1.0.2.tar.gz
(5.5 kB
view details)
Built Distribution
File details
Details for the file sor4onnx-1.0.2.tar.gz
.
File metadata
- Download URL: sor4onnx-1.0.2.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d5eaf38f21ba77817fd19189ec2769cfa28b65838ceb92f0106c7d213318e49 |
|
MD5 | 9e2652eda9ef8fac9c8a0936e1d356ed |
|
BLAKE2b-256 | 54f3ec36e56270d62a3dfb396d508fae84405c30f74c093eb92b4bc4367b6ba4 |
File details
Details for the file sor4onnx-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: sor4onnx-1.0.2-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 348962e0b273f7357bc86be012e4c7256edcca394ab675d8b128dd5de79b3e6f |
|
MD5 | 54aea8e754d6f5a6b31d859fe3e5366a |
|
BLAKE2b-256 | 4aa7b4b41a994901a39728c962da3ef123749fa0ef3e92e9dfa9865d36954ed8 |