Skip to content

Commit 3cf62e2

Browse files
authored
Update Keras related tests to support latest TF version. (#1980)
* Update all Keras related tests to support latest TF version. Signed-off-by: Jay Zhang <[email protected]>
1 parent 7a57a6b commit 3cf62e2

File tree

7 files changed

+92
-80
lines changed

7 files changed

+92
-80
lines changed

ci_build/azure_pipelines/keras2onnx_application_tests.yml

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,6 @@ jobs:
88
vmImage: 'ubuntu-latest'
99
strategy:
1010
matrix:
11-
Python37-onnx1.5:
12-
python.version: '3.7'
13-
ONNX_PATH: onnx==1.5.0
14-
INSTALL_KERAS: pip install keras==2.2.4
15-
UNINSTALL_KERAS:
16-
INSTALL_TENSORFLOW: pip install tensorflow==1.15.0
17-
INSTALL_ORT: pip install onnxruntime==1.8.0
18-
INSTALL_KERAS_RESNET: pip install keras-resnet
19-
INSTALL_TRANSFORMERS:
20-
INSTALL_NUMPY:
21-
NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py"
22-
2311
Python37-onnx1.6:
2412
python.version: '3.7'
2513
ONNX_PATH: onnx==1.6.0
@@ -44,7 +32,7 @@ jobs:
4432
INSTALL_NUMPY:
4533
NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py"
4634

47-
Python37-onnx1.11:
35+
Python37-onnx1.11-tf1.15:
4836
python.version: '3.7'
4937
ONNX_PATH: onnx==1.11.0
5038
INSTALL_KERAS: pip install keras==2.3.1
@@ -56,18 +44,30 @@ jobs:
5644
INSTALL_NUMPY: pip install numpy==1.19.0
5745
NIGHTLY_BUILD_TEST: python run_all_v2.py --exclude "test_keras_applications_v2.py"
5846

59-
Python38-tf2.x:
60-
python.version: '3.8'
47+
Python37-onnx1.11-tf2.5:
48+
python.version: '3.7'
6149
ONNX_PATH: onnx==1.11.0
62-
INSTALL_KERAS:
50+
INSTALL_KERAS:
6351
UNINSTALL_KERAS: pip uninstall keras -y
6452
INSTALL_TENSORFLOW: pip install tensorflow==2.5.0
65-
INSTALL_ORT: pip install onnxruntime==1.9.0
53+
INSTALL_ORT: pip install onnxruntime==1.11.0
6654
INSTALL_KERAS_RESNET: pip install keras-resnet
6755
INSTALL_TRANSFORMERS: pip install transformers==3.4.0
6856
INSTALL_NUMPY: pip install numpy==1.19.0
6957
NIGHTLY_BUILD_TEST: python run_all_v2.py
7058

59+
Python38-onnx1.11-tf2.8:
60+
python.version: '3.7'
61+
ONNX_PATH: onnx==1.11.0
62+
INSTALL_KERAS:
63+
UNINSTALL_KERAS:
64+
INSTALL_TENSORFLOW: pip install tensorflow==2.8.0
65+
INSTALL_ORT: pip install onnxruntime==1.11.0
66+
INSTALL_KERAS_RESNET: pip install keras-resnet
67+
INSTALL_TRANSFORMERS: pip install transformers==3.4.0
68+
INSTALL_NUMPY:
69+
NIGHTLY_BUILD_TEST: python run_all_v2.py
70+
7171
steps:
7272
- template: 'templates/keras2onnx_application_tests.yml'
7373
parameters:
@@ -79,17 +79,6 @@ jobs:
7979
vmImage: 'windows-2019'
8080
strategy:
8181
matrix:
82-
Python37-onnx1.5:
83-
python.version: '3.7'
84-
ONNX_PATH: onnx==1.5.0
85-
INSTALL_KERAS: pip install keras==2.2.4
86-
UNINSTALL_KERAS:
87-
INSTALL_TENSORFLOW: pip install tensorflow==1.15.0
88-
INSTALL_ORT: pip install onnxruntime==1.8.0
89-
INSTALL_KERAS_RESNET: pip install keras-resnet
90-
INSTALL_TRANSFORMERS:
91-
NIGHTLY_BUILD_TEST: python run_all_v2.py --exclude "test_keras_applications_v2.py"
92-
9382
Python37-onnx1.6:
9483
python.version: '3.7'
9584
ONNX_PATH: onnx==1.6.0
@@ -114,7 +103,7 @@ jobs:
114103
INSTALL_NUMPY: pip install numpy==1.19.0
115104
NIGHTLY_BUILD_TEST: python run_all_v2.py --exclude "test_keras_applications_v2.py"
116105

117-
Python37-onnx1.11:
106+
Python37-onnx1.11-tf1.15:
118107
python.version: '3.7'
119108
ONNX_PATH: onnx==1.11.0
120109
INSTALL_KERAS: pip install keras==2.3.1
@@ -129,7 +118,7 @@ jobs:
129118
Python38-tf2.x:
130119
python.version: '3.8'
131120
ONNX_PATH: onnx==1.11.0
132-
INSTALL_KERAS:
121+
INSTALL_KERAS:
133122
UNINSTALL_KERAS: pip uninstall keras -y
134123
INSTALL_TENSORFLOW: pip install tensorflow==2.5.0
135124
INSTALL_ORT: pip install onnxruntime==1.9.0

ci_build/azure_pipelines/keras2onnx_unit_test.yml

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ jobs:
1616
INSTALL_ORT: pip install onnxruntime==1.9.0
1717
INSTALL_NUMPY: pip install numpy==1.19.0
1818

19-
Python37-tf2.1:
20-
python.version: '3.7'
21-
ONNX_PATH: onnx==1.11.0
22-
TENSORFLOW_PATH: tensorflow-cpu==2.1.0
23-
INSTALL_ORT: pip install onnxruntime==1.11.0
24-
INSTALL_NUMPY: pip install numpy==1.19.0
25-
2619
Python38-tf2.2:
2720
python.version: '3.8'
2821
ONNX_PATH: onnx==1.11.0
@@ -44,14 +37,14 @@ jobs:
4437
INSTALL_ORT: pip install onnxruntime==1.11.0
4538
INSTALL_NUMPY: pip install numpy==1.19.0
4639

47-
############ Pure Keras Unit Tests ############
48-
Keras-Py37-tf1.15.0:
49-
python.version: '3.7'
50-
ONNX_PATH: onnx==1.10.2
51-
KERAS: keras==2.2.5
52-
TENSORFLOW_PATH: tensorflow==1.15.0
53-
INSTALL_ORT: pip install onnxruntime==1.9.0
40+
Python38-tf2.8:
41+
python.version: '3.8'
42+
ONNX_PATH: onnx==1.11.0
43+
TENSORFLOW_PATH: tensorflow-cpu==2.8.0
44+
INSTALL_ORT: pip install onnxruntime==1.11.0
45+
INSTALL_NUMPY:
5446

47+
############ Pure Keras Unit Tests ############
5548
Keras-Py37-tf1.15.0:
5649
python.version: '3.7'
5750
ONNX_PATH: onnx==1.11.0
@@ -93,12 +86,6 @@ jobs:
9386
ONNX_PATH: onnx==1.10.2
9487
TENSORFLOW_PATH: tensorflow==1.15.0
9588
INSTALL_ORT: pip install onnxruntime==1.9.0
96-
97-
Python37-tf2.1:
98-
python.version: '3.7'
99-
ONNX_PATH: onnx==1.11.0
100-
TENSORFLOW_PATH: tensorflow-cpu==2.1.0
101-
INSTALL_ORT: pip install onnxruntime==1.11.0
10289
INSTALL_NUMPY: pip install numpy==1.19.0
10390

10491
Python37-tf2.2:
@@ -122,6 +109,13 @@ jobs:
122109
INSTALL_ORT: pip install onnxruntime==1.11.0
123110
INSTALL_NUMPY: pip install numpy==1.19.0
124111

112+
Python37-tf2.8:
113+
python.version: '3.8'
114+
ONNX_PATH: onnx==1.11.0
115+
TENSORFLOW_PATH: tensorflow-cpu==2.8.0
116+
INSTALL_ORT: pip install onnxruntime==1.11.0
117+
INSTALL_NUMPY:
118+
125119
############ Pure Keras Unit Tests ############
126120
Keras-Py37-tf1.15.0:
127121
python.version: '3.7'

ci_build/azure_pipelines/templates/keras2onnx_unit_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ steps:
6969

7070
- script: |
7171
call activate py$(python.version)
72-
python -m pip install --upgrade pip numpy==1.19
72+
python -m pip install --upgrade pip numpy
7373
echo Test numpy installation... && python -c "import numpy"
7474
pip install %ONNX_PATH%
7575
pip uninstall -y protobuf

ci_build/azure_pipelines/trimmed_keras2onnx_application_tests.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@ jobs:
1010
matrix:
1111
Python37-onnx1.10:
1212
python.version: '3.7'
13-
ONNX_PATH: onnx==1.10.2
13+
ONNX_PATH: onnx==1.11.0
1414
INSTALL_KERAS: pip install keras==2.2.4
1515
UNINSTALL_KERAS:
1616
INSTALL_TENSORFLOW: pip install tensorflow==1.15.0
17-
INSTALL_ORT: pip install onnxruntime==1.9.0
17+
INSTALL_ORT: pip install onnxruntime==1.11.0
1818
INSTALL_KERAS_RESNET: pip install keras-resnet
1919
INSTALL_TRANSFORMERS:
2020
INSTALL_NUMPY: pip install numpy==1.19.0
2121
NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py"
2222

23-
Python38-tf2:
23+
Python38-tf2.x:
2424
python.version: '3.8'
2525
ONNX_PATH: onnx==1.11.0
2626
INSTALL_KERAS:
27-
UNINSTALL_KERAS: pip uninstall keras -y
28-
INSTALL_TENSORFLOW: pip install tensorflow==2.5.0
27+
UNINSTALL_KERAS:
28+
INSTALL_TENSORFLOW: pip install tensorflow==2.9.0
2929
INSTALL_ORT: pip install onnxruntime==1.11.0
3030
INSTALL_KERAS_RESNET: pip install keras-resnet
3131
INSTALL_TRANSFORMERS: pip install transformers==3.4.0
32-
INSTALL_NUMPY: pip install numpy==1.19.0
32+
INSTALL_NUMPY:
3333
NIGHTLY_BUILD_TEST: python run_all_v2.py
3434

3535
steps:

ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ jobs:
1111
############ TF Keras Unit Tests ############
1212
Python37-tf1.15:
1313
python.version: '3.7'
14-
ONNX_PATH: onnx==1.10.2
14+
ONNX_PATH: onnx==1.11.0
1515
TENSORFLOW_PATH: tensorflow==1.15.0
16-
INSTALL_ORT: pip install onnxruntime==1.9.0
16+
INSTALL_ORT: pip install onnxruntime==1.11.0
1717
INSTALL_NUMPY: pip install numpy==1.19.0
1818

19-
Python38-tf2.5:
19+
Python38-tf2.9:
2020
python.version: '3.8'
2121
ONNX_PATH: onnx==1.11.0
22-
TENSORFLOW_PATH: tensorflow-cpu==2.5.0
22+
TENSORFLOW_PATH: tensorflow-cpu==2.9.0
2323
INSTALL_ORT: pip install onnxruntime==1.11.0
24-
INSTALL_NUMPY: pip install numpy==1.19.0
24+
INSTALL_NUMPY:
2525

2626
############ Pure Keras Unit Tests ############
2727
Keras-Py37-tf1.15.0:
@@ -41,6 +41,13 @@ jobs:
4141
INSTALL_ORT: pip install onnxruntime==1.11.0
4242
INSTALL_NUMPY: pip install numpy==1.19.0
4343

44+
Keras-Py38-tf2.9.0:
45+
python.version: '3.8'
46+
ONNX_PATH: -i onnx==1.11.0
47+
TENSORFLOW_PATH: tensorflow==2.9.0
48+
INSTALL_ORT: pip install onnxruntime==1.11.0
49+
INSTALL_NUMPY:
50+
4451
steps:
4552
- template: 'templates/keras2onnx_unit_test.yml'
4653
parameters:
@@ -54,9 +61,9 @@ jobs:
5461
############ TF Keras Unit Tests ############
5562
Python37-tf-1.15:
5663
python.version: '3.7'
57-
ONNX_PATH: onnx==1.10.2
64+
ONNX_PATH: onnx==1.11.0
5865
TENSORFLOW_PATH: tensorflow==1.15.0
59-
INSTALL_ORT: pip install onnxruntime==1.9.0
66+
INSTALL_ORT: pip install onnxruntime==1.11.0
6067
INSTALL_NUMPY: pip install numpy==1.19.0
6168

6269
Python37-tf2.3:
@@ -66,6 +73,13 @@ jobs:
6673
INSTALL_ORT: pip install onnxruntime==1.11.0
6774
INSTALL_NUMPY: pip install numpy==1.19.0
6875

76+
Python38-tf2.9:
77+
python.version: '3.8'
78+
ONNX_PATH: onnx==1.11.0
79+
TENSORFLOW_PATH: tensorflow-cpu==2.9.0
80+
INSTALL_ORT: pip install onnxruntime==1.11.0
81+
INSTALL_NUMPY:
82+
6983
############ Pure Keras Unit Tests ############
7084
Keras-Py37-tf2.2.0:
7185
python.version: '3.7'

tests/keras2onnx_unit_tests/mock_keras2onnx/proto/__init__.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44
import tensorflow
5-
from distutils.version import StrictVersion
5+
from packaging.version import Version
66

77
# Rather than using ONNX protobuf definition throughout our codebase, we import ONNX protobuf definition here so that
88
# we can conduct quick fixes by overwriting ONNX functions without changing any lines elsewhere.
@@ -22,11 +22,15 @@ def _check_onnx_version():
2222

2323

2424
def is_tensorflow_older_than(version_str):
25-
return StrictVersion(tensorflow.__version__.split('-')[0]) < StrictVersion(version_str)
25+
return Version(tensorflow.__version__.split('-')[0]) < Version(version_str)
2626

2727

2828
def is_tensorflow_later_than(version_str):
29-
return StrictVersion(tensorflow.__version__.split('-')[0]) > StrictVersion(version_str)
29+
return Version(tensorflow.__version__.split('-')[0]) > Version(version_str)
30+
31+
32+
def python_keras_is_deprecated():
33+
return is_tensorflow_later_than("2.5.0")
3034

3135

3236
is_tf_keras = False
@@ -38,7 +42,10 @@ def is_tensorflow_later_than(version_str):
3842
is_tf_keras = str_tk_keras != '0'
3943

4044
if is_tf_keras:
41-
from tensorflow.python import keras
45+
if python_keras_is_deprecated():
46+
from tensorflow import keras
47+
else:
48+
from tensorflow.python import keras
4249
else:
4350
try:
4451
import keras
@@ -47,12 +54,15 @@ def is_tensorflow_later_than(version_str):
4754
is_tf_keras = True
4855
except ImportError:
4956
is_tf_keras = True
50-
from tensorflow.python import keras
57+
if python_keras_is_deprecated():
58+
from tensorflow import keras
59+
else:
60+
from tensorflow.python import keras
5161

5262

5363
def is_keras_older_than(version_str):
54-
return StrictVersion(keras.__version__.split('-')[0]) < StrictVersion(version_str)
64+
return Version(keras.__version__.split('-')[0]) < Version(version_str)
5565

5666

5767
def is_keras_later_than(version_str):
58-
return StrictVersion(keras.__version__.split('-')[0]) > StrictVersion(version_str)
68+
return Version(keras.__version__.split('-')[0]) > Version(version_str)

0 commit comments

Comments
 (0)