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)
DPC: Unsupervised Deep Point Correspondence via Cross and Self Construction (3DV 2021)

DPC: Unsupervised Deep Point Correspondence via Cross and Self Construction (3DV 2021) This repo is the implementation of DPC. Tested environment Pyth

Dvir Ginzburg 30 Nov 30, 2022
Benchmarks for semi-supervised domain generalization.

Semi-Supervised Domain Generalization This code is the official implementation of the following paper: Semi-Supervised Domain Generalization with Stoc

Kaiyang 49 Dec 10, 2022
Official implementation of Unfolded Deep Kernel Estimation for Blind Image Super-resolution.

Unfolded Deep Kernel Estimation for Blind Image Super-resolution Hongyi Zheng, Hongwei Yong, Lei Zhang, "Unfolded Deep Kernel Estimation for Blind Ima

Z80 15 Dec 26, 2022
Re-implementation of the vector capsule with dynamic routing

VectorCapsule Re-implementation of the vector capsule with dynamic routing We implement the vector capsule and dynamic routing via graph neural networ

ZhenchaoTang 10 Feb 10, 2022
A 1.3B text-to-image generation model trained on 14 million image-text pairs

minDALL-E on Conceptual Captions minDALL-E, named after minGPT, is a 1.3B text-to-image generation model trained on 14 million image-text pairs for no

Kakao Brain 604 Dec 14, 2022
Predictive AI layer for existing databases.

MindsDB is an open-source AI layer for existing databases that allows you to effortlessly develop, train and deploy state-of-the-art machine learning

MindsDB Inc 12.2k Jan 03, 2023
Code for "Discovering Non-monotonic Autoregressive Orderings with Variational Inference" (paper and code updated from ICLR 2021)

Discovering Non-monotonic Autoregressive Orderings with Variational Inference Description This package contains the source code implementation of the

Xuanlin (Simon) Li 10 Dec 29, 2022
使用深度学习框架提取视频硬字幕;docker容器免安装深度学习库,使用本地api接口使得界面和后端识别分离;

extract-video-subtittle 使用深度学习框架提取视频硬字幕; 本地识别无需联网; CPU识别速度可观; 容器提供API接口; 运行环境 本项目运行环境非常好搭建,我做好了docker容器免安装各种深度学习包; 提供windows界面操作; 容器为CPU版本; 视频演示 https

歌者 16 Aug 06, 2022
Cognate Detection Repository

Cognate Detection Repository Details This repository contains the data for two publications: Challenge Dataset of Cognates and False Friend Pairs from

Diptesh Kanojia 1 Apr 26, 2022
InsCLR: Improving Instance Retrieval with Self-Supervision

InsCLR: Improving Instance Retrieval with Self-Supervision This is an official PyTorch implementation of the InsCLR paper. Download Dataset Dataset Im

Zelu Deng 25 Aug 30, 2022
Repository for self-supervised landmark discovery

self-supervised-landmarks Repository for self-supervised landmark discovery Requirements pytorch pynrrd (for 3d images) Usage The use of this models i

Riddhish Bhalodia 2 Apr 18, 2022
[3DV 2021] A Dataset-Dispersion Perspective on Reconstruction Versus Recognition in Single-View 3D Reconstruction Networks

dispersion-score Official implementation of 3DV 2021 Paper A Dataset-dispersion Perspective on Reconstruction versus Recognition in Single-view 3D Rec

Yefan 7 May 28, 2022
Region-aware Contrastive Learning for Semantic Segmentation, ICCV 2021

Region-aware Contrastive Learning for Semantic Segmentation, ICCV 2021 Abstract Recent works have made great success in semantic segmentation by explo

Hanzhe Hu 30 Dec 29, 2022
Outlier Exposure with Confidence Control for Out-of-Distribution Detection

OOD-detection-using-OECC This repository contains the essential code for the paper Outlier Exposure with Confidence Control for Out-of-Distribution De

Nazim Shaikh 64 Nov 02, 2022
Out of Distribution Detection on Natural Adversarial Examples

OOD-on-NAE Research project on out of distribution detection for the Computer Vision course by Prof. Rob Fergus (CSCI-GA 2271) Paper out on arXiv - ht

Anugya 1 Jun 08, 2022
No Code AI/ML platform

NoCodeAIML No Code AI/ML platform - Community Edition Video credits: Uday Kiran Typical No Code AI/ML Platform will have features like drag and drop,

Bhagvan Kommadi 5 Jan 28, 2022
Uncertainty Estimation via Response Scaling for Pseudo-mask Noise Mitigation in Weakly-supervised Semantic Segmentation

Uncertainty Estimation via Response Scaling for Pseudo-mask Noise Mitigation in Weakly-supervised Semantic Segmentation Introduction This is a PyTorch

XMed-Lab 30 Sep 23, 2022
Official pytorch implementation of Active Learning for deep object detection via probabilistic modeling (ICCV 2021)

Active Learning for Deep Object Detection via Probabilistic Modeling This repository is the official PyTorch implementation of Active Learning for Dee

NVIDIA Research Projects 130 Jan 06, 2023
NumPy로 구현한 딥러닝 라이브러리입니다. (자동 미분 지원)

Deep Learning Library only using NumPy 본 레포지토리는 NumPy 만으로 구현한 딥러닝 라이브러리입니다. 자동 미분이 구현되어 있습니다. 자동 미분 자동 미분은 미분을 자동으로 계산해주는 기능입니다. 아래 코드는 자동 미분을 활용해 역전파

조준희 17 Aug 16, 2022
State of the Art Neural Networks for Deep Learning

pyradox This python library helps you with implementing various state of the art neural networks in a totally customizable fashion using Tensorflow 2

Ritvik Rastogi 60 May 29, 2022