- Notifications
You must be signed in to change notification settings - Fork296
Tensorflow Backend for ONNX
License
onnx/onnx-tensorflow
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Note this repo is not actively maintained and will be deprecated. If you are interested in becoming the owner, please contact the ONNX Steering Committee (https://github.com/onnx/steering-committee).
Open Neural Network Exchange (ONNX) is an open standard format for representing machine learning models. ONNX is supported by a community of partners who have implemented it in many frameworks and tools.
TensorFlow Backend for ONNX makes it possible to use ONNX models as input forTensorFlow. The ONNX model is first converted to a TensorFlow model and then delegated for execution on TensorFlow to produce the output.
This is one of the two TensorFlow converter projects which serve different purposes in the ONNX community:
- onnx-tensorflow converts ONNX models to Tensorflow
- tf2onnx converts Tensorflow models to ONNX
Command Line Interface Documentation
From ONNX to TensorFlow:onnx-tf convert -i /path/to/input.onnx -o /path/to/output
We have joined force with Microsoft to co-develop ONNX TensorFlow frontend.For current onnx-tf frontend users, please migrate to use tf-onnx (https://github.com/onnx/tensorflow-onnx) where our code had been merged into.
import onnxfrom onnx_tf.backend import prepareonnx_model = onnx.load("input_path") # load onnx modeloutput = prepare(onnx_model).run(input) # run the loaded model
Running an ONNX model using TensorFlow
ONNX-TF requires ONNX (Open Neural Network Exchange) as an external dependency, for any issues related to ONNX installation, we refer our users toONNX project repository for documentation and help. Notably, please ensure thatprotoc
is available if you plan to install ONNX via pip.
The specific ONNX release version that we support in the master branch of ONNX-TF can be foundhere. This information about ONNX version requirement is automatically encoded insetup.py
, therefore users needn't worry about ONNX version requirement when installing ONNX-TF.
To install the latest version of ONNX-TF via pip, runpip install onnx-tf
.
Because users often have their own preferences for which variant of TensorFlow to install (i.e., a GPU version instead of a CPU version), we do not explicitly require tensorflow in the installation script. It is therefore users' responsibility to ensure that the proper variant of TensorFlow is available to ONNX-TF. Moreover, we require TensorFlow version == 2.8.0.
ONNX-TensorFlow Op Coverage Status
- Install ONNX master branch from source.
- Install TensorFlow >= 2.8.0, tensorflow-probability and tensorflow-addons. (Note TensorFlow 1.x is no longer supported)
- Run
git clone https://github.com/onnx/onnx-tensorflow.git && cd onnx-tensorflow
. - Run
pip install -e .
.
- onnx_tf: main source code file.
- test: test files.
- Format code
pip install yapfyapf -rip --style="{based_on_style: google, indent_width: 2}" $FilePath$
- Install pylint
pip install pylintwget -O /tmp/pylintrc https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/tools/ci_build/pylintrc
- Check format
pylint --rcfile=/tmp/pylintrc myfile.py
Google Style Python Docstrings
To perfomunit tests:
pip install pytest tabulatepython -m unittest discover test
Note: Only the ONNX backend tests found intest_onnx_backend.py
require thepytest
andtabulate
packages.
Testing requires significant hardware resources, but nonetheless, we highly recommend that users run through the complete test suite before deploying onnx-tf. The complete test suite typically takes between 15 and 45 minutes to complete, depending on hardware configurations.
The tests intest_modelzoo.py
verify whether theONNX Model Zoo models can be successfully validated against the ONNX specification and converted to a TensorFlow representation. Model inferencing on the converted model is not tested currently.
The model zoo usesGit LFS (Large File Storage) to store ONNX model files. Make sure that Git LFS is installed on your operating system.
By default, the tests assume that the model zoo repository has been cloned into this project directory. The model zoo directory is scanned for ONNX models. For each model found: download the model, convert the model to TensorFlow, generate a test status, and delete the model. By default, the generated test report is created in the system temporary directory. Runpython test/test_modelzoo.py -h
for help on command line options.
git clone https://github.com/onnx/modelspython test/test_modelzoo.py
Testing all models can take at least an hour to complete, depending on hardware configuration and model download times. If you expect to test some models frequently, we recommend using Git LFS to download those models before running the tests so the large files are cached locally.
When making code contributions, the model zoo tests are run when a commit is merged. Generated test reports are published on theonnx-tensorflow wiki.
About
Tensorflow Backend for ONNX