Talmaj/onnx2pytorch

Transform ONNX model to PyTorch representation

What it solves

This tool bridges the gap between the ONNX (Open Neural Network Exchange) format and PyTorch, allowing you to convert ONNX models into native PyTorch models. It is designed to ensure that models exported from other frameworks can be run, inspected, or utilized within a PyTorch environment.

How it works

The converter maps ONNX operators to their PyTorch equivalents. It includes an explicit implementation for all 203 default-domain operators in the current ONNX specification. During conversion, the tool validates its output by testing against onnxruntime to ensure accuracy. If an operator or attribute cannot be accurately represented in PyTorch, the tool raises an error rather than producing incorrect results.

Who it’s for

It is for developers and researchers who need to import pre-trained models from the ONNX ecosystem into their PyTorch projects for inference. It is particularly useful for those who require a reliable, well-tested conversion process for standard computer vision and NLP models.

Highlights

  • Supports all 203 default-domain operators in ONNX 1.23.2.
  • Includes a debug mode to compare activations between PyTorch and onnxruntime for troubleshooting.
  • Tested against a wide range of popular models, including ResNet, MobileNet, BERT, and YOLOv4.
  • Prioritizes accuracy by raising errors for unsupported operations instead of returning incorrect tensor data.

Related

  • Project
  • Project
  • Project
  • Project