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 to various other frameworks, primarily targeting LiteRT (formerly TensorFlow Lite), TensorFlow, and PyTorch. It eliminates the need to manually rewrite models when switching between these ecosystems, supporting a wide range of operators to ensure high compatibility.
How it works
The tool provides two primary execution paths for conversion:
flatbuffer_direct(Default): A high-speed path that bypasses per-node TensorFlow conversion. It performs ONNX graph preprocessing, direct lowering to an internal ModelIR, and exports directly to FlatBuffer (TFLite) format. This path can be over 100x faster 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, TorchScript, and Exported Programs (.pt2), as well as TensorFlow SavedModels and Keras files. It also supports converting directly from LiteRT back to PyTorch.
Who it’s for
It is intended for ML engineers and developers who need to deploy models on edge devices (via LiteRT/TFLite) or migrate models between PyTorch and TensorFlow/ONNX ecosystems without losing functional accuracy.
Highlights
- Multi-Framework Support: Converts ONNX to LiteRT, TensorFlow, and native PyTorch code.
- High Performance: The
flatbuffer_directbackend offers significantly faster conversion speeds compared to traditional methods. - Extensive Op Coverage: Supports a vast library of ONNX operators, including complex layers like Attention, GRU, and LSTM.
- Accuracy Validation: Provides built-in tools to generate accuracy reports comparing the input model (e.g., ONNX) with the converted output (e.g., TFLite or PyTorch).
- PyTorch Native Export: Can emit a standard
torch.nn.Modulewith a compatiblestate_dict.pthfor eager inference.