Skip to main content

A tool for ONNX model:Shape inference, MACs(FLOPs) counting for each layer, Extract subgraph from ONNX model, or do inplace op fusion, and any operation you can image with ONNX.

Project description

onnx-tool

A tool for ONNX model:

  • Shape inference.
  • MACs(FLOPs) counting for each layer.
  • Extract subgraph from ONNX model, or do inplace op fusion. ...
    and any operation you can image with ONNX.

New:

  • Sparse Models are initially supported in v0.3.1 release. view Sparse Model
  • Quantized models are initially supported in v0.3.0 release.
  • 4 onnx models of Stable Diffusion are supported in v0.2.14 release. view results
  • Memory usage of each layer is valid in v0.2.10 release.
  • Pytorch models are also valid if torch.onnx.export succeeded.

Shape inference

how to use: data/Profile.md.
pytorch usage: data/PytorchUsage.md.


MACs counting for each layer (FLOPs=2*MACs)

Float MultipleAdd Count, Memory Usage(in bytes), Parameters(elements number)

Sparse Pattern, Sparse Block Ratio, Sparse Element Ratio

how to use: data/Profile.md.
pytorch usage: data/PytorchUsage.md.


Extract subgraph from ONNX model

how to use: data/Subgraph.md.


Inplace op fusion

how to use: data/Subgraph.md.


Add any hidden tensors to model's outputs

how to use: data/Profile.md.


Tensor operations

  • Export weight tensors to files
  • Simplify tensor and node names, convert name from a long string to a short string
  • Remove unused tensors, models like vgg19-7.onnx set its static weight tensors as its input tensors
  • Set custom input and output tensors' name and dimension, change model from fixed input to dynamic input
    how to use: data/Tensors.md.

How to install

pip install onnx-tool

OR

pip install --upgrade git+https://github.com/ThanatosShinji/onnx-tool.git

python>=3.6

If pip install onnx-tool failed by onnx's installation, you may try pip install onnx==1.8.1 (a lower version like this) first.
Then pip install onnx-tool again.


Known Issues

  • Loop op is not supported

Results of ONNX Model Zoo and SOTA models

Some models have dynamic input shapes. The MACs varies from input shapes. The input shapes used in these results are writen to data/public/config.py. These onnx models with all tensors' shape can be downloaded: baidu drive(code: p91k) google drive

Model Params(M) MACs(M)
text_encoder 123.13 6,782
UNet2DCondition 859.52 888,870
VAE_encoder 34.16 566,371
VAE_decoder 49.49 1,271,959
SqueezeNet 1.0 1.23 351
VGG 19 143.66 19,643
AlexNet 60.96 665
GoogleNet 6.99 1,606
googlenet_age_adience 5.98 1,605
LResNet100E-IR 65.22 12,102
BERT-Squad 113.61 22,767
BiDAF 18.08 9.87
EfficientNet-Lite4 12.96 1,361
Emotion FERPlus 12.95 877
Mask R-CNN R-50-FPN-fp32 46.77 92,077
Model Params(M) MACs(M)
rvm_mobilenetv3_fp32.onnx 3.73 4,289
yolov4 64.33 3,319
ConvNeXt-L 229.79 34,872
edgenext_small 5.58 1,357
SSD 19.98 216,598
RealESRGAN_x4plus.pth 16.69 73,551
ShuffleNet-v2-fp32 2.29 146
GPT-2 137.02 1,103
T5-encoder 109.62 686
T5-decoder-with-lm-head 162.62 1,113
RoBERTa-BASE 124.64 688
Faster R-CNN R-50-FPN-fp32 44.10 46,018
FCN ResNet-50 35.29 37,056
MobileNet v2-1.0-fp32 3.3 300
ResNet50_fp32 25 3,868

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

onnx-tool-0.3.2.tar.gz (25.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

onnx_tool-0.3.2-py3.10.egg (59.1 kB view details)

Uploaded Egg

onnx_tool-0.3.2-py3-none-any.whl (25.0 kB view details)

Uploaded Python 3

File details

Details for the file onnx-tool-0.3.2.tar.gz.

File metadata

  • Download URL: onnx-tool-0.3.2.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for onnx-tool-0.3.2.tar.gz
Algorithm Hash digest
SHA256 839cd44bf6214f213f9903a4338e21d9b2a6c22ffead1e4d57f9c7c4874f23f9
MD5 fd88acf6153d09c887e30d7e9dfd8b83
BLAKE2b-256 8e16c98808e41081ac1ab2043e71092e7ddec9ff65306985dd35a9dc46be4ec2

See more details on using hashes here.

File details

Details for the file onnx_tool-0.3.2-py3.10.egg.

File metadata

  • Download URL: onnx_tool-0.3.2-py3.10.egg
  • Upload date:
  • Size: 59.1 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for onnx_tool-0.3.2-py3.10.egg
Algorithm Hash digest
SHA256 26cf6befd136b4c9a8d3fe9c11307c4ea8041f7302da306c1cf336450dd149a0
MD5 84d70150e221c8eaaf5ba80c66280cce
BLAKE2b-256 b19049af3b92d022e5204e8ebfa9f5f0883ec4a134188eef2fd58c63b4e27b89

See more details on using hashes here.

File details

Details for the file onnx_tool-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: onnx_tool-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 25.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for onnx_tool-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b0b0d423b6b46322b0a93465328a39787f3b5f09a0173c4cc7adc819e757e4a7
MD5 67ed0985b220ef79298dad0b895edfc3
BLAKE2b-256 5cbe263c8a833af25738ffec7dbfe4873a37c447d0cef8d864fa1ceb135bb4c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page