diff --git a/.github/actions/keras_application_test/action.yml b/.github/actions/keras_application_test/action.yml index 7148e417b..57c93dc42 100644 --- a/.github/actions/keras_application_test/action.yml +++ b/.github/actions/keras_application_test/action.yml @@ -58,6 +58,7 @@ runs: pip install numpy==1.19.0 else pip install transformers + pip install tf_keras pip install "numpy<2" fi @@ -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 diff --git a/.github/actions/keras_unit_test/action.yml b/.github/actions/keras_unit_test/action.yml index 4c78945f1..4888e3a7a 100644 --- a/.github/actions/keras_unit_test/action.yml +++ b/.github/actions/keras_unit_test/action.yml @@ -24,6 +24,7 @@ runs: python -m pip install --upgrade pip pip install onnxconverter-common pip install onnx==${{ inputs.onnx_version }} + pip install tf_keras pip install h5py==3.7.0 pip install parameterized pip install timeout-decorator @@ -35,7 +36,8 @@ runs: pip install "protobuf~=3.20" if [[ ${{ inputs.tf_version }} == 1.* ]]; then pip install numpy==1.19.0 - else + else + pip install tf_keras pip install "numpy<2" fi @@ -48,6 +50,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 diff --git a/.github/actions/unit_test/action.yml b/.github/actions/unit_test/action.yml index 00cb28386..ebcad6c80 100644 --- a/.github/actions/unit_test/action.yml +++ b/.github/actions/unit_test/action.yml @@ -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 @@ -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 diff --git a/.github/workflows/keras_application_test_ci.yml b/.github/workflows/keras_application_test_ci.yml index c962b1dc8..28dd4f4cb 100644 --- a/.github/workflows/keras_application_test_ci.yml +++ b/.github/workflows/keras_application_test_ci.yml @@ -24,10 +24,10 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Run Tests (Py38-TF2.9) + - name: Run Tests (Py38-TF2.12) uses: ./.github/actions/keras_application_test with: - tf_version: '2.9.0' + tf_version: '2.12.0' python_version: '3.8' ort_version: '1.16.3' onnx_version: '1.16.1' @@ -36,7 +36,7 @@ jobs: if: always() uses: actions/upload-artifact@v3 with: - name: Test Results (Py38-TF2.9-ubuntu) + name: Test Results (Py38-TF2.12-ubuntu) path: ./**/test-results-*.xml Test_max_py_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. @@ -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' @@ -60,13 +60,13 @@ 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. strategy: fail-fast: false - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Checkout code @@ -92,17 +92,17 @@ jobs: fail-fast: false matrix: name: - - 'py39-tf2.10' - - 'py39-tf2.15' + - 'py39-tf2.17' + - 'py39-tf2.18' os: ['ubuntu-latest', 'windows-2022'] ort_version: ['1.16.3'] onnx_version: ['1.16.1'] include: - - name: 'py39-tf2.10' - tf_version: '2.10.0' + - name: 'py39-tf2.17' + tf_version: '2.17.0' python_version: '3.9' - - name: 'py39-tf2.15' - tf_version: '2.15.0' + - name: 'py39-tf2.18' + tf_version: '2.18.0' python_version: '3.9' runs-on: ${{ matrix.os }} diff --git a/.github/workflows/keras_unit_test_ci.yml b/.github/workflows/keras_unit_test_ci.yml index 7ef38d79a..7ba8d0d1a 100644 --- a/.github/workflows/keras_unit_test_ci.yml +++ b/.github/workflows/keras_unit_test_ci.yml @@ -23,10 +23,10 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Run Tests (Py38-TF2.9) + - name: Run Tests (Py38-TF2.12) uses: ./.github/actions/keras_unit_test with: - tf_version: '2.9.0' + tf_version: '2.13.1' python_version: '3.8' ort_version: '1.16.3' onnx_version: '1.16.1' @@ -35,7 +35,7 @@ jobs: if: always() uses: actions/upload-artifact@v3 with: - name: Test Results (Py38-TF2.9-ubuntu) + name: Test Results (Py38-TF2.12-ubuntu) path: ./**/test-results-*.xml Test_max_py_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. @@ -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' @@ -59,13 +59,13 @@ 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. strategy: fail-fast: false - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Checkout code @@ -91,17 +91,17 @@ jobs: fail-fast: false matrix: name: - - 'py39-tf2.10' - - 'py39-tf2.15' + - 'py39-tf2.17' + - 'py39-tf2.18' os: ['ubuntu-latest', 'windows-2022'] ort_version: ['1.16.3'] onnx_version: ['1.16.1'] include: - - name: 'py39-tf2.10' - tf_version: '2.10.0' + - name: 'py39-tf2.17' + tf_version: '2.17.0' python_version: '3.9' - - name: 'py39-tf2.15' - tf_version: '2.15.0' + - name: 'py39-tf2.18' + tf_version: '2.18.0' python_version: '3.9' runs-on: ${{ matrix.os }} diff --git a/.github/workflows/pretrained_model_test_ci.yml b/.github/workflows/pretrained_model_test_ci.yml index e82968fc3..361bb34b9 100644 --- a/.github/workflows/pretrained_model_test_ci.yml +++ b/.github/workflows/pretrained_model_test_ci.yml @@ -24,11 +24,11 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Run Tests (Py38-TF2.9-18) + - name: Run Tests (Py38-TF2.12-18) uses: ./.github/actions/pretrained_model_test with: os: 'ubuntu-latest' - tf_version: '2.9.0' + tf_version: '2.13.1' python_version: '3.8' ort_version: '1.16.3' onnx_version: '1.16.1' @@ -39,7 +39,7 @@ jobs: if: always() uses: actions/upload-artifact@v3 with: - name: Test Results (Py38-TF2.9-18-ubuntu) + name: Test Results (Py38-TF2.12-18-ubuntu) path: ./**/test-results-*.xml Test_max_py_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. @@ -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' @@ -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: @@ -74,29 +74,29 @@ jobs: fail-fast: false matrix: name: - - 'py38-tf2.13' - - 'py39-tf2.15' - os: ['ubuntu-latest', 'windows-2022'] + - 'py39-tf2.17' + - 'py39-tf2.18' + os: ['ubuntu-22.04', 'windows-2022'] opset_version: ['18', '15'] ort_version: ['1.16.3'] onnx_version: ['1.16.1'] skip_tflite: ['False'] include: - name: 'py38-tf2.13' - tf_version: '2.13.0' + tf_version: '2.13.1' python_version: '3.8' - - name: 'py39-tf2.15' - tf_version: '2.15.0' + - name: 'py39-tf2.18' + tf_version: '2.18.0' python_version: '3.9' - name: 'py37-tf1.15' tf_version: '1.15.5' python_version: '3.7' - os: 'ubuntu-latest' + os: 'ubuntu-22.04' opset_version: '15' ort_version: '1.14.1' onnx_version: '1.14.1' - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} steps: - name: Checkout code diff --git a/.github/workflows/unit_test_ci.yml b/.github/workflows/unit_test_ci.yml index 1dcbef980..bb23ba77a 100644 --- a/.github/workflows/unit_test_ci.yml +++ b/.github/workflows/unit_test_ci.yml @@ -28,7 +28,7 @@ jobs: uses: ./.github/actions/unit_test with: os: 'ubuntu-latest' - tf_version: '2.9.0' + tf_version: '2.13.1' python_version: '3.8' ort_version: '1.16.3' onnx_version: '1.16.1' @@ -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' @@ -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: @@ -74,24 +74,24 @@ jobs: fail-fast: false matrix: name: - - 'py38-tf2.13' - - 'py39-tf2.15' - os: ['ubuntu-latest', 'windows-2022'] + - 'py38-tf2.17' + - 'py39-tf2.18' + os: ['ubuntu-22.04', 'windows-2022'] opset_version: ['18', '15'] ort_version: ['1.16.3'] onnx_version: ['1.16.1'] skip_tflite: ['False'] include: - - name: 'py38-tf2.13' - tf_version: '2.13.0' - python_version: '3.8' - - name: 'py39-tf2.15' - tf_version: '2.15.0' + - name: 'py39-tf2.17' + tf_version: '2.17.0' + python_version: '3.9' + - name: 'py39-tf2.18' + tf_version: '2.18.0' python_version: '3.9' - name: 'py37-tf1.15' tf_version: '1.15.5' python_version: '3.7' - os: 'ubuntu-latest' + os: 'ubuntu-22.04' opset_version: '15' ort_version: '1.14.1' onnx_version: '1.14.1' diff --git a/tests/keras2onnx_unit_tests/conftest.py b/tests/keras2onnx_unit_tests/conftest.py index 758c31f7f..6ba7452cb 100644 --- a/tests/keras2onnx_unit_tests/conftest.py +++ b/tests/keras2onnx_unit_tests/conftest.py @@ -12,6 +12,8 @@ K = keras.backend +def is_keras_3(): + return tf.__version__.startswith("2.18") or tf.__version__.startswith("2.17") or tf.__version__.startswith("2.16") @pytest.fixture(scope='function') def runner(): @@ -25,10 +27,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 diff --git a/tests/utils/setup_test_env.sh b/tests/utils/setup_test_env.sh index a14828d05..d74df3447 100755 --- a/tests/utils/setup_test_env.sh +++ b/tests/utils/setup_test_env.sh @@ -28,6 +28,8 @@ pip install tensorflow==$TF_VERSION pip uninstall -y protobuf pip install "protobuf~=3.20" +pip install tf_keras + python setup.py install echo "----- List all of depdencies:"