Skip to content

Commit dfd089b

Browse files
author
Wenbing Li
authored
add tf2onnx wrapper test. (#367)
* add tf2onnx wrapper test. * install tf 1.15.0 * install tf2onnx
1 parent 68a04ee commit dfd089b

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

.azure-pipelines/linux-CI-nightly.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ jobs:
3636
conda install -c conda-forge numpy
3737
conda install -c conda-forge cmake
3838
python -m pip install $(ONNX_PATH)
39+
test '$(python.version)' != '2.7' && python -m pip install tensorflow-cpu==1.15.0
40+
python -m pip install tf2onnx
3941
python -m pip install git+https://github.com/microsoft/onnxconverter-common
42+
python -m pip install git+https://github.com/onnx/keras-onnx
4043
python -m pip install -r requirements.txt
4144
python -m pip install -r requirements-dev.txt
4245
python -m pip install $(ORT_PATH)

.azure-pipelines/linux-conda-CI.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ jobs:
5050
conda install -c conda-forge numpy
5151
conda install -c conda-forge cmake
5252
pip install $(ONNX_PATH)
53-
git clone https://github.com/microsoft/onnxconverter-common
54-
cd onnxconverter-common
55-
pip install -e .
56-
cd ..
53+
test '$(python.version)' != '2.7' && python -m pip install tensorflow-cpu==1.15.0
54+
python -m pip install tf2onnx
55+
python -m pip install git+https://github.com/microsoft/onnxconverter-common
56+
python -m pip install git+https://github.com/onnx/keras-onnx
5757
pip install -r requirements.txt
5858
pip install -r requirements-dev.txt
5959
test '$(python.version)' != '2.7' && pip install $(ONNXRT_PATH)

.azure-pipelines/win32-CI-nightly.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ jobs:
3737
python -m pip install --upgrade pip numpy
3838
echo Test numpy installation... && python -c "import numpy"
3939
pip install %COREML_PATH% %ONNX_PATH%
40-
git clone https://github.com/microsoft/onnxconverter-common
41-
cd onnxconverter-common
42-
pip install -e .
43-
cd ..
40+
python -m pip install tensorflow-cpu==1.15.0
41+
python -m pip install tf2onnx
42+
python -m pip install git+https://github.com/microsoft/onnxconverter-common
43+
python -m pip install git+https://github.com/onnx/keras-onnx
4444
echo Test onnxconverter-common installation... && python -c "import onnxconverter_common"
4545
pip install -r requirements.txt
4646
pip install -r requirements-dev.txt

.azure-pipelines/win32-conda-CI.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ jobs:
5656
python -m pip install --upgrade pip numpy
5757
echo Test numpy installation... && python -c "import numpy"
5858
python -m pip install %COREML_PATH% %ONNX_PATH%
59+
python -m pip install tensorflow-cpu==1.15.0
60+
python -m pip install tf2onnx
5961
python -m pip install git+https://github.com/microsoft/onnxconverter-common
62+
python -m pip install git+https://github.com/onnx/keras-onnx
6063
echo Test onnxconverter-common installation... && python -c "import onnxconverter_common"
6164
python -m pip install -r requirements.txt
6265
python -m pip install -r requirements-dev.txt

tests/utils/test_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
Tests utilities.
33
"""
44
import os
5+
import six
56
import unittest
7+
import onnxmltools
68
from onnxmltools.utils import load_model, save_model
79
from onnxmltools.utils import set_model_version, set_model_domain, set_model_doc_string
810

@@ -53,5 +55,21 @@ def test_set_docstring_blank(self):
5355
self.assertEqual(onnx_model.doc_string, "")
5456

5557

58+
@unittest.skipIf(six.PY2, "Keras and Tensorflow converter not support python 2.x")
59+
class TestWrapper(unittest.TestCase):
60+
61+
def test_keras_with_tf2onnx(self):
62+
import keras2onnx
63+
from keras2onnx.proto import keras
64+
from keras2onnx.proto.tfcompat import is_tf2
65+
if not is_tf2: # tf2onnx is not available for tensorflow 2.0 yet.
66+
model = keras.Sequential()
67+
model.add(keras.layers.Dense(units=4, input_shape=(10,), activation='relu'))
68+
model.compile(loss='binary_crossentropy', optimizer='Adam', metrics=['binary_accuracy'])
69+
graph_def = keras2onnx.export_tf_frozen_graph(model)
70+
onnx_model = onnxmltools.convert_tensorflow(graph_def, **keras2onnx.build_io_names_tf2onnx(model))
71+
self.assertTrue(len(onnx_model.graph.node) > 0)
72+
73+
5674
if __name__ == "__main__":
5775
unittest.main()

0 commit comments

Comments
 (0)