Package: onnxcli
ONNX Command Line ToolboxAim to improve your experience of investigating ONNX models.Use it likeonnx infershape /path/to/input/model.onnx /path/to/output/model.onnx. (See theusage section.)InstallationRecommand to install viaGitHub repofor the latest functionality.pip install git+https://github.com/zhenhuaw-me/onnxcli.gitTwo alternative ways are:Install viapypi packagepip install onnxcliDownload and add the code tree to your$PYTHONPATH. (For development purpose and the command line is different.）git clone https://github.com/zhenhuaw-me/onnxcli.git
export PYTHONPATH=$(pwd)/onnxcli:${PYTHONPATH}
python onnxcli/cli/dispatcher.py <sub command> <more args...>Requirementsonnxclidepends on different packages w.r.t. different functionality and may extend.
However, we only include only several basic ones (onnxfor example) since you may use only a small portion of the functionalities, or you may like have a different version.Depending on the sub command, error will be raised if the requirements are not met.
Follow the error message to install the requirements.UsageOnce installed, theonnxandonnxclicommands are avaiable.
You can play with commands such asonnx infershape /path/to/input/model.onnx /path/to/output/model.onnx.The general format isonnx <sub command> <dedicated arguments ...>.
The sub commands are as sections below.Check the online help withonnx --helpandonnx <subcmd> --helpfor latest usage.infershapeonnx infershapeperformsshape inferenceof the ONNX model.
It's an CLI wrapper ofonnx.shape_inference.
You will find it useful to generate shape information for the models that are extracted byonnx extract.extractonnx extractextracts the sub model that is determined by the names of the input and output tensor of the subgraph from the original model.
It's a CLI wrapper ofonnx.utils.extract_model(which I authorized in the ONNX repo).inspectonnx inspectgives you quick view of the information of the given model.
It's inspired bythe tf-onnx tool.When working on deep learning, you may like to take a look at what's inside the model.Netronis powerful but doesn't provide fine-grain view.Withonnx inspect, you no longer need to scroll the Netron window to look for nodes or tensors.
Instead, you can dump the node attributes and tensor values with a single command.Click here to see a node example$ onnx inspect ./assets/tests/conv.float32.onnx --node --indices 0 --detailInpect of model ./assets/tests/conv.float32.onnx
Graph name: 9
Graph inputs: 1
Graph outputs: 1
Nodes in total: 1
ValueInfo in total: 2
Initializers in total: 2
Sparse Initializers in total: 0
Quantization in total: 0Node information:
Node "output": type "Conv", inputs "['input', 'Variable/read', 'Conv2D_bias']", outputs "['output']"
attributes: [name: "dilations"
ints: 1
ints: 1
type: INTS
, name: "group"
i: 1
type: INT
, name: "kernel_shape"
ints: 3
ints: 3
type: INTS
, name: "pads"
ints: 1
ints: 1
ints: 1
ints: 1
type: INTS
, name: "strides"
ints: 1
ints: 1
type: INTS
]Click here to see a tensor example$ onnx inspect ./assets/tests/conv.float32.onnx --tensor --names Conv2D_bias --detailInpect of model ./assets/tests/conv.float32.onnx
Graph name: 9
Graph inputs: 1
Graph outputs: 1
Nodes in total: 1
ValueInfo in total: 2
Initializers in total: 2
Sparse Initializers in total: 0
Quantization in total: 0Tensor information:
Initializer "Conv2D_bias": type FLOAT, shape [16],
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]drawonnx drawdraws the graph indot,svg,pngformats.
It gives you quick view of the type and shape of the tensors that are fed to a specific node.
You can view the model topology in image viewer of browser without waiting for the model to load,
which I found is really helpful for large models.If you are viewingsvgin browser, you can even quick search for the nodes and tensors.
Together withonnx inspect, it will be very efficient to understand the issue you are looking into.The node are in ellipses and tensors are in rectangles where the rounded ones are initializers.
The node type of the node and the data type and shape of the tenors are also rendered.
Here is a Convolution node example.Note: Theonnx drawrequiresdotcommand (graphviz)to be avaiable on your machine - which can be installed by command as below on Ubuntu/Debian.sudo apt install -y graphvizoptimizeonnx optimizeoptimizes the input model withONNX Optimizer.ContributingWelcome to contribute new commands or enhance them.
Let's make our life easier together.The workflow is pretty simple:Starting with GitHub Codespace or clone locally.make setupto config the dependencies (orpip install -r ./requirements.txtif you prefer).Create a new subcommandStarting by copying and modifyinginfershape.Register the command in thedispatcherCreate a new command linetestmake testto build and test.make checkandmake formatto fix any code style issues.Try out, debug, commit, push, and open pull request.The code has been protected by CI. You need to get a pass before merging.Ask if any questions.LicenseApache License Version 2.0.