sio4onnx
Simple tool to change the INPUT and OUTPUT shape of ONNX.
https://github.com/PINTO0309/simple-onnx-processing-tools
1. Setup
1-1. HostPC
### option
$ echo export PATH="~/.local/bin:$PATH" >> ~/.bashrc \
&& source ~/.bashrc
### run
$ pip install -U onnx \
&& pip install -U sio4onnx
1-2. Docker
https://github.com/PINTO0309/simple-onnx-processing-tools#docker
2. CLI Usage
$ sio4onnx -h
usage:
sio4onnx [-h]
-if INPUT_ONNX_FILE_PATH
-of OUTPUT_ONNX_FILE_PATH
-i INPUT_NAMES
-is INPUT_SHAPES [INPUT_SHAPES ...]
-o OUTPUT_NAMES
-os OUTPUT_SHAPES [OUTPUT_SHAPES ...]
[-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
-of OUTPUT_ONNX_FILE_PATH, --output_onnx_file_path OUTPUT_ONNX_FILE_PATH
OUTPUT ONNX file path
-i INPUT_NAMES, --input_names INPUT_NAMES
List of input OP names. All input OPs of the model must be specified.
The order is unspecified, but must match the order specified for input_shapes.
e.g.
--input_names "input.A" \
--input_names "input.B" \
--input_names "input.C"
-is INPUT_SHAPES [INPUT_SHAPES ...], --input_shapes INPUT_SHAPES [INPUT_SHAPES ...]
List of input OP shapes. All input OPs of the model must be specified.
The order is unspecified, but must match the order specified for input_names.
e.g.
--input_shapes 1 3 "H" "W" \
--input_shapes "N" 3 "H" "W" \
--input_shapes "-1" 3 480 640
-o OUTPUT_NAMES, --output_names OUTPUT_NAMES
List of output OP names. All output OPs of the model must be specified.
The order is unspecified, but must match the order specified for output_shapes.
e.g.
--output_names "output.a" \
--output_names "output.b" \
--output_names "output.c"
-os OUTPUT_SHAPES [OUTPUT_SHAPES ...], --output_shapes OUTPUT_SHAPES [OUTPUT_SHAPES ...]
List of input OP shapes. All output OPs of the model must be specified.
The order is unspecified, but must match the order specified for output_shapes.
e.g.
--output_shapes 1 3 "H" "W" \
--output_shapes "N", 3, "H", "W" \
--output_shapes "-1" 3 480 640
-n, --non_verbose
Do not show all information logs. Only error logs are displayed.
3. In-script Usage
>>> from sio4onnx import io_change
>>> help(io_change)
Help on function io_change in module sio4onnx.onnx_input_output_variable_changer:
io_change(
input_onnx_file_path: Union[str, NoneType] = '',
onnx_graph: Union[onnx.onnx_ml_pb2.ModelProto, NoneType] = None,
output_onnx_file_path: Union[str, NoneType] = '',
input_names: Union[List[str], NoneType] = [],
input_shapes: Union[List[Union[int, str]], NoneType] = [],
output_names: Union[List[str], NoneType] = [],
output_shapes: Union[List[Union[int, str]], NoneType] = [],
non_verbose: Union[bool, NoneType] = False,
) -> onnx.onnx_ml_pb2.ModelProto
Parameters
----------
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: ''
input_names: Optional[List[str]]
List of input OP names. All input OPs of the model must be specified.
The order is unspecified, but must match the order specified for input_shapes.
e.g. ['input.A', 'input.B', 'input.C']
input_shapes: Optional[List[Union[int, str]]]
List of input OP shapes. All input OPs of the model must be specified.
The order is unspecified, but must match the order specified for input_names.
e.g.
[
[1, 3, 'H', 'W'],
['N', 3, 'H', 'W'],
['-1', 3, 480, 640],
]
output_names: Optional[List[str]]
List of output OP names. All output OPs of the model must be specified.
The order is unspecified, but must match the order specified for output_shapes.
e.g. ['output.a', 'output.b', 'output.c']
output_shapes: Optional[List[Union[int, str]]]
List of input OP shapes. All output OPs of the model must be specified.
The order is unspecified, but must match the order specified for output_shapes.
e.g.
[
[1, 3, 'H', 'W'],
['N', 3, 'H', 'W'],
['-1', 3, 480, 640],
]
non_verbose: Optional[bool]
Do not show all information logs. Only error logs are displayed.
Default: False
Returns
-------
io_changed_graph: onnx.ModelProto
onnx ModelProto with modified INPUT and OUTPUT shapes.
4. CLI Execution
$ sio4onnx \
--input_onnx_file_path yolov3-10.onnx \
--output_onnx_file_path yolov3-10_upd.onnx \
--input_names "input_1" \
--input_names "image_shape" \
--input_shapes "batch" 3 "H" "W" \
--input_shapes "batch" 2 \
--output_names "yolonms_layer_1/ExpandDims_1:0" \
--output_names "yolonms_layer_1/ExpandDims_3:0" \
--output_names "yolonms_layer_1/concat_2:0" \
--output_shapes 1 "boxes" 4 \
--output_shapes 1 "classes" "boxes" \
--output_shapes "boxes" 3
5. In-script Execution
from sio4onnx import io_change
io_changed_graph = io_change(
input_onnx_file_path="yolov3-10.onnx",
output_onnx_file_path="yolov3-10_upd.onnx",
input_names=[
"input_1",
"image_shape",
],
input_shapes=[
["batch", 3, "H", "W"],
["batch", 2],
],
output_names=[
"yolonms_layer_1/ExpandDims_1:0",
"yolonms_layer_1/ExpandDims_3:0",
"yolonms_layer_1/concat_2:0",
],
output_shapes=[
[1, "boxes", 4],
[1, "classes", "boxes"],
["boxes", 3],
],
)
6. Sample
Before
After
Metadata
Release files for sio4onnx 1.0.3
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 |
|---|---|---|---|---|
| sio4onnx-1.0.3.tar.gz | 8.5 kB | Without provenance | Details for sio4onnx-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sio4onnx-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for sio4onnx-1.0.3-py3-none-any.whl |
Total release size: 16.5 kB
Release files / sio4onnx-1.0.3.tar.gz
| Download URL | sio4onnx-1.0.3.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9037c76afa96c359eba8d04897dbe943a31e49806c25ab5b785cb0eba7427e05
|
|
BLAKE2b-256 checksum How to use checksums |
9ed78dca6ff4e74304d25314f439053f3d1192f5fd55572267004cc857116bc4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|
Release files / sio4onnx-1.0.3-py3-none-any.whl
| Download URL | sio4onnx-1.0.3-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d90744fb00c4e43b9e9411ab057e407c5b907f2a9cbae50638e6308c7713b75e
|
|
BLAKE2b-256 checksum How to use checksums |
dd9908cfcda4d87cca896dc079ef95586e09081248dea218456752762741ba1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|
Security for sio4onnx 1.0.3
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.