Skip to main content

Convert TensorFlow Lite models to ONNX

Project description

tflite2onnx - Convert TensorFlow Lite models to ONNX

Build and Test Sanity Coverage

tflite2onnx converts TensorFlow Lite (TFLite) models (*.tflite) to ONNX models (*.onnx), with data layout and quantization semantic properly handled (check the introduction blog for detail).

Highlights

  • If you'd like to convert a TensorFlow model (frozen graph *.pb, SavedModel or whatever) to ONNX, try tf2onnx. Or, you can firstly convert it to a TFLite (*.tflite) model, and then convert the TFLite model to ONNX.

  • Microsoft has implemented another TensorFlow Lite to ONNX model converter in tf2onnx at Feb 2021 (we open sourced tflite2onnx in May 2020). tf2onnx seems to able to convert Quantization just like us, and it seems able to convert RNN networks which we are not supported yet. Please try tf2onnx --tflite if tflite2onnx missing any functionality.

Installation

Install via pip pip install tflite2onnx.

Or install from source to get latest features (please try out with virtualenv):

  1. Download the repo: git clone https://github.com/zhenhuaw-me/tflite2onnx.git && cd tflite2onnx
  2. Build the package: ./scripts/build-wheel.sh
  3. Install the built package: pip install assets/dist/tflite2onnx-*.whl

Or you can just add the code tree to your $PYTHONPATH. (Command line tool is not avaiable in this mode.)

export PYTHONPATH=$(pwd):${PYTHONPATH}

Usage

Python Interface

import tflite2onnx

tflite_path = '/path/to/original/tflite/model'
onnx_path = '/path/to/save/converted/onnx/model'

tflite2onnx.convert(tflite_path, onnx_path)

tflite2onnx now supports explicit layout, check the test example.

Command Line

tflite2onnx /path/to/original/tflite/model /path/to/save/converted/onnx/model

Documentation

Contributing

Check contribution guide for more.

License

Apache License Version 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tflite2onnx-0.4.1.tar.gz (29.3 kB view details)

Uploaded Source

Built Distribution

tflite2onnx-0.4.1-py3-none-any.whl (42.2 kB view details)

Uploaded Python 3

File details

Details for the file tflite2onnx-0.4.1.tar.gz.

File metadata

  • Download URL: tflite2onnx-0.4.1.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.14

File hashes

Hashes for tflite2onnx-0.4.1.tar.gz
Algorithm Hash digest
SHA256 a17d18398a87e40bf25df7c190b6fa9533dab3812431690e858f87ee2b697022
MD5 dc4d87a9fd6c3564de5ea6547a3f3e96
BLAKE2b-256 829047beb443f16ce9264213bec1776fda2c168367ebc992a88039df19f87023

See more details on using hashes here.

File details

Details for the file tflite2onnx-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: tflite2onnx-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 42.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.14

File hashes

Hashes for tflite2onnx-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef310782d970220cef8ba407bdbcdf4c18f787a176fc16325ef7da08df3c503a
MD5 3fb980d61a832aa62dddbad8093aa3a9
BLAKE2b-256 91d221041386acdfbe76bfbaaf46b799e3af3a1ae69f3c9fe633c78273e7eacd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page