File tree Expand file tree Collapse file tree 9 files changed +40
-19
lines changed
tests/keras2onnx_unit_tests Expand file tree Collapse file tree 9 files changed +40
-19
lines changed Original file line number Diff line number Diff line change 58
58
pip install numpy==1.19.0
59
59
else
60
60
pip install transformers
61
+ pip install tf_keras
61
62
pip install "numpy<2"
62
63
fi
63
64
71
72
run : |
72
73
python -c "import onnxruntime"
73
74
pytest tests/keras2onnx_unit_tests --doctest-modules --junitxml=junit/test-results.xml
75
+
76
+ export TF_USE_LEGACY_KERAS=True
74
77
cd tests/keras2onnx_applications/nightly_build
75
78
python run_all_v2.py
Original file line number Diff line number Diff line change 36
36
if [[ ${{ inputs.tf_version }} == 1.* ]]; then
37
37
pip install numpy==1.19.0
38
38
else
39
+ pip install tf_keras
39
40
pip install "numpy<2"
40
41
fi
41
42
48
49
shell : bash
49
50
if : runner.os == 'Linux'
50
51
run : |
52
+ export TF_USE_LEGACY_KERAS=True
51
53
python -c "import onnxruntime"
52
54
python -c "import onnxconverter_common"
53
55
pytest tests/keras2onnx_unit_tests --doctest-modules --junitxml=junit/test-results.xml
Original file line number Diff line number Diff line change 46
46
export TF2ONNX_SKIP_TFLITE_TESTS=${{ inputs.skip_tflite }}
47
47
export TF2ONNX_SKIP_TFJS_TESTS=True
48
48
export TF2ONNX_SKIP_TF_TESTS=False
49
+ export TF_USE_LEGACY_KERAS=True
49
50
python -m pytest --cov=tf2onnx --cov-report=term --disable-pytest-warnings -r s tests --cov-append --junitxml=junit/test-results.xml
50
51
ls
51
52
58
59
set TF2ONNX_SKIP_TFLITE_TESTS=${{ inputs.skip_tflite }}
59
60
set TF2ONNX_SKIP_TFJS_TESTS=True
60
61
set TF2ONNX_SKIP_TF_TESTS=False
62
+ set TF_USE_LEGACY_KERAS=True
61
63
python -m pytest --cov=tf2onnx --cov-report=term --disable-pytest-warnings -r s tests --cov-append --junitxml=junit/test-results.xml
62
64
ls
Original file line number Diff line number Diff line change @@ -48,10 +48,10 @@ jobs:
48
48
- name : Checkout code
49
49
uses : actions/checkout@v4
50
50
51
- - name : Run Tests (Py310-TF2.15 )
51
+ - name : Run Tests (Py310-TF2.18 )
52
52
uses : ./.github/actions/keras_application_test
53
53
with :
54
- tf_version : ' 2.15 .0'
54
+ tf_version : ' 2.18 .0'
55
55
python_version : ' 3.10'
56
56
ort_version : ' 1.16.3'
57
57
onnx_version : ' 1.16.1'
60
60
if : always()
61
61
uses : actions/upload-artifact@v4
62
62
with :
63
- name : Test Results (Py310-TF2.15 -ubuntu)
63
+ name : Test Results (Py310-TF2.18 -ubuntu)
64
64
path : ./**/test-results-*.xml
65
65
66
66
Test_py37_with_tf1_15 : # Do not change this name because it is used in Ruleset of this repo.
Original file line number Diff line number Diff line change @@ -47,10 +47,10 @@ jobs:
47
47
- name : Checkout code
48
48
uses : actions/checkout@v4
49
49
50
- - name : Run Tests (Py310-TF2.15 )
50
+ - name : Run Tests (Py310-TF2.18 )
51
51
uses : ./.github/actions/keras_unit_test
52
52
with :
53
- tf_version : ' 2.15 .0'
53
+ tf_version : ' 2.18 .0'
54
54
python_version : ' 3.10'
55
55
ort_version : ' 1.16.3'
56
56
onnx_version : ' 1.16.1'
59
59
if : always()
60
60
uses : actions/upload-artifact@v4
61
61
with :
62
- name : Test Results (Py310-TF2.15 -ubuntu)
62
+ name : Test Results (Py310-TF2.18 -ubuntu)
63
63
path : ./**/test-results-*.xml
64
64
65
65
Test_py37_with_tf1_15 : # Do not change this name because it is used in Ruleset of this repo.
Original file line number Diff line number Diff line change @@ -51,11 +51,11 @@ jobs:
51
51
- name : Checkout code
52
52
uses : actions/checkout@v4
53
53
54
- - name : Run Tests (Py310-TF2.15 -18)
54
+ - name : Run Tests (Py310-TF2.18 -18)
55
55
uses : ./.github/actions/pretrained_model_test
56
56
with :
57
57
os : ' ubuntu-latest'
58
- tf_version : ' 2.15 .0'
58
+ tf_version : ' 2.18 .0'
59
59
python_version : ' 3.10'
60
60
ort_version : ' 1.16.3'
61
61
onnx_version : ' 1.16.1'
66
66
if : always()
67
67
uses : actions/upload-artifact@v4
68
68
with :
69
- name : Test Results (Py310-TF2.15 -18-ubuntu)
69
+ name : Test Results (Py310-TF2.18 -18-ubuntu)
70
70
path : ./**/test-results-*.xml
71
71
72
72
Test_py37_with_tf1_15 : # Do not change this name because it is used in 'publish-test-results' section below.
Original file line number Diff line number Diff line change @@ -51,11 +51,11 @@ jobs:
51
51
- name : Checkout code
52
52
uses : actions/checkout@v4
53
53
54
- - name : Run Tests (Py310-TF2.15 -18)
54
+ - name : Run Tests (Py310-TF2.18 -18)
55
55
uses : ./.github/actions/unit_test
56
56
with :
57
57
os : ' ubuntu-latest'
58
- tf_version : ' 2.15 .0'
58
+ tf_version : ' 2.18 .0'
59
59
python_version : ' 3.10'
60
60
ort_version : ' 1.16.3'
61
61
onnx_version : ' 1.16.1'
66
66
if : always()
67
67
uses : actions/upload-artifact@v4
68
68
with :
69
- name : Test Results (Py310-TF2.15 -18-ubuntu)
69
+ name : Test Results (Py310-TF2.18 -18-ubuntu)
70
70
path : ./**/test-results-*.xml
71
71
72
72
Extra_tests :
Original file line number Diff line number Diff line change 13
13
K = keras .backend
14
14
15
15
16
+ def is_keras_3 ():
17
+ if hasattr (keras , '__version__' ):
18
+ return keras .__version__ .startswith ("3." )
19
+
20
+ return False
21
+
16
22
@pytest .fixture (scope = 'function' )
17
23
def runner ():
18
24
np .random .seed (42 )
@@ -25,12 +31,19 @@ def runner():
25
31
def runner_func (* args , ** kwargs ):
26
32
return run_onnx_runtime (* args , model_files , ** kwargs )
27
33
28
- # Ensure Keras layer naming is reset for each function
29
- if hasattr (K , "reset_uids" ):
30
- # see https://github.com/onnx/tensorflow-onnx/issues/2370
31
- K .reset_uids ()
32
- # Reset the TensorFlow session to avoid resource leaking between tests
33
- K .clear_session ()
34
+ if is_keras_3 ():
35
+ import tf_keras
36
+ if hasattr (K , "reset_uids" ):
37
+ # see https://github.com/onnx/tensorflow-onnx/issues/2370
38
+ K .reset_uids ()
39
+ tf_keras .backend .clear_session ()
40
+ else :
41
+ # Ensure Keras layer naming is reset for each function
42
+ if hasattr (K , "reset_uids" ):
43
+ # see https://github.com/onnx/tensorflow-onnx/issues/2370
44
+ K .reset_uids ()
45
+ # Reset the TensorFlow session to avoid resource leaking between tests
46
+ K .clear_session ()
34
47
35
48
# Provide wrapped run_onnx_runtime function
36
49
yield runner_func
Original file line number Diff line number Diff line change @@ -328,7 +328,8 @@ def _rename_duplicate_keras_model_names(model):
328
328
IMPORTANT: model may be edited. Assign model.output_names to old_out_names to restore.
329
329
"""
330
330
old_out_names = None
331
- if model .output_names and len (set (model .output_names )) != len (model .output_names ):
331
+ if hasattr (model , "output_names" ) and model .output_names \
332
+ and len (set (model .output_names )) != len (model .output_names ):
332
333
# In very rare cases, keras has a bug where it will give multiple outputs the same name
333
334
# We must edit the model or the TF trace will fail
334
335
old_out_names = model .output_names
You can’t perform that action at this time.
0 commit comments