tensorflow-onnx  by onnx

CLI tool to convert TensorFlow models to ONNX

Created 7 years ago
2,477 stars

Top 18.8% on SourcePulse

GitHubView on GitHub
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

6 days ago

Responsiveness

1 day

Pull Requests (30d)
2
Issues (30d)
3
Star History
19 stars in the last 30 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), Luis Capelo Luis Capelo(Cofounder of Lightning AI), and
1 more.

tutorials by onnx

0.1%
4k
ONNX model tutorials and examples
Created 7 years ago
Updated 1 year ago
Feedback? Help us improve.