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: 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)

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)
MobileNet v2-1.0-fp32 3.3 300
ResNet50_fp32 25 3868
SqueezeNet 1.0 1.23 351
VGG 19 143.66 19643
AlexNet 60.96 665
GoogleNet 6.99 1606
googlenet_age_adience 5.98 1605
LResNet100E-IR 65.22 12102
BERT-Squad 113.61 22767
BiDAF 18.08 9.87
EfficientNet-Lite4 12.96 1361
Emotion FERPlus 12.95 877
Mask R-CNN R-50-FPN-fp32 46.77 92077
Model Params(M) MACs(M)
rvm_mobilenetv3_fp32.onnx 3.73 4289
yolov4 64.33 33019
ConvNeXt-L 229.79 34872
edgenext_small 5.58 1357
SSD 19.98 216598
RealESRGAN_x4plus.pth 16.69 73551
ShuffleNet-v2-fp32 2.29 146
GPT-2 137.02 1103
T5-encoder 109.62 686
T5-decoder-with-lm-head 162.62 1113
RoBERTa-BASE 124.64 688
Faster R-CNN R-50-FPN-fp32 44.10 46018
FCN ResNet-50 35.29 37056

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.2.9.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

onnx_tool-0.2.9-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: onnx-tool-0.2.9.tar.gz
  • Upload date:
  • Size: 23.1 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.2.9.tar.gz
Algorithm Hash digest
SHA256 6e1f2e82c4a4ee5223e5165ecc808401aaa2263b8495ada93d215775c187e8b6
MD5 b6e0535b22597d0c79373caeef3b6c46
BLAKE2b-256 860b07e89e3f4cd95e38bf180c656d7a0b6e43a439b4ac86899353e059a4ef4c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: onnx_tool-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 22.5 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.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 a429213e5c2573914cbec2786e4020e9f5b1afd69a155c9b0f88bd09191a784a
MD5 73df70b07b57494983ee87a56f251c0b
BLAKE2b-256 366918c9e9574bb95226f877bb19092c94d87f120d7d7eace76e39c7fffa5847

See more details on using hashes here.

Supported by

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