Conversion between TensorFlow and ONNX
First, we will look at the conversion between TF and ONNX. We will break down the process into two: converting a TF model into an ONNX model and converting an ONNX model back into a TF model.
Converting a TensorFlow model into an ONNX model
tf2onnx
is used to convert a TF model into an ONNX model (https://github.com/onnx/tensorflow-onnx). This library supports both versions of TF (version 1 as well as version 2). Furthermore, conversions to deployment-specific TF formats such as TensorFlow.js and TensorFlow Lite are also available.
To convert a TF model generated using the saved_model
module into an ONNX model, you can use the tf2onnx.convert
module, as follows:
python -m tf2onnx.convert --saved-model tensorflow_model_path --opset 9 --output model.onnx
In the preceding command, tensorflow-model-path
points to a TF model saved on disk, --output
defines where the generated ONNX model will be saved, and --opset
sets ONNX...