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).
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.
Currently we have 14 open issues. I am sorry that I don't have more bandwidth to work on them. Please help to contribute to this project! See Contributing below.
Started from the beginning, I have written docs to help you ramp up this project. Therefore I am not the critical path of this project.
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.
Yet, due to the architecture, I think it's non-trivial to fix a bug, which means that,
tflite2onnx
is a rather better choice if you are blocked and don't wait for a fix from the maintainer.
Install via pip pip install tflite2onnx
.
Or install from source to get latest features (please try out with virtualenv):
- Download the repo:
git clone https://github.com/zhenhuaw-me/tflite2onnx.git && cd tflite2onnx
- Build the package:
./scripts/build-wheel.sh
- 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}
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.
tflite2onnx /path/to/original/tflite/model /path/to/save/converted/onnx/model
- FAQ
- Release note
- Contribution guide
- Introduction blog - the background, design and implementation
- How to enable a new operator
- Data layout semantic
- If something seems wrong to you, report bugs.
- If some operators are not supported yet, you may request a new operator.
- It would be great if you can help to enable new operators, please join us with How to enable a new operator.
- Feel free to open any other related discussions.
Check contribution guide for more.
Apache License Version 2.0.