tensorflow-onnx  by onnx

CLI tool to convert TensorFlow models to ONNX

created 7 years ago
2,455 stars

Top 19.3% on sourcepulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

This repository provides tf2onnx, a tool for converting TensorFlow, Keras, TensorFlow.js, and TFLite models to the ONNX format. It's designed for developers and researchers who need to deploy TensorFlow-based models on platforms supporting ONNX, enabling cross-compatibility and hardware acceleration.

How It Works

The converter processes TensorFlow models by first performing a 1:1 conversion of the protobuf format to ONNX. It then rewrites subgraphs for complex operations like transpose and LSTM, and processes individual ops by mapping TensorFlow types to ONNX equivalents. TensorFlow ops that are composed of multiple simpler ONNX ops (e.g., ReLU6) are handled by composing the ONNX equivalent. Finally, it optimizes the ONNX graph by removing redundant operations, fusing ops, and ensuring topological sorting.

Quick Start & Requirements

  • Install via pip: pip install -U tf2onnx
  • Prerequisites: TensorFlow (1.15+ or 2.x), ONNX (1.9+). Python 3.7-3.10.
  • Conversion command example: python -m tf2onnx.convert --saved-model <path> --output model.onnx
  • Official documentation: https://github.com/onnx/tensorflow-onnx

Highlighted Details

  • Supports conversion from SavedModel, Checkpoint, GraphDef, TensorFlow.js, and TFLite formats.
  • Handles NHWC to NCHW data format conversion for TensorFlow models.
  • Allows specifying ONNX opset versions (14-18 tested, default 15).
  • Provides Python APIs for programmatic conversion and custom op handling.

Maintenance & Community

The project is actively maintained by the ONNX community. Further details on community engagement and roadmaps are available on the project's GitHub repository.

Licensing & Compatibility

  • License: Apache License v2.0.
  • Compatible with commercial use and closed-source linking.

Limitations & Caveats

TensorFlow.js support is experimental. Some TensorFlow ops may not have direct ONNX equivalents and might require custom handling or may not convert successfully. The converter relies on specific TensorFlow versions for testing.

Health Check
Last commit

2 weeks ago

Responsiveness

1 day

Pull Requests (30d)
3
Issues (30d)
1
Star History
48 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.