skillfed

onnx2torch

ONNX to PyTorch converter

onnx2torch v1.5.15 225.7K downloads/30d#9,216 on PyPI739
Permissive license Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for… (full text in the JSON record) AGING released

What it is and what it does

onnx2torch is a converter that transforms ONNX model files into native PyTorch modules. It accepts either a file path or a loaded ONNX model object and returns a PyTorch nn.Module that can be used directly for inference or training. The converter is designed to be extensible—you can register custom PyTorch layers for unsupported ONNX operations using a decorator pattern, and converted models can be exported back to ONNX using torch.onnx.export.

The package supports a curated set of models including popular segmentation architectures (DeepLabV3+, UNet, HRNet), detection models (YOLOv3, YOLOv5, RetinaNet), classification networks (ResNet, MobileNet, EfficientNet, ViT), and transformers (Swin, GPT-J). However, it covers only a limited number of ONNX operations, so not all ONNX models will convert successfully. The maintainers explicitly encourage users to report unsupported models and operations.

Use it for:

  • Convert a pre-trained ONNX model to PyTorch for fine-tuning or inference in a PyTorch-native pipeline.
  • Integrate ONNX-exported models from other frameworks into a PyTorch codebase.
  • Extend the converter with custom layers to support domain-specific ONNX operations not yet in the core library.
  • Validate ONNX model behavior by running inference in PyTorch and comparing outputs against ONNX Runtime.
  • Deploy ONNX models trained elsewhere as native PyTorch modules without maintaining separate inference code.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Converts ONNX models to PyTorch modules with a simple API, supporting a limited but growing set of operations and popular model architectures.

Yes, if you need to convert ONNX models to PyTorch and your model uses supported operations. The package is stable and permissively licensed, with low install friction. However, verify that your specific ONNX model's operations are supported before committing to it—the converter does not support all ONNX operations, and maintenance has slowed. If your model is unsupported, you may need to implement custom converters or consider alternatives.

Install

onnx2torch on PyPI

pip

pip install onnx2torch

uv

uv add onnx2torch

poetry

poetry add onnx2torch

Installing onnx2torch

Before you install

Low install friction with a pure Python wheel. Maintenance is aging—last release was over a year ago, though the repository remains active and the project is marked Production/Stable.

License in practice

Apache License 2.0 is permissive; you may use, modify, and distribute this package freely in commercial and private projects provided you include the license and attribute the original work.

Quickstart

pip install onnx2torch

import torch
from onnx2torch import convert

torch_model = convert("/path/to/model.onnx")
output = torch_model(torch.randn(1, 3, 224, 224))

Requires torch and torchvision installed; conversion success depends on whether the ONNX model's operations are in the supported set.

Verify before relying

  • Whether all operations in your specific ONNX model are currently supported by this version.
  • Performance characteristics of converted models compared to native PyTorch implementations.
  • Compatibility with ONNX opset versions beyond those documented in the description.

Package facts

License Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for… (full text in the JSON record) (permissive)
Python support supports the current Python release (>=3.6)
Install friction low — pure-Python wheel
Runtime dependencies 4 — numpy, onnx, torch, torchvision
Maintenance aging — 737 days since the last release
Last repo commit
First released
Downloads 225,660/month — #9,216 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: onnx2torch-1.5.15-py3-none-any.whl

Keywords: AI, onnx, torch, onnx2torch, converters

Development Status :: 5 - Production/StableLicense :: OSI Approved :: Apache Software LicenseProgramming Language :: PythonProgramming Language :: Python :: 3 :: Only

Tags

onnx to pytorch conversionconvert onnx models to torchonnx model converterpytorch from onnxonnx2torch converterdeep learning model format conversion
model-conversiononnxpytorch

More Artificial Intelligence packages