ONNX简介

Open Neural Network Exchange(ONNX,开放神经网络交换)格式,是一个用于表示深度学习模型的标准,可使模型在不同框架之间进行转移(一般用于中间部署阶段)。
目前官方支持加载ONNX模型并进行推理的深度学习框架有: Caffe2, PyTorch, MXNet,ML.NET,TensorRT 和 Microsoft CNTK,并且 TensorFlow 也非官方的支持ONNX。

ONNX Runtime简介

ONNX Runtime是将 ONNX 模型部署到生产环境的跨平台高性能运行引擎。
适用于 Linux、Windows 和 Mac。编写C++,它还具有 C、Python 和C# api。 ONNX 运行时为所有 ONNX 规范提供支持,并与不同硬件(如 TensorRT 上的 NVidia Gpu)上的加速器集成

tf2onnx - Convert TensorFlow, Keras, Tensorflow.js and Tflite models to ONNX.

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

Build Type OS Python Tensorflow ONNX opset Status
Unit Test - Basic Linux, MacOS, Windows 3.6-3.9 1.12-1.15, 2.1-2.6 8-14 [ONNX] ONNX - 图1
Unit Test - Full Linux, MacOS, Windows 3.6-3.9 1.12-1.15, 2.1-2.6 8-14 [ONNX] ONNX - 图2

Supported Versions

ONNX

tf2onnx will use the ONNX version installed on your system and installs the latest ONNX version if none is found.
We support and test ONNX opset-8 to opset-14. opset-6 and opset-7 should work but we don’t test them. By default we use opset-9 for the resulting ONNX graph since most runtimes will support opset-9.
If you want the graph to be generated with a specific opset, use —opset in the command line, for example —opset 13.

TensorFlow

We support tf-1.x graphs and tf-2. To keep our test matrix manageable we test tf2onnx running on top of tf-1.12 or better.
When running under tf-2.x tf2onnx will use the tensorflow V2 controlflow.
You can install tf2onnx on top of tf-1.x or tf-2.x.

Python

We support Python 3.6-3.9. Note that on windows for Python > 3.7 the protobuf package doesn’t use the cpp implementation and is very slow - we recommend to use Python 3.7 for that reason.

Prerequisites

Install TensorFlow

If you don’t have TensorFlow installed already, install the desired TensorFlow build, for example:
pip install tensorflow

(Optional) Install runtime

If you want to run tests, install a runtime that can run ONNX models. For example:
ONNX Runtime (available for Linux, Windows, and Mac):
pip install onnxruntime

Installation

Install from pypi

pip install -U tf2onnx

Install latest from github

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