Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try tf 2.18.0 version. #2377

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/actions/keras_application_test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ runs:
pip install numpy==1.19.0
else
pip install transformers
pip install tf_keras
pip install "numpy<2"
fi

Expand All @@ -71,5 +72,7 @@ runs:
run: |
python -c "import onnxruntime"
pytest tests/keras2onnx_unit_tests --doctest-modules --junitxml=junit/test-results.xml

export TF_USE_LEGACY_KERAS=True
cd tests/keras2onnx_applications/nightly_build
python run_all_v2.py
2 changes: 2 additions & 0 deletions .github/actions/keras_unit_test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ runs:
if [[ ${{ inputs.tf_version }} == 1.* ]]; then
pip install numpy==1.19.0
else
pip install tf_keras
pip install "numpy<2"
fi
Expand All @@ -48,6 +49,7 @@ runs:
shell: bash
if: runner.os == 'Linux'
run: |
export TF_USE_LEGACY_KERAS=True
python -c "import onnxruntime"
python -c "import onnxconverter_common"
pytest tests/keras2onnx_unit_tests --doctest-modules --junitxml=junit/test-results.xml
2 changes: 2 additions & 0 deletions .github/actions/unit_test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ runs:
export TF2ONNX_SKIP_TFLITE_TESTS=${{ inputs.skip_tflite }}
export TF2ONNX_SKIP_TFJS_TESTS=True
export TF2ONNX_SKIP_TF_TESTS=False
export TF_USE_LEGACY_KERAS=True
python -m pytest --cov=tf2onnx --cov-report=term --disable-pytest-warnings -r s tests --cov-append --junitxml=junit/test-results.xml
ls
Expand All @@ -58,5 +59,6 @@ runs:
set TF2ONNX_SKIP_TFLITE_TESTS=${{ inputs.skip_tflite }}
set TF2ONNX_SKIP_TFJS_TESTS=True
set TF2ONNX_SKIP_TF_TESTS=False
set TF_USE_LEGACY_KERAS=True
python -m pytest --cov=tf2onnx --cov-report=term --disable-pytest-warnings -r s tests --cov-append --junitxml=junit/test-results.xml
ls
6 changes: 3 additions & 3 deletions .github/workflows/keras_application_test_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Run Tests (Py310-TF2.15)
- name: Run Tests (Py310-TF2.18)
uses: ./.github/actions/keras_application_test
with:
tf_version: '2.15.0'
tf_version: '2.18.0'
python_version: '3.10'
ort_version: '1.16.3'
onnx_version: '1.16.1'
Expand All @@ -60,7 +60,7 @@ jobs:
if: always()
uses: actions/upload-artifact@v3
with:
name: Test Results (Py310-TF2.15-ubuntu)
name: Test Results (Py310-TF2.18-ubuntu)
path: ./**/test-results-*.xml

Test_py37_with_tf1_15: # Do not change this name because it is used in Ruleset of this repo.
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/keras_unit_test_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Run Tests (Py310-TF2.15)
- name: Run Tests (Py310-TF2.18)
uses: ./.github/actions/keras_unit_test
with:
tf_version: '2.15.0'
tf_version: '2.18.0'
python_version: '3.10'
ort_version: '1.16.3'
onnx_version: '1.16.1'
Expand All @@ -59,7 +59,7 @@ jobs:
if: always()
uses: actions/upload-artifact@v3
with:
name: Test Results (Py310-TF2.15-ubuntu)
name: Test Results (Py310-TF2.18-ubuntu)
path: ./**/test-results-*.xml

Test_py37_with_tf1_15: # Do not change this name because it is used in Ruleset of this repo.
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pretrained_model_test_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Run Tests (Py310-TF2.15-18)
- name: Run Tests (Py310-TF2.18-18)
uses: ./.github/actions/pretrained_model_test
with:
os: 'ubuntu-latest'
tf_version: '2.15.0'
tf_version: '2.18.0'
python_version: '3.10'
ort_version: '1.16.3'
onnx_version: '1.16.1'
Expand All @@ -66,7 +66,7 @@ jobs:
if: always()
uses: actions/upload-artifact@v3
with:
name: Test Results (Py310-TF2.15-18-ubuntu)
name: Test Results (Py310-TF2.18-18-ubuntu)
path: ./**/test-results-*.xml

Test_py37_with_tf1_15: # Do not change this name because it is used in 'publish-test-results' section below.
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/unit_test_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Run Tests (Py310-TF2.15-18)
- name: Run Tests (Py310-TF2.18-18)
uses: ./.github/actions/unit_test
with:
os: 'ubuntu-latest'
tf_version: '2.15.0'
tf_version: '2.18.0'
python_version: '3.10'
ort_version: '1.16.3'
onnx_version: '1.16.1'
Expand All @@ -66,7 +66,7 @@ jobs:
if: always()
uses: actions/upload-artifact@v3
with:
name: Test Results (Py310-TF2.15-18-ubuntu)
name: Test Results (Py310-TF2.18-18-ubuntu)
path: ./**/test-results-*.xml

Extra_tests:
Expand Down
19 changes: 15 additions & 4 deletions tests/keras2onnx_unit_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
K = keras.backend


def is_keras_3():
if hasattr(keras, '__version__'):
return keras.__version__.startswith("3.")

return False

@pytest.fixture(scope='function')
def runner():
np.random.seed(42)
Expand All @@ -25,10 +31,15 @@ def runner():
def runner_func(*args, **kwargs):
return run_onnx_runtime(*args, model_files, **kwargs)

# Ensure Keras layer naming is reset for each function
K.reset_uids()
# Reset the TensorFlow session to avoid resource leaking between tests
K.clear_session()
if is_keras_3():
import tf_keras
tf_keras.backend.reset_uids()
tf_keras.backend.clear_session()
else:
# Ensure Keras layer naming is reset for each function
K.reset_uids()
# Reset the TensorFlow session to avoid resource leaking between tests
K.clear_session()

# Provide wrapped run_onnx_runtime function
yield runner_func
Expand Down
3 changes: 2 additions & 1 deletion tf2onnx/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ def _rename_duplicate_keras_model_names(model):
IMPORTANT: model may be edited. Assign model.output_names to old_out_names to restore.
"""
old_out_names = None
if model.output_names and len(set(model.output_names)) != len(model.output_names):
if hasattr(model, "output_names") and model.output_names \
and len(set(model.output_names)) != len(model.output_names):
# In very rare cases, keras has a bug where it will give multiple outputs the same name
# We must edit the model or the TF trace will fail
old_out_names = model.output_names
Expand Down
Loading