{"id":15650539,"url":"https://github.com/zhenhuaw-me/onnxcli","last_synced_at":"2025-04-23T18:08:36.378Z","repository":{"id":39972651,"uuid":"404241710","full_name":"zhenhuaw-me/onnxcli","owner":"zhenhuaw-me","description":"ONNX Command-Line Toolbox","archived":false,"fork":false,"pushed_at":"2024-10-11T07:10:11.000Z","size":90,"stargazers_count":35,"open_issues_count":8,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-23T18:08:35.531Z","etag":null,"topics":["deep-learning","onnx","python"],"latest_commit_sha":null,"homepage":"https://zhenhuaw.me/onnxcli","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhenhuaw-me.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-08T06:51:10.000Z","updated_at":"2024-01-05T05:54:35.000Z","dependencies_parsed_at":"2024-10-03T12:35:53.652Z","dependency_job_id":"b3d14f9a-3cfa-4a29-bce8-f06f39e4d1cd","html_url":"https://github.com/zhenhuaw-me/onnxcli","commit_stats":{"total_commits":65,"total_committers":5,"mean_commits":13.0,"dds":0.1384615384615384,"last_synced_commit":"0eb2e9fb55f4fd5ea7d37e3b8ef5e0644dbd5b94"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhenhuaw-me%2Fonnxcli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhenhuaw-me%2Fonnxcli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhenhuaw-me%2Fonnxcli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhenhuaw-me%2Fonnxcli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhenhuaw-me","download_url":"https://codeload.github.com/zhenhuaw-me/onnxcli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250487528,"owners_count":21438612,"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":["deep-learning","onnx","python"],"created_at":"2024-10-03T12:35:00.268Z","updated_at":"2025-04-23T18:08:36.346Z","avatar_url":"https://github.com/zhenhuaw-me.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"ONNX Command Line Toolbox\n=========================\n\n[![Build and Test](https://github.com/zhenhuaw-me/onnxcli/workflows/Build%20and%20Test/badge.svg)](https://github.com/zhenhuaw-me/onnxcli/actions/workflows/build.yml)\n[![CodeQL](https://github.com/zhenhuaw-me/onnxcli/workflows/CodeQL/badge.svg)](https://github.com/zhenhuaw-me/onnxcli/actions/workflows/codeql-analysis.yml)\n[![Sanity](https://github.com/zhenhuaw-me/onnxcli/workflows/Sanity/badge.svg)](https://github.com/zhenhuaw-me/onnxcli/actions/workflows/sanity.yml)\n[![Coverage](https://codecov.io/gh/zhenhuaw-me/onnxcli/branch/master/graph/badge.svg)](https://codecov.io/gh/zhenhuaw-me/onnxcli)\n[![Download](https://img.shields.io/pypi/dm/onnxcli)](https://img.shields.io/pypi/dm/onnxcli)\n\n\n* Aim to improve your experience of investigating ONNX models.\n* Use it like `onnx infershape /path/to/input/model.onnx /path/to/output/model.onnx`. (See the [usage section](#usage).)\n\n\n## Installation\n\nRecommand to install via [GitHub repo][github] for the latest functionality.\n```\npip install git+https://github.com/zhenhuaw-me/onnxcli.git\n```\n\n_Two alternative ways are:_\n1. Install via [pypi package][pypi] `pip install onnxcli`\n2. Download and add the code tree to your `$PYTHONPATH`. (For development purpose and the command line is different.）\n    ```\n    git clone https://github.com/zhenhuaw-me/onnxcli.git\n    export PYTHONPATH=$(pwd)/onnxcli:${PYTHONPATH}\n    python onnxcli/cli/dispatcher.py \u003csub command\u003e \u003cmore args...\u003e\n    ```\n\n**Requirements**\n\n`onnxcli` depends on different packages w.r.t. different functionality and may extend.\nHowever, we only include only several basic ones (`onnx` for example) since you may use only a small portion of the functionalities, or you may like have a different version.\n\nDepending on the sub command, error will be raised if the requirements are not met.\nFollow the error message to install the requirements.\n\n\n## Usage\n\nOnce installed, the `onnx` and `onnxcli` commands are avaiable.\nYou can play with commands such as `onnx infershape /path/to/input/model.onnx /path/to/output/model.onnx`.\n\nThe general format is `onnx \u003csub command\u003e \u003cdedicated arguments ...\u003e`.\nThe sub commands are as sections below.\n\n_Check the online help with `onnx --help` and `onnx \u003csubcmd\u003e --help` for latest usage._\n\n### infershape\n\n`onnx infershape` performs [shape inference](https://github.com/onnx/onnx/blob/master/docs/ShapeInference.md) of the ONNX model.\nIt's an CLI wrapper of [`onnx.shape_inference`](https://github.com/onnx/onnx/blob/master/docs/PythonAPIOverview.md#running-shape-inference-on-an-onnx-model).\nYou will find it useful to generate shape information for the models that are extracted by [`onnx extract`](#extract).\n\n### extract\n\n`onnx extract` extracts the sub model that is determined by the names of the input and output tensor of the subgraph from the original model.\nIt's a CLI wrapper of [`onnx.utils.extract_model`](https://github.com/onnx/onnx/blob/master/docs/PythonAPIOverview.md#extracting-sub-model-with-inputs-outputs-tensor-names) (which I authorized in the ONNX repo).\n\n### inspect\n\n`onnx inspect` gives you quick view of the information of the given model.\nIt's inspired by [the tf-onnx tool](https://github.com/onnx/tensorflow-onnx/blob/master/tools/dump-onnx.py).\n\nWhen working on deep learning, you may like to take a look at what's inside the model.\n[Netron](https://github.com/lutzroeder/netron) is powerful but doesn't provide fine-grain view.\n\nWith `onnx inspect`, you no longer need to scroll the Netron window to look for nodes or tensors.\nInstead, you can dump the node attributes and tensor values with a single command.\n\n\u003cdetails\u003e\u003csummary\u003eClick here to see a node example\u003c/summary\u003e\n\u003cpre\u003e\u003ccode\u003e\n$ onnx inspect ./assets/tests/conv.float32.onnx --node --indices 0 --detail\n\nInpect of model ./assets/tests/conv.float32.onnx\n  Graph name: 9\n  Graph inputs: 1\n  Graph outputs: 1\n  Nodes in total: 1\n  ValueInfo in total: 2\n  Initializers in total: 2\n  Sparse Initializers in total: 0\n  Quantization in total: 0\n\nNode information:\n  Node \"output\": type \"Conv\", inputs \"['input', 'Variable/read', 'Conv2D_bias']\", outputs \"['output']\"\n    attributes: [name: \"dilations\"\nints: 1\nints: 1\ntype: INTS\n, name: \"group\"\ni: 1\ntype: INT\n, name: \"kernel_shape\"\nints: 3\nints: 3\ntype: INTS\n, name: \"pads\"\nints: 1\nints: 1\nints: 1\nints: 1\ntype: INTS\n, name: \"strides\"\nints: 1\nints: 1\ntype: INTS\n]\n\u003c/code\u003e\u003c/pre\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eClick here to see a tensor example\u003c/summary\u003e\n\u003cpre\u003e\u003ccode\u003e\n$ onnx inspect ./assets/tests/conv.float32.onnx --tensor --names Conv2D_bias --detail\n\nInpect of model ./assets/tests/conv.float32.onnx\n  Graph name: 9\n  Graph inputs: 1\n  Graph outputs: 1\n  Nodes in total: 1\n  ValueInfo in total: 2\n  Initializers in total: 2\n  Sparse Initializers in total: 0\n  Quantization in total: 0\n\nTensor information:\n  Initializer \"Conv2D_bias\": type FLOAT, shape [16],\n    float data: [0.4517577290534973, -0.014192663133144379, 0.2946248948574066, -0.9742919206619263, -1.2975586652755737, 0.7223454117774963, 0.7835700511932373, 1.7674627304077148, 1.7242872714996338, 1.1230682134628296, -0.2902531623840332, 0.2627834975719452, 1.0175092220306396, 0.5643373131752014, -0.8244842290878296, 1.2169424295425415]\n\u003c/code\u003e\u003c/pre\u003e\n\u003c/details\u003e\n\n### draw\n\n`onnx draw` draws the graph in `dot`, `svg`, `png` formats.\nIt gives you quick view of the type and shape of the tensors that are fed to a specific node.\nYou can view the model topology in image viewer of browser without waiting for the model to load,\nwhich I found is really helpful for large models.\n\nIf you are viewing `svg` in browser, you can even quick search for the nodes and tensors.\nTogether with [`onnx inspect`](#inspect), it will be very efficient to understand the issue you are looking into.\n\nThe node are in ellipses and tensors are in rectangles where the rounded ones are initializers.\nThe node type of the node and the data type and shape of the tenors are also rendered.\nHere is a Convolution node example.\n\n![conv](assets/conv.svg)\n\n**Note**: The [`onnx draw`](#draw) requires [`dot` command (graphviz)](https://graphviz.org/) to be avaiable on your machine - which can be installed by command as below on Ubuntu/Debian.\n```\nsudo apt install -y graphviz\n```\n\n### optimize\n\n`onnx optimize` optimizes the input model with [ONNX Optimizer](https://github.com/onnx/optimizer).\n\n\n## Contributing\n\nWelcome to contribute new commands or enhance them.\nLet's make our life easier together.\n\nThe workflow is pretty simple:\n\n1. Starting with GitHub Codespace or clone locally.\n  1. `make setup` to config the dependencies (or `pip install -r ./requirements.txt` if you prefer).\n\n2. Create a new subcommand\n   1. Starting by copying and modifying [infershape](./onnxcli/infer_shape.py).\n   2. Register the command in the [dispatcher](./onnxcli/dispatcher.py)\n   3. Create a new command line [test](./tests/test_dispatcher.py)\n   4. `make test` to build and test.\n   5. `make check` and `make format` to fix any code style issues.\n\n3. Try out, debug, commit, push, and open pull request.\n   1. The code has been protected by CI. You need to get a pass before merging.\n   2. Ask if any questions.\n\n\n## License\n\nApache License Version 2.0.\n\n\n[pypi]: https://pypi.org/project/onnxcli\n[github]: https://github.com/zhenhuaw-me/onnxcli\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhenhuaw-me%2Fonnxcli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhenhuaw-me%2Fonnxcli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhenhuaw-me%2Fonnxcli/lists"}