Last edited one year ago

How to convert a Tensorflow™ Lite model to ONNX using tf2onnx

Applicable for STM32MP13x lines, STM32MP15x lines

This article describes how to convert a .tflite model to the ONNX format.

1. Convert a Tensorflow™ Lite model to ONNX using tf2onnx

To convert a .tflite model to the ONNX format, ONNX provides a tool named tf2onnx [1], which is very simple to use. The tool tf2onnx uses the versions of Tensorflow and ONNX Runtime already installed. If it does not find any, it installs the most recent versions. Follow these steps to install tf2onnx and convert a model:

- Install from PyPI:

 pip install -U tf2onnx

or

- Install latest from GitHub:

 pip install git+https://github.com/onnx/tensorflow-onnx

After the installation, the user is able to convert the .tflite model directly using the following command line:

  python -m tf2onnx.convert --opset 16 --tflite path/to/tflite/model.tflite --output path/to/onnx/model/model.onnx

Native ONNX models are also available in the ONNX Model Zoo [2].

2. References