onnx2pytorch  by Talmaj

Library to transform ONNX models to PyTorch

created 5 years ago
338 stars

Top 82.6% on sourcepulse

GitHubView on GitHub
Project Summary

This library transforms ONNX models into PyTorch representations, enabling users to leverage PyTorch's backend and features for neural network manipulation. It is particularly useful for researchers and developers who need to convert pre-trained models from ONNX format to PyTorch for further analysis, modification, or integration into PyTorch-based pipelines.

How It Works

The library parses an ONNX model and reconstructs an equivalent PyTorch model layer by layer. It maps ONNX operators to their corresponding PyTorch modules, handling the graph traversal and dependency management to ensure accurate conversion. This approach allows for seamless integration with the PyTorch ecosystem.

Quick Start & Requirements

  • Primary install: pip install onnx2pytorch
  • Prerequisites: ONNX, Python 3.7+. For OSx users with onnxruntime>=1.5.0, set export KMP_DUPLICATE_LIB_OK=True in .bashrc or .zshrc.
  • Testing fixtures can be downloaded via ./download_fixtures.sh.
  • Official documentation and usage examples are available in the README.

Highlighted Details

  • Supports conversion of models from ONNX Zoo, including MobileNet, ResNet, ShuffleNet_V2, BERT-Squad, EfficientNet-Lite4, and U-net.
  • YOLOv4 conversion is available but may have minor differences due to interpolation implementations.
  • Debugging mode (debug=True) allows comparison of PyTorch and ONNX Runtime activations to pinpoint conversion discrepancies.

Maintenance & Community

  • The project appears to be actively maintained, with clear instructions for code formatting (Black) and testing (Pytest, tox).
  • No specific community channels (Discord/Slack) or roadmap links are provided in the README.

Licensing & Compatibility

  • The README does not explicitly state a license. Users should verify licensing for commercial use or closed-source integration.

Limitations & Caveats

  • Batch size greater than 1 may yield unexpected results due to ONNX BatchNorm ambiguity; setting experimental=True in ConvertModel is required to bypass this assertion.
  • Fine-tuning and training of converted models have not been tested; only inference is guaranteed.
Health Check
Last commit

8 months ago

Responsiveness

Inactive

Pull Requests (30d)
1
Issues (30d)
0
Star History
6 stars in the last 90 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems) and Deshraj Yadav Deshraj Yadav(Cofounder of Mem0).

tutorials by onnx

0.1%
4k
ONNX model tutorials and examples
created 7 years ago
updated 1 year ago
Feedback? Help us improve.