Skip to main content

Library to transform onnx model to pytorch.

Project description

ONNX to PyTorch

PyPI - License Lint and Test Downloads PyPI

A library to transform ONNX model to PyTorch. This library enables use of PyTorch backend and all of its great features for manipulation of neural networks.

Installation

pip install onnx2pytorch

Usage

import onnx
from onnx2pytorch import ConvertModel

onnx_model = onnx.load(path_to_onnx_model)
pytorch_model = ConvertModel(onnx_model)

Currently supported and tested models from onnx_zoo:

Limitations

Known current version limitations are:

  • batch_size > 1 is now supported by default.
    BatchNorm layers use inference mode (running statistics), which is correct for ONNX models
    exported for inference.
  • Fine tuning and training of converted models was not tested yet, only inference.

Development

Dependency installation

pip install -r requirements.txt

From onnxruntime>=1.5.0 you need to add the following to your .bashrc or .zshrc if you are running OSx: export KMP_DUPLICATE_LIB_OK=True

Code formatting

The Uncompromising Code Formatter: Black
black {source_file_or_directory}

Install it into pre-commit hook to always commit nicely formatted code:
pre-commit install

Testing

Pytest and tox.
tox

Test fixtures

To test the complete conversion of an onnx model download pre-trained models: ./download_fixtures.sh
Use flag --all to download more models. Add any custom models to ./fixtures folder to test their conversion.

Debugging

Set ConvertModel(..., debug=True) to compare each converted activation from pytorch with the activation from onnxruntime.
This helps identify where in the graph the activations start to differ.

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

onnx2pytorch-0.5.3.tar.gz (41.5 kB view details)

Uploaded Source

Built Distribution

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

onnx2pytorch-0.5.3-py3-none-any.whl (58.3 kB view details)

Uploaded Python 3

File details

Details for the file onnx2pytorch-0.5.3.tar.gz.

File metadata

  • Download URL: onnx2pytorch-0.5.3.tar.gz
  • Upload date:
  • Size: 41.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for onnx2pytorch-0.5.3.tar.gz
Algorithm Hash digest
SHA256 28cf3efff7a7f13144d83bfe24d110ca3329a3bd11e568e99fbaf3bc75f6f7c0
MD5 e8628087d3c6e5808c5bc8385f512ac9
BLAKE2b-256 1ca670fa9bfab7a47f8516943dc99f263f521229adf1aea87bb22f88800efa85

See more details on using hashes here.

File details

Details for the file onnx2pytorch-0.5.3-py3-none-any.whl.

File metadata

  • Download URL: onnx2pytorch-0.5.3-py3-none-any.whl
  • Upload date:
  • Size: 58.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for onnx2pytorch-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f6aea58d1cbcdb8cb1700ad4ba2d19b7ee4f6fda59e6247588965be70fb69db7
MD5 e99821318815929b697e8672c614a2e2
BLAKE2b-256 f32a242ce12ae9a5a107ce185df9bc5937a0fbddcb30541062df82dfb4b8983b

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