{"id":15674929,"url":"https://github.com/pinto0309/sio4onnx","last_synced_at":"2025-05-06T22:08:50.972Z","repository":{"id":44925270,"uuid":"513109028","full_name":"PINTO0309/sio4onnx","owner":"PINTO0309","description":"Simple tool to change the INPUT and OUTPUT shape of ONNX.","archived":false,"fork":false,"pushed_at":"2025-04-01T15:09:37.000Z","size":31,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-06T22:08:39.403Z","etag":null,"topics":["cli","model-converter","models","onnx","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PINTO0309.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-12T11:07:34.000Z","updated_at":"2025-04-02T01:58:56.000Z","dependencies_parsed_at":"2022-08-04T01:15:11.432Z","dependency_job_id":null,"html_url":"https://github.com/PINTO0309/sio4onnx","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Fsio4onnx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Fsio4onnx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Fsio4onnx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2Fsio4onnx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PINTO0309","download_url":"https://codeload.github.com/PINTO0309/sio4onnx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252776581,"owners_count":21802468,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","model-converter","models","onnx","python"],"created_at":"2024-10-03T15:53:13.556Z","updated_at":"2025-05-06T22:08:50.950Z","avatar_url":"https://github.com/PINTO0309.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sio4onnx\nSimple tool to change the INPUT and OUTPUT shape of ONNX.\n\nhttps://github.com/PINTO0309/simple-onnx-processing-tools\n\n[![Downloads](https://static.pepy.tech/personalized-badge/sio4onnx?period=total\u0026units=none\u0026left_color=grey\u0026right_color=brightgreen\u0026left_text=Downloads)](https://pepy.tech/project/sio4onnx) ![GitHub](https://img.shields.io/github/license/PINTO0309/sio4onnx?color=2BAF2B) [![PyPI](https://img.shields.io/pypi/v/sio4onnx?color=2BAF2B)](https://pypi.org/project/sio4onnx/) [![CodeQL](https://github.com/PINTO0309/sio4onnx/workflows/CodeQL/badge.svg)](https://github.com/PINTO0309/sio4onnx/actions?query=workflow%3ACodeQL)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/33194443/178511831-14c1e72c-7816-47ea-9c13-27426066cd51.png\" /\u003e\n\u003c/p\u003e\n\n## 1. Setup\n### 1-1. HostPC\n```bash\n### option\n$ echo export PATH=\"~/.local/bin:$PATH\" \u003e\u003e ~/.bashrc \\\n\u0026\u0026 source ~/.bashrc\n\n### run\n$ pip install -U onnx \\\n\u0026\u0026 pip install -U sio4onnx\n```\n### 1-2. Docker\nhttps://github.com/PINTO0309/simple-onnx-processing-tools#docker\n\n## 2. CLI Usage\n```bash\n$ sio4onnx -h\n\nusage:\n    sio4onnx [-h]\n    -if INPUT_ONNX_FILE_PATH\n    -of OUTPUT_ONNX_FILE_PATH\n    -i INPUT_NAMES\n    -is INPUT_SHAPES [INPUT_SHAPES ...]\n    -o OUTPUT_NAMES\n    -os OUTPUT_SHAPES [OUTPUT_SHAPES ...]\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  -of OUTPUT_ONNX_FILE_PATH, --output_onnx_file_path OUTPUT_ONNX_FILE_PATH\n        OUTPUT ONNX file path\n\n  -i INPUT_NAMES, --input_names INPUT_NAMES\n        List of input OP names. All input OPs of the model must be specified.\n        The order is unspecified, but must match the order specified for input_shapes.\n        e.g.\n        --input_names \"input.A\" \\\n        --input_names \"input.B\" \\\n        --input_names \"input.C\"\n\n  -is INPUT_SHAPES [INPUT_SHAPES ...], --input_shapes INPUT_SHAPES [INPUT_SHAPES ...]\n        List of input OP shapes. All input OPs of the model must be specified.\n        The order is unspecified, but must match the order specified for input_names.\n        e.g.\n        --input_shapes 1 3 \"H\" \"W\" \\\n        --input_shapes \"N\" 3 \"H\" \"W\" \\\n        --input_shapes \"-1\" 3 480 640\n\n  -o OUTPUT_NAMES, --output_names OUTPUT_NAMES\n        List of output OP names. All output OPs of the model must be specified.\n        The order is unspecified, but must match the order specified for output_shapes.\n        e.g.\n        --output_names \"output.a\" \\\n        --output_names \"output.b\" \\\n        --output_names \"output.c\"\n\n  -os OUTPUT_SHAPES [OUTPUT_SHAPES ...], --output_shapes OUTPUT_SHAPES [OUTPUT_SHAPES ...]\n        List of input OP shapes. All output OPs of the model must be specified.\n        The order is unspecified, but must match the order specified for output_shapes.\n        e.g.\n        --output_shapes 1 3 \"H\" \"W\" \\\n        --output_shapes \"N\", 3, \"H\", \"W\" \\\n        --output_shapes \"-1\" 3 480 640\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\u003e\u003e\u003e from sio4onnx import io_change\n\u003e\u003e\u003e help(io_change)\n\nHelp on function io_change in module sio4onnx.onnx_input_output_variable_changer:\n\nio_change(\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    input_names: Union[List[str], NoneType] = [],\n    input_shapes: Union[List[Union[int, str]], NoneType] = [],\n    output_names: Union[List[str], NoneType] = [],\n    output_shapes: Union[List[Union[int, str]], NoneType] = [],\n    non_verbose: Union[bool, NoneType] = False,\n) -\u003e onnx.onnx_ml_pb2.ModelProto\n\n    Parameters\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    input_names: Optional[List[str]]\n        List of input OP names. All input OPs of the model must be specified.\n        The order is unspecified, but must match the order specified for input_shapes.\n        e.g. ['input.A', 'input.B', 'input.C']\n\n    input_shapes: Optional[List[Union[int, str]]]\n        List of input OP shapes. All input OPs of the model must be specified.\n        The order is unspecified, but must match the order specified for input_names.\n        e.g.\n        [\n            [1, 3, 'H', 'W'],\n            ['N', 3, 'H', 'W'],\n            ['-1', 3, 480, 640],\n        ]\n\n    output_names: Optional[List[str]]\n        List of output OP names. All output OPs of the model must be specified.\n        The order is unspecified, but must match the order specified for output_shapes.\n        e.g. ['output.a', 'output.b', 'output.c']\n\n    output_shapes: Optional[List[Union[int, str]]]\n        List of input OP shapes. All output OPs of the model must be specified.\n        The order is unspecified, but must match the order specified for output_shapes.\n        e.g.\n        [\n            [1, 3, 'H', 'W'],\n            ['N', 3, 'H', 'W'],\n            ['-1', 3, 480, 640],\n        ]\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    io_changed_graph: onnx.ModelProto\n        onnx ModelProto with modified INPUT and OUTPUT shapes.\n```\n\n## 4. CLI Execution\n```bash\n$ sio4onnx \\\n--input_onnx_file_path yolov3-10.onnx \\\n--output_onnx_file_path yolov3-10_upd.onnx \\\n--input_names \"input_1\" \\\n--input_names \"image_shape\" \\\n--input_shapes \"batch\" 3 \"H\" \"W\" \\\n--input_shapes \"batch\" 2 \\\n--output_names \"yolonms_layer_1/ExpandDims_1:0\" \\\n--output_names \"yolonms_layer_1/ExpandDims_3:0\" \\\n--output_names \"yolonms_layer_1/concat_2:0\" \\\n--output_shapes 1 \"boxes\" 4 \\\n--output_shapes 1 \"classes\" \"boxes\" \\\n--output_shapes \"boxes\" 3\n```\n\n## 5. In-script Execution\n```python\nfrom sio4onnx import io_change\n\nio_changed_graph = io_change(\n    input_onnx_file_path=\"yolov3-10.onnx\",\n    output_onnx_file_path=\"yolov3-10_upd.onnx\",\n    input_names=[\n        \"input_1\",\n        \"image_shape\",\n    ],\n    input_shapes=[\n        [\"batch\", 3, \"H\", \"W\"],\n        [\"batch\", 2],\n    ],\n    output_names=[\n        \"yolonms_layer_1/ExpandDims_1:0\",\n        \"yolonms_layer_1/ExpandDims_3:0\",\n        \"yolonms_layer_1/concat_2:0\",\n    ],\n    output_shapes=[\n        [1, \"boxes\", 4],\n        [1, \"classes\", \"boxes\"],\n        [\"boxes\", 3],\n    ],\n)\n```\n## 6. Sample\n### Before\n![image](https://user-images.githubusercontent.com/33194443/178515405-42d2bd01-f5fa-41be-95e3-3a229b0c8ae9.png)\n### After\n![image](https://user-images.githubusercontent.com/33194443/178515314-ecbf7f85-5c1d-4626-ac8b-3558432f6e9b.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinto0309%2Fsio4onnx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpinto0309%2Fsio4onnx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinto0309%2Fsio4onnx/lists"}