PINTO0309/onnx2tf
A tool for converting ONNX files to LiteRT/TFLite/TensorFlow, PyTorch native code (nn.Module), TorchScript (.pt), state_dict (.pt), Exported Program (.pt2), and Dynamo ONNX. It also supports direct conversion from LiteRT to PyTorch.
What it solves
onnx2tf is a conversion tool designed to move AI models from the ONNX format into various other frameworks. It primarily solves the problem of deploying models to mobile or edge devices by converting ONNX files to LiteRT (formerly TFLite) and TensorFlow, while also providing paths to convert models into native PyTorch code, TorchScript, and other PyTorch-compatible formats.
How it works
The tool provides two primary execution paths for conversion:
flatbuffer_direct(Default): A high-speed path that bypasses the legacy TensorFlow conversion process. It performs ONNX graph preprocessing and direct lowering to a ModelIR, which is then exported directly to FlatBuffer (TFLite) files. This path can be significantly faster (up to 100x) than the legacy path.tf_converter(Legacy): A compatibility path that uses the standard TensorFlow Lite Converter.
Beyond TFLite, the tool can generate native PyTorch nn.Module packages, including state_dict files and Exported Programs, allowing models to be run in eager inference mode within PyTorch.
Who it’s for
It is intended for ML engineers and developers who need to port models between different deep learning frameworks—specifically from ONNX to TensorFlow/LiteRT or PyTorch—to ensure compatibility with specific hardware accelerators or deployment targets.
Highlights
- Multi-Framework Support: Converts ONNX to LiteRT/TFLite, TensorFlow, and native PyTorch code.
- High Performance: The
flatbuffer_directbackend offers massive speedups over traditional conversion methods. - Comprehensive Op Support: Supports a vast array of ONNX operators for the
tf_converterpath. - Accuracy Validation: Can generate accuracy reports to compare the output of the converted model against the original ONNX model.
- Bi-directional Conversion: Supports direct conversion from LiteRT back to PyTorch.
Related
- Project
- Project
- Project
- Project
- Project