Library to transform onnx model to pytorch.
Project description
ONNX to PyTorch
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:
- MobileNet
- ResNet
- ShuffleNet_V2
- BERT-Squad
- EfficientNet-Lite4
- Fast Neural Style Transfer
- Super Resolution
- YOLOv4 (Not exactly the same, nearest neighbour interpolation in pytorch differs)
- U-net (Converted from pytorch to onnx and then back)
Limitations
Known current version limitations are:
batch_size > 1is 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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28cf3efff7a7f13144d83bfe24d110ca3329a3bd11e568e99fbaf3bc75f6f7c0
|
|
| MD5 |
e8628087d3c6e5808c5bc8385f512ac9
|
|
| BLAKE2b-256 |
1ca670fa9bfab7a47f8516943dc99f263f521229adf1aea87bb22f88800efa85
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6aea58d1cbcdb8cb1700ad4ba2d19b7ee4f6fda59e6247588965be70fb69db7
|
|
| MD5 |
e99821318815929b697e8672c614a2e2
|
|
| BLAKE2b-256 |
f32a242ce12ae9a5a107ce185df9bc5937a0fbddcb30541062df82dfb4b8983b
|