Skip to content

Commit e3ce446

Browse files
Add windows keras2onnx applications tests (#1598)
* Add windows keras2onnx applications tests Signed-off-by: Tom Wildenhain <[email protected]> * Update tf versions Signed-off-by: Tom Wildenhain <[email protected]>
1 parent 448d61d commit e3ce446

File tree

9 files changed

+113
-6
lines changed

9 files changed

+113
-6
lines changed

ci_build/azure_pipelines/keras2onnx_application_tests.yml

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
jobs:
77

8-
- job: 'Test'
8+
- job: 'Linux'
99
timeoutInMinutes: 180
1010
pool:
1111
vmImage: 'Ubuntu-16.04'
@@ -110,3 +110,99 @@ jobs:
110110
testResultsFiles: '**/test-results-*.xml'
111111
testRunTitle: 'Python $(python.version)'
112112
condition: succeededOrFailed()
113+
114+
- job: 'Win'
115+
timeoutInMinutes: 180
116+
pool:
117+
vmImage: 'vs2017-win2016'
118+
strategy:
119+
matrix:
120+
Python36-onnx1.5:
121+
python.version: '3.6'
122+
ONNX_PATH: onnx==1.5.0
123+
INSTALL_KERAS: pip install keras==2.2.4
124+
UNINSTALL_KERAS:
125+
INSTALL_TENSORFLOW: pip install tensorflow==1.15.0
126+
INSTALL_ORT: pip install onnxruntime==1.8.0
127+
INSTALL_KERAS_RESNET: pip install keras-resnet
128+
INSTALL_TRANSFORMERS:
129+
NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py test_mask_rcnn.py"
130+
131+
Python37-onnx1.6:
132+
python.version: '3.7'
133+
ONNX_PATH: onnx==1.6.0
134+
INSTALL_KERAS: pip install keras==2.3.1
135+
UNINSTALL_KERAS:
136+
INSTALL_TENSORFLOW: pip install tensorflow==1.15.0
137+
INSTALL_ORT: pip install onnxruntime==1.8.0
138+
INSTALL_KERAS_RESNET: pip install keras-resnet
139+
INSTALL_TRANSFORMERS:
140+
NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py test_mask_rcnn.py"
141+
142+
Python37-onnx1.9:
143+
python.version: '3.7'
144+
ONNX_PATH: onnx==1.9.0
145+
INSTALL_KERAS: pip install keras==2.3.1
146+
UNINSTALL_KERAS:
147+
INSTALL_TENSORFLOW: pip install tensorflow==1.15.0
148+
INSTALL_ORT: pip install onnxruntime==1.8.0
149+
INSTALL_KERAS_RESNET: pip install keras-resnet
150+
INSTALL_TRANSFORMERS:
151+
NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py test_mask_rcnn.py"
152+
153+
steps:
154+
- task: UsePythonVersion@0
155+
inputs:
156+
versionSpec: '$(python.version)'
157+
architecture: 'x64'
158+
159+
- powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts"
160+
displayName: Add conda to PATH
161+
162+
- script: conda create --yes --quiet --name py$(python.version) -c conda-forge python=$(python.version) numpy protobuf
163+
displayName: Create Anaconda environment
164+
165+
- script: |
166+
call activate py$(python.version)
167+
python -m pip install --upgrade pip numpy
168+
echo Test numpy installation... && python -c "import numpy"
169+
pip install %ONNX_PATH%
170+
pip uninstall -y protobuf
171+
pip install protobuf
172+
pip install h5py==2.9.0
173+
pip install numpy==1.19
174+
pip install parameterized
175+
%INSTALL_TENSORFLOW%
176+
%INSTALL_KERAS%
177+
pip install git+https://github.com/microsoft/onnxconverter-common
178+
%INSTALL_ORT%
179+
pip install Pillow==8.2.0
180+
pip install opencv-python
181+
pip install tqdm
182+
pip install keras-segmentation==0.2.0
183+
pip install matplotlib
184+
git clone https://github.com/qqwweee/keras-yolo3
185+
%INSTALL_KERAS_RESNET%
186+
pip install git+https://www.github.com/keras-team/keras-contrib.git
187+
pip install keras-tcn==2.8.3
188+
%UNINSTALL_KERAS%
189+
pip install git+https://github.com/qubvel/efficientnet
190+
%INSTALL_TRANSFORMERS%
191+
pip install keras-self-attention
192+
pip install pytest pytest-cov pytest-runner
193+
displayName: 'Install dependencies'
194+
195+
- script: |
196+
call activate py$(python.version)
197+
pip install -e .
198+
echo Test onnxruntime installation... && python -c "import onnxruntime"
199+
pytest tests/keras2onnx_unit_tests --doctest-modules --junitxml=junit/test-results.xml
200+
cd tests/keras2onnx_applications/nightly_build
201+
%NIGHTLY_BUILD_TEST%
202+
displayName: 'pytest'
203+
204+
- task: PublishTestResults@2
205+
inputs:
206+
testResultsFiles: '**/test-results-*.xml'
207+
testRunTitle: 'Python $(python.version)'
208+
condition: succeededOrFailed()

ci_build/azure_pipelines/templates/unit_test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ steps:
1212
export TF2ONNX_TEST_OPSET=$CI_ONNX_OPSET
1313
export TF2ONNX_SKIP_TFLITE_TESTS=$CI_SKIP_TFLITE_TESTS
1414
export TF2ONNX_SKIP_TF_TESTS=$CI_SKIP_TF_TESTS
15-
python -m pytest --cov=tf2onnx --cov-report=term --disable-pytest-warnings -r s tests --cov-append \
16-
--ignore tests/keras2onnx_unit_tests --ignore tests/keras2onnx_applications
15+
python -m pytest --cov=tf2onnx --cov-report=term --disable-pytest-warnings -r s tests --cov-append
1716
timeoutInMinutes: 15
1817
displayName: ${{ format('Run UnitTest - Opset{0}', onnx_opset) }}
1918
condition: succeededOrFailed()

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ test=pytest
55

66
[tool:pytest]
77
addopts=--cov=tf2onnx
8+
norecursedirs=tests/keras2onnx_applications tests/keras2onnx_unit_tests

tests/keras2onnx_applications/nightly_build/run_all.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
os.environ["PYTHONPATH"] = \
1414
os.environ.get("PYTHONPATH", "") + os.pathsep + "../../keras2onnx_unit_tests" + os.pathsep + "../../../"
15+
os.environ["TF2ONNX_CATCH_ERRORS"] = "FALSE"
1516

1617
mypath = '.'
1718
files = [f for f in listdir(mypath) if isfile(join(mypath, f)) and f.find("test_") == 0]

tests/keras2onnx_applications/nightly_build/run_all_v2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
os.environ["PYTHONPATH"] = \
55
os.environ.get("PYTHONPATH", "") + os.pathsep + "../../keras2onnx_unit_tests" + os.pathsep + "../../../"
6+
os.environ["TF2ONNX_CATCH_ERRORS"] = "FALSE"
67

78
files = ['test_keras_applications_v2.py', 'test_transformers.py', 'test_chatbot.py', 'test_efn.py', \
89
'test_resnext.py']

tests/keras2onnx_unit_tests/conftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44
import pytest
55

66
import numpy as np
7+
import tensorflow as tf
78

8-
from mock_keras2onnx.proto import keras
9+
from mock_keras2onnx.proto import keras, is_tf_keras
910
from test_utils import run_onnx_runtime
11+
from mock_keras2onnx.proto.tfcompat import is_tf2
1012

1113
K = keras.backend
1214

1315

1416
@pytest.fixture(scope='function')
1517
def runner():
1618
np.random.seed(42)
19+
if is_tf_keras and is_tf2:
20+
tf.random.set_seed(42)
1721
model_files = []
1822

1923
def runner_func(*args, **kwargs):

tf2onnx/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
# Environment variables
4545
ENV_TF2ONNX_DEBUG_MODE = "TF2ONNX_DEBUG_MODE"
46+
ENV_TF2ONNX_CATCH_ERRORS = "TF2ONNX_CATCH_ERRORS"
4647

4748
# Mapping opset to IR version.
4849
# Note: opset 7 and opset 8 came out with IR3 but we need IR4 because of PlaceholderWithDefault

tf2onnx/convert.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ def _convert_common(frozen_graph, name="unknown", large_model=False, output_path
152152
if not kwargs.get("tflite_path"):
153153
tf.import_graph_def(frozen_graph, name='')
154154
g = process_tf_graph(tf_graph, const_node_values=const_node_values, **kwargs)
155-
onnx_graph = optimizer.optimize_graph(g, catch_errors=not large_model)
155+
if constants.ENV_TF2ONNX_CATCH_ERRORS in os.environ:
156+
catch_errors = constants.ENV_TF2ONNX_CATCH_ERRORS.upper() == "TRUE"
157+
else:
158+
catch_errors = not large_model
159+
onnx_graph = optimizer.optimize_graph(g, catch_errors)
156160
model_proto = onnx_graph.make_model("converted from {}".format(name),
157161
external_tensor_storage=external_tensor_storage)
158162
if output_path:

tf2onnx/optimizer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _get_optimizers():
4343

4444

4545
def optimize_graph(graph, catch_errors=True, optimizers=None):
46-
""" Optimize graph, return optimized graph. No throw if catch_errors is true"""
46+
""" Optimize graph, return optimized graph. Catch errors and restore old graph if catch_errors is True"""
4747
logger = logging.getLogger(__name__)
4848
logger.info("Optimizing ONNX model")
4949

0 commit comments

Comments
 (0)