zhenhuaw-me / tflite2onnx

Convert TensorFlow Lite models (*.tflite) to ONNX.
https://zhenhuaw.me/tflite2onnx
Apache License 2.0
147 stars 26 forks source link

Get to know the recent status of TF2ONNX #9

Closed zhenhuaw-me closed 4 years ago

zhenhuaw-me commented 4 years ago

https://github.com/onnx/tensorflow-onnx

zhenhuaw-me commented 4 years ago

Overall status (readme)

How tf2onnx works

zhenhuaw-me commented 4 years ago

Transpose based layout handling

tf2onnx has a reasonable handling of layout - all in all, it has ~10 active developers. In one sentance, it's very like our propagation based approach with input/output shape unchanged when comparing the original model and output model - inserting Transpose there. It could be inserting Transpose operators first, and then remove most of them during graph optimization.

A mobilenet v2 example (official Google MobileNetV2 model) after convert is as below.

python -m tf2onnx.convert --graphdef ./mobilenet_v2_1.0_224/mobilenet_v2_1.0_224_frozen.pb \
  --output mobilenet_v2.onnx --inputs input:0[1,224,224,3] --outputs MobilenetV2/Predictions/Softmax:0

The Transpose for input.

tf2onnx - mobilenetv2

Further more, tf2onnx performs graph optimization such as fusing batch normalization and bias add into convolution. Better than what we expected before.

zhenhuaw-me commented 4 years ago

Quantization support

tf2onnx doesn't support generate quantized ONNX model from TensorFlow models.

Converted official quantization-aware training mobilenet v1 model.

屏幕快照 2020-07-13 下午8 16 02

Given a quantiation-aware training tensorflow model, tf2onnx:

And, they officially not support quantized tensorflow models:

We have not been planning for adding direct support for quantitizatized tensorflow models for a couple of reasons...

If you want to convert a tensorflow model to onnx and than quantitize the onnx model you'd

Regarding the quantization, we have a chance here.

zhenhuaw-me commented 4 years ago

TF2 support

Limit support here as of July 13 2020. Not going to play around as we don't have much tf2 experience neither...

There is now experimental support for tf-2.x. With the exception of LSTM unit tests, all unit tests are enabled and passing. Unit tests that we still need to fix are marked with @skip_tf2. GRU/LSTM's are converting but not runnable due to type/shape inference issues at runtime (working on that one). All unit tests are running in eager mode. After execution we take the python function, make it a graph and convert it to ONNX. When running under tf-2.x tf2onnx will use the tensorflow V2 controlflow.

zhenhuaw-me commented 4 years ago

We known the basic status here. Layout handling is better then we imaging and quantization is too limited.