ONNX Command-Line Toolbox

Overview

ONNX Command Line Toolbox

Build and Test CodeQL Sanity Coverage

  • Aims to improve your experience of investigating ONNX models.
  • Use it like onnx infershape /path/to/model.onnx. (See the usage section for more.)

Installation

Recommand to install via GitHub repo for the latest functionality.

pip install git+https://github.com/jackwish/onnxcli.git

Two alternative ways are:

  1. Install via pypi package pip install onnxcli
  2. Download and add the code tree to your $PYTHONPATH. This is for development purpose since the command line is different.
    git clone https://github.com/jackwish/onnxcli.git
    export PYTHONPATH=$(pwd)/onnxcli:${PYTHONPATH}
    python onnxcli/cli/dispatcher.py <more args>
    

The onnx draw requires dot command (graphviz) to be avaiable on your machine - which can be installed by command as below on Ubuntu/Debian.

sudo apt install -y graphviz

Usage

Once installed, the onnx and onnxcli commands are avaiable on your machine. You can play with commands such as onnx infershape /path/to/model.onnx. The general format is onnx <sub command> <dedicated arguments ...>. The sub commands are as sections below.

Check the online help with onnx --help and onnx <subcmd> --help for latest usage.

infershape

onnx infershape performs shape inference of the ONNX model. It's an CLI wrapper of onnx.shape_inference. You will find it useful to generate shape information for the models that are extracted by onnx extract.

extract

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. It's a CLI wrapper of onnx.utils.extract_model (which I authorized in the ONNX repo).

inspect

onnx inspect gives you quick view of the information of the given model. It's inspired by the tf-onnx tool.

When working on deep learning, you may like to take a look at what's inside the model. Netron is powerful but doesn't provide fine-grain view.

With onnx 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 --detail

Inpect 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: 0

Node 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 --detail

Inpect 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: 0

Tensor 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]

draw

onnx draw draws the graph in dot, svg, png formats. 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 viewing svg in browser, you can even quick search for the nodes and tensors. Together with onnx 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.

conv

Contributing

Welcome to contribute new commands or enhance them. Let's make our life easier together.

The workflow is pretty simple:

  1. Starting with GitHub Codespace or clone locally.
  • make setup to config the dependencies (or pip install -r ./requirements.txt if you prefer).
  1. Create a new subcommand
  • Starting by copying and modifying infershape.
  • Register the command in the dispatcher
  • Create a new command line test
  • make test to build and test.
  • make check and make format to fix any code style issues.
  1. 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.

License

Apache License Version 2.0.

Comments
  • Some ONNX models don't list activation tensors in GraphProto.value_info

    Some ONNX models don't list activation tensors in GraphProto.value_info

    They should, but they don't. I am not sure why such models behave like this - they cannot pass the ONNX model checker.

    There should be something wrong with the exporter. I can try to figure out which exporter has such issues.

    For onnxcli, any functionality depending on walking GraphProto.value_info may not show the real model. This is not our defect, but the models'. To workaround, you can firstly run shape inference on the model, and the GraphProto.value_info listing issue will be fixed.

    onnx infershape /path/to/input/model /path/to/output/model
    
    documentation 
    opened by zhenhuaw-me 2
  • Integrate the onnx dumper

    Integrate the onnx dumper

    src: https://github.com/onnx/tensorflow-onnx/blob/master/tools/dump-onnx.py

    most of them need to be renamed.

    • [x] inspect to check the model
    • [x] dump dot has high priotiry
    • [ ] print to std if no file specified
    opened by zhenhuaw-me 0
  • Optimizer reports

    Optimizer reports "Unresolved value references" since v0.3.0

    Via pipeline https://github.com/zhenhuaw-me/onnxcli/actions/runs/3453474851/jobs/5764096907.

    A simple model works no issue till optimizer v0.2.7 (verified locally), but starts to fail with optimizer v0.3.0 (verified locally) and still fail with v0.3.2 (the pipeline).

    It's onnx optimize ./assets/tests/conv.float32.onnx optimized.onnx.

    opened by zhenhuaw-me 2
  • Overwrite weights (initializers) with fixed data or random data

    Overwrite weights (initializers) with fixed data or random data

    Bert series ONNX models are very large (x GB) thus not easy to share the real file. We can improve this process by overwriting the weights (initializers)

    • It can be fixed data (e.g. all 0.1 or other value specified), thus the model can be compressed.
    • After sharing, we can recover with numpy style random numbers.

    This can only be used as a sharing method, the generated model are not useful when evaluate accuracy.

    For better usage:

    • Annotation will be added when writing fixed data, thus when re-random we can detect automatically.
    • The tensors can be specified with names or size.
    • Only works for FP32/FP16.
    • 0 removed.
    enhancement 
    opened by zhenhuaw-me 0
  • [draw] show tensor information on the edges

    [draw] show tensor information on the edges

    We currently draw tensors as boxes and operators as circles.

    image

    The graph will be complex if large model. We draw the tensor information on the edges and keep only operators as nodes.

    enhancement 
    opened by zhenhuaw-me 0
  • [infershape] should be able to set tensor shapes - inputs and others

    [infershape] should be able to set tensor shapes - inputs and others

    infershape is not very useful if the input shapes are symbolics (dynamic shapes). If the user can set input shapes, it's more powerful:

    • If set to static shapes, the shape of the model will be known.
    • Even for symbolics, the user can update the input shapes.

    The setup should be optional, and can extend to all the tensors in the model (excluding shape op related).

    Interface should be something like below.

    onnx infershape path/to/input/model.onnx path/to/output/model.onnx --tensor-shape t1:[d0,d1] t2:[d0,d1,d3]
    
    enhancement 
    opened by zhenhuaw-me 0
  • Extract should be able to skip the input tensor names

    Extract should be able to skip the input tensor names

    We should be able to walk the graph starting with the output tensor names and auto infer the input names if not given.

    It would be interesting to figure out if the user provided input tensor names and output tensor names don't cut a subgraph.

    enhancement 
    opened by zhenhuaw-me 0
Releases(v0.2.1)
  • v0.2.1(Nov 13, 2022)

    What's Changed

    • Ping onnxoptimizer to 0.2.7 due to "Unresolved value references" issue. See more in https://github.com/zhenhuaw-me/onnxcli/issues/28
    • convert: enable onnx to json by @zhenhuaw-me in https://github.com/zhenhuaw-me/onnxcli/pull/10
    • inspect: print input and output tensor too by @zhenhuaw-me in https://github.com/zhenhuaw-me/onnxcli/pull/12
    • inspect: dump input output tensor by @zhenhuaw-me in https://github.com/zhenhuaw-me/onnxcli/pull/14
    • inspect: show dimension name instead of value if has any by @zhenhuaw-me in https://github.com/zhenhuaw-me/onnxcli/pull/17
    • draw: gen tensor info for tensors that only have name by @zhenhuaw-me in https://github.com/zhenhuaw-me/onnxcli/pull/18
    • setup: install the dependent python packages by @zhenhuaw-me in https://github.com/zhenhuaw-me/onnxcli/pull/19
    • Check command by @zhenhuaw-me in https://github.com/zhenhuaw-me/onnxcli/pull/21

    Full Changelog: https://github.com/zhenhuaw-me/onnxcli/compare/v0.2.0...v0.2.1

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Jan 8, 2022)

  • v0.1.0(Dec 24, 2021)

Owner
黎明灰烬 (王振华 Zhenhua WANG)
A b[i|y]te of ML.sys|Arch|VM.
黎明灰烬 (王振华 Zhenhua WANG)
Implementation of Lie Transformer, Equivariant Self-Attention, in Pytorch

Lie Transformer - Pytorch (wip) Implementation of Lie Transformer, Equivariant Self-Attention, in Pytorch. Only the SE3 version will be present in thi

Phil Wang 78 Oct 26, 2022
Beancount-mercury - Beancount importer for Mercury Startup Checking

beancount-mercury beancount-mercury provides an Importer for converting CSV expo

Michael Lynch 4 Oct 31, 2022
Node for thenewboston digital currency network.

Project setup For project setup see INSTALL.rst Community Join the community to stay updated on the most recent developments, project roadmaps, and ra

thenewboston 27 Jul 08, 2022
Python Library for Signal/Image Data Analysis with Transport Methods

PyTransKit Python Transport Based Signal Processing Toolkit Website and documentation: https://pytranskit.readthedocs.io/ Installation The library cou

24 Dec 23, 2022
Scalable and Elastic Deep Reinforcement Learning Using PyTorch. Please star. 🔥

ElegantRL “小雅”: Scalable and Elastic Deep Reinforcement Learning ElegantRL is developed for researchers and practitioners with the following advantage

AI4Finance Foundation 2.5k Jan 05, 2023
Reduce end to end training time from days to hours (or hours to minutes), and energy requirements/costs by an order of magnitude using coresets and data selection.

COResets and Data Subset selection Reduce end to end training time from days to hours (or hours to minutes), and energy requirements/costs by an order

decile-team 244 Jan 09, 2023
Prometheus Exporter for data scraped from datenplattform.darmstadt.de

darmstadt-opendata-exporter Scrapes data from https://datenplattform.darmstadt.de and presents it in the Prometheus Exposition format. Pull requests w

Martin Weinelt 2 Apr 12, 2022
Source code for our Paper "Learning in High-Dimensional Feature Spaces Using ANOVA-Based Matrix-Vector Multiplication"

NFFT4ANOVA Source code for our Paper "Learning in High-Dimensional Feature Spaces Using ANOVA-Based Matrix-Vector Multiplication" This package uses th

Theresa Wagner 1 Aug 10, 2022
Official tensorflow implementation for CVPR2020 paper “Learning to Cartoonize Using White-box Cartoon Representations”

Tensorflow implementation for CVPR2020 paper “Learning to Cartoonize Using White-box Cartoon Representations”.

3.7k Dec 31, 2022
SegNet model implemented using keras framework

keras-segnet Implementation of SegNet-like architecture using keras. Current version doesn't support index transferring proposed in SegNet article, so

185 Aug 30, 2022
World Models with TensorFlow 2

World Models This repo reproduces the original implementation of World Models. This implementation uses TensorFlow 2.2. Docker The easiest way to hand

Zac Wellmer 234 Nov 30, 2022
Combining Diverse Feature Priors

Combining Diverse Feature Priors This repository contains code for reproducing the results of our paper. Paper: https://arxiv.org/abs/2110.08220 Blog

Madry Lab 5 Nov 12, 2022
Implementation of a Transformer, but completely in Triton

Transformer in Triton (wip) Implementation of a Transformer, but completely in Triton. I'm completely new to lower-level neural net code, so this repo

Phil Wang 152 Dec 22, 2022
A Python library for Deep Probabilistic Modeling

Abstract DeeProb-kit is a Python library that implements deep probabilistic models such as various kinds of Sum-Product Networks, Normalizing Flows an

DeeProb-org 46 Dec 26, 2022
Official implementation for Likelihood Regret: An Out-of-Distribution Detection Score For Variational Auto-encoder at NeurIPS 2020

Likelihood-Regret Official implementation of Likelihood Regret: An Out-of-Distribution Detection Score For Variational Auto-encoder at NeurIPS 2020. T

Xavier 33 Oct 12, 2022
Multi-task Learning of Order-Consistent Causal Graphs (NeuRIPs 2021)

Multi-task Learning of Order-Consistent Causal Graphs (NeuRIPs 2021) Authors: Xinshi Chen, Haoran Sun, Caleb Ellington, Eric Xing, Le Song Link to pap

Xinshi Chen 2 Dec 20, 2021
LiDAR Distillation: Bridging the Beam-Induced Domain Gap for 3D Object Detection

LiDAR Distillation Paper | Model LiDAR Distillation: Bridging the Beam-Induced Domain Gap for 3D Object Detection Yi Wei, Zibu Wei, Yongming Rao, Jiax

Yi Wei 75 Dec 22, 2022
WatermarkRemoval-WDNet-WACV2021

WatermarkRemoval-WDNet-WACV2021 Thank you for your attention. Citation Please cite the related works in your publications if it helps your research: @

LUYI 63 Dec 05, 2022
It is a simple library to speed up CLIP inference up to 3x (K80 GPU)

CLIP-ONNX It is a simple library to speed up CLIP inference up to 3x (K80 GPU) Usage Install clip-onnx module and requirements first. Use this trick !

Gerasimov Maxim 93 Dec 20, 2022
Implementation / replication of DALL-E, OpenAI's Text to Image Transformer, in Pytorch

DALL-E in Pytorch Implementation / replication of DALL-E, OpenAI's Text to Image Transformer, in Pytorch. It will also contain CLIP for ranking the ge

Phil Wang 5k Jan 04, 2023