Skip to content

Commit

Permalink
add tf2onnx wrapper test. (#367)
Browse files Browse the repository at this point in the history
* add tf2onnx wrapper test.

* install tf 1.15.0

* install tf2onnx
  • Loading branch information
wenbingl authored Jan 29, 2020
1 parent 68a04ee commit dfd089b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .azure-pipelines/linux-CI-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ jobs:
conda install -c conda-forge numpy
conda install -c conda-forge cmake
python -m pip install $(ONNX_PATH)
test '$(python.version)' != '2.7' && python -m pip install tensorflow-cpu==1.15.0
python -m pip install tf2onnx
python -m pip install git+https://github.com/microsoft/onnxconverter-common
python -m pip install git+https://github.com/onnx/keras-onnx
python -m pip install -r requirements.txt
python -m pip install -r requirements-dev.txt
python -m pip install $(ORT_PATH)
Expand Down
8 changes: 4 additions & 4 deletions .azure-pipelines/linux-conda-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ jobs:
conda install -c conda-forge numpy
conda install -c conda-forge cmake
pip install $(ONNX_PATH)
git clone https://github.com/microsoft/onnxconverter-common
cd onnxconverter-common
pip install -e .
cd ..
test '$(python.version)' != '2.7' && python -m pip install tensorflow-cpu==1.15.0
python -m pip install tf2onnx
python -m pip install git+https://github.com/microsoft/onnxconverter-common
python -m pip install git+https://github.com/onnx/keras-onnx
pip install -r requirements.txt
pip install -r requirements-dev.txt
test '$(python.version)' != '2.7' && pip install $(ONNXRT_PATH)
Expand Down
8 changes: 4 additions & 4 deletions .azure-pipelines/win32-CI-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ jobs:
python -m pip install --upgrade pip numpy
echo Test numpy installation... && python -c "import numpy"
pip install %COREML_PATH% %ONNX_PATH%
git clone https://github.com/microsoft/onnxconverter-common
cd onnxconverter-common
pip install -e .
cd ..
python -m pip install tensorflow-cpu==1.15.0
python -m pip install tf2onnx
python -m pip install git+https://github.com/microsoft/onnxconverter-common
python -m pip install git+https://github.com/onnx/keras-onnx
echo Test onnxconverter-common installation... && python -c "import onnxconverter_common"
pip install -r requirements.txt
pip install -r requirements-dev.txt
Expand Down
3 changes: 3 additions & 0 deletions .azure-pipelines/win32-conda-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ jobs:
python -m pip install --upgrade pip numpy
echo Test numpy installation... && python -c "import numpy"
python -m pip install %COREML_PATH% %ONNX_PATH%
python -m pip install tensorflow-cpu==1.15.0
python -m pip install tf2onnx
python -m pip install git+https://github.com/microsoft/onnxconverter-common
python -m pip install git+https://github.com/onnx/keras-onnx
echo Test onnxconverter-common installation... && python -c "import onnxconverter_common"
python -m pip install -r requirements.txt
python -m pip install -r requirements-dev.txt
Expand Down
18 changes: 18 additions & 0 deletions tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
Tests utilities.
"""
import os
import six
import unittest
import onnxmltools
from onnxmltools.utils import load_model, save_model
from onnxmltools.utils import set_model_version, set_model_domain, set_model_doc_string

Expand Down Expand Up @@ -53,5 +55,21 @@ def test_set_docstring_blank(self):
self.assertEqual(onnx_model.doc_string, "")


@unittest.skipIf(six.PY2, "Keras and Tensorflow converter not support python 2.x")
class TestWrapper(unittest.TestCase):

def test_keras_with_tf2onnx(self):
import keras2onnx
from keras2onnx.proto import keras
from keras2onnx.proto.tfcompat import is_tf2
if not is_tf2: # tf2onnx is not available for tensorflow 2.0 yet.
model = keras.Sequential()
model.add(keras.layers.Dense(units=4, input_shape=(10,), activation='relu'))
model.compile(loss='binary_crossentropy', optimizer='Adam', metrics=['binary_accuracy'])
graph_def = keras2onnx.export_tf_frozen_graph(model)
onnx_model = onnxmltools.convert_tensorflow(graph_def, **keras2onnx.build_io_names_tf2onnx(model))
self.assertTrue(len(onnx_model.graph.node) > 0)


if __name__ == "__main__":
unittest.main()

0 comments on commit dfd089b

Please sign in to comment.