From 85a10b599ae7fb5a0f0e19906e0c32db584f8b68 Mon Sep 17 00:00:00 2001 From: Jay Zhang <36183870+fatcat-z@users.noreply.github.com> Date: Fri, 15 Dec 2023 15:43:20 +0800 Subject: [PATCH 01/11] Change the way to set node name. (#2278) Signed-off-by: Jay Zhang --- tf2onnx/tflite_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tf2onnx/tflite_utils.py b/tf2onnx/tflite_utils.py index 223643fb1..e69bc5032 100644 --- a/tf2onnx/tflite_utils.py +++ b/tf2onnx/tflite_utils.py @@ -483,6 +483,8 @@ def shape_to_tf_shape(dims): if has_prequantized_output: output_names = [get_prequant(out) for out in output_names] onnx_node = helper.make_node(optype, input_names, output_names, name=output_names[0], **attr) + node_name = output_names[0] if output_names else utils.make_name(f"{optype}_Output") + onnx_node = helper.make_node(optype, input_names, output_names, name=node_name, **attr) onnx_nodes.append(onnx_node) inputs = [tensor_names[tflite_g.Inputs(i)] for i in range(tflite_g.InputsLength())] From e177a26804a4bdf69bf40ecdedff46293a226f7a Mon Sep 17 00:00:00 2001 From: Jay Zhang <36183870+fatcat-z@users.noreply.github.com> Date: Thu, 21 Dec 2023 13:09:44 +0800 Subject: [PATCH 02/11] Enable support to ONNX 1.15. (#2279) * Add attr_type for empty sequence attribute. * Process attributes to avoid empty iterator error. * Do not use strict mode while checking node shape. * Update CI to work with ONNX 1.15.0. Signed-off-by: Jay Zhang --------- Signed-off-by: Jay Zhang Signed-off-by: Jay Zhang <36183870+fatcat-z@users.noreply.github.com> --- .../keras2onnx_application_tests.yml | 20 ++++----- .../azure_pipelines/keras2onnx_unit_test.yml | 28 ++++++------ .../onnxruntime_nightly_test.yml | 1 + .../pretrained_model_test-matrix.yml | 2 + .../azure_pipelines/pretrained_model_test.yml | 1 + .../templates/job_generator.yml | 2 +- .../trimmed_keras2onnx_application_tests.yml | 30 +++++++++++-- .../trimmed_keras2onnx_unit_test.yml | 18 ++++---- ci_build/azure_pipelines/unit_test-matrix.yml | 1 + ci_build/azure_pipelines/unit_test.yml | 1 + tests/backend_test_base.py | 6 ++- tf2onnx/graph.py | 10 +++-- tf2onnx/schemas.py | 2 +- tf2onnx/tf_utils.py | 5 ++- tf2onnx/tfjs_utils.py | 2 +- tf2onnx/tflite_utils.py | 4 +- tf2onnx/utils.py | 45 ++++++++++++++++++- 17 files changed, 130 insertions(+), 48 deletions(-) diff --git a/ci_build/azure_pipelines/keras2onnx_application_tests.yml b/ci_build/azure_pipelines/keras2onnx_application_tests.yml index f9ef1a80d..66a0387d4 100644 --- a/ci_build/azure_pipelines/keras2onnx_application_tests.yml +++ b/ci_build/azure_pipelines/keras2onnx_application_tests.yml @@ -10,7 +10,7 @@ jobs: matrix: Python37-tf-1.15: python.version: '3.7' # Max version that supports tf 1.15 - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.14.1 # Max version that supports python 3.7 INSTALL_KERAS: pip install keras==2.3.1 UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==1.15.0 @@ -23,7 +23,7 @@ jobs: Python39-tf2-2.12: python.version: '3.9' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==2.12.0 @@ -35,7 +35,7 @@ jobs: Python310-tf2-2.11: python.version: '3.10' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==2.11.0 @@ -47,7 +47,7 @@ jobs: Python38-tf2-2.10: python.version: '3.8' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==2.10.0 @@ -59,7 +59,7 @@ jobs: Python310-tf2-oldest: python.version: '3.10' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==2.8.0 @@ -82,7 +82,7 @@ jobs: matrix: Python37-tf-1.15: python.version: '3.7' # Max version that supports tf 1.15 - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.14.1 # Max version that supports python 3.7 INSTALL_KERAS: pip install keras==2.3.1 UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==1.15.0 @@ -95,7 +95,7 @@ jobs: Python39-tf2-2.12: python.version: '3.9' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==2.12.0 @@ -107,7 +107,7 @@ jobs: Python310-tf2-2.11: python.version: '3.10' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==2.11.0 @@ -119,7 +119,7 @@ jobs: Python38-tf2-2.10: python.version: '3.8' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==2.10.0 @@ -131,7 +131,7 @@ jobs: Python310-tf2-oldest: python.version: '3.10' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==2.8.0 diff --git a/ci_build/azure_pipelines/keras2onnx_unit_test.yml b/ci_build/azure_pipelines/keras2onnx_unit_test.yml index 5cdeb0184..2b7eb0c1b 100644 --- a/ci_build/azure_pipelines/keras2onnx_unit_test.yml +++ b/ci_build/azure_pipelines/keras2onnx_unit_test.yml @@ -10,42 +10,42 @@ jobs: ############ TF Keras Unit Tests ############ Python310-tf2-2.13: python.version: '3.10' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.13.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: Python38-tf2-2.12: python.version: '3.8' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.12.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: Python39-tf2-2.11: python.version: '3.9' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.11.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: Python310-tf2-2.10: python.version: '3.10' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.10.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: Python38-tf2-2.9: python.version: '3.8' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.9.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: Python310-tf2-oldest: python.version: '3.10' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.8.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: @@ -53,7 +53,7 @@ jobs: ############ Pure Keras Unit Tests ############ Keras-Py37-tf1.15.0: python.version: '3.7' # Max version that supports tf 1.15 - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.14.1 # Max version that supports python 3.7 KERAS: keras==2.4.3 TENSORFLOW_PATH: tensorflow==1.15.0 INSTALL_ORT: pip install onnxruntime==1.14.1 # Max version that supports python 3.7 @@ -72,42 +72,42 @@ jobs: ############ TF Keras Unit Tests ############ Python310-tf2-2.13: python.version: '3.10' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.13.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: Python38-tf2-2.12: python.version: '3.8' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.12.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: Python39-tf2-2.11: python.version: '3.9' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.11.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: Python310-tf2-2.10: python.version: '3.10' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.10.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: Python38-tf2-2.9: python.version: '3.8' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.9.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: Python310-tf2-oldest: python.version: '3.10' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.8.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: @@ -115,7 +115,7 @@ jobs: ############ Pure Keras Unit Tests ############ Keras-Py37-tf1.15.0: python.version: '3.7' # Max version that supports tf 1.15 - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.14.1 # Max version that supports python 3.7 KERAS: keras==2.4.3 TENSORFLOW_PATH: tensorflow==1.15.0 INSTALL_ORT: pip install onnxruntime==1.14.1 # Max version that supports python 3.7 diff --git a/ci_build/azure_pipelines/onnxruntime_nightly_test.yml b/ci_build/azure_pipelines/onnxruntime_nightly_test.yml index ace18e9d3..b3e0cdec6 100644 --- a/ci_build/azure_pipelines/onnxruntime_nightly_test.yml +++ b/ci_build/azure_pipelines/onnxruntime_nightly_test.yml @@ -8,6 +8,7 @@ stages: platforms: ['linux', 'windows'] python_versions: [3.7'] tf_versions: ['1.15.5'] + onnx_versions: ['1.14.1'] # Max version that supports python 3.7 onnx_backends: {onnxruntime: ['nightly']} job: steps: diff --git a/ci_build/azure_pipelines/pretrained_model_test-matrix.yml b/ci_build/azure_pipelines/pretrained_model_test-matrix.yml index 7c61e48b2..aaeeb4fc4 100755 --- a/ci_build/azure_pipelines/pretrained_model_test-matrix.yml +++ b/ci_build/azure_pipelines/pretrained_model_test-matrix.yml @@ -7,6 +7,7 @@ jobs: platforms: ['windows'] python_versions: ['3.7'] # Max version that supports tf 1.15 tf_versions: ['1.15.5'] + onnx_versions: ['1.14.1'] # Max version that supports python 3.7 onnx_opsets: ['18', '17', '16', '15'] onnx_backends: {onnxruntime: ['1.14.1']} # Max version that supports python 3.7 job: @@ -28,6 +29,7 @@ jobs: platforms: ['linux', 'windows'] python_versions: ['3.7'] # Max version that supports tf 1.15 tf_versions: ['1.15.5'] + onnx_versions: ['1.14.1'] # Max version that supports python 3.7 onnx_opsets: ['14'] onnx_backends: {onnxruntime: ['1.14.1']} # Max version that supports python 3.7 job: diff --git a/ci_build/azure_pipelines/pretrained_model_test.yml b/ci_build/azure_pipelines/pretrained_model_test.yml index 2c590840f..395a051d0 100644 --- a/ci_build/azure_pipelines/pretrained_model_test.yml +++ b/ci_build/azure_pipelines/pretrained_model_test.yml @@ -6,6 +6,7 @@ jobs: platforms: ['linux'] python_versions: ['3.7'] # Max version that supports tf 1.15 tf_versions: ['1.15.5'] + onnx_versions: ['1.14.1'] # Max version that supports python 3.7 onnx_opsets: ['18', '17', '16', '15'] onnx_backends: {onnxruntime: ['1.14.1']} # Max version that supports python 3.7 job: diff --git a/ci_build/azure_pipelines/templates/job_generator.yml b/ci_build/azure_pipelines/templates/job_generator.yml index 28fee6a2b..1fa3a677f 100644 --- a/ci_build/azure_pipelines/templates/job_generator.yml +++ b/ci_build/azure_pipelines/templates/job_generator.yml @@ -4,7 +4,7 @@ parameters: platforms: ['linux'] python_versions: ['3.8'] tf_versions: [''] - onnx_versions: ['1.14.1'] + onnx_versions: ['1.15.0'] onnx_opsets: ['18', '17', '16', '15', '14'] onnx_backends: {onnxruntime: ['1.15.1']} job: {} diff --git a/ci_build/azure_pipelines/trimmed_keras2onnx_application_tests.yml b/ci_build/azure_pipelines/trimmed_keras2onnx_application_tests.yml index e18c56d7a..51fcab2b6 100644 --- a/ci_build/azure_pipelines/trimmed_keras2onnx_application_tests.yml +++ b/ci_build/azure_pipelines/trimmed_keras2onnx_application_tests.yml @@ -10,7 +10,7 @@ jobs: matrix: Python37-tf-1.15: python.version: '3.7' # Max version that supports tf 1.15 - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.14.1 # Max version that supports python 3.7 INSTALL_KERAS: pip install keras==2.3.1 UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==1.15.0 @@ -23,7 +23,7 @@ jobs: Python38-tf2-oldest: python.version: '3.8' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==2.8.0 @@ -35,7 +35,31 @@ jobs: Python38-tf2-2.13: python.version: '3.8' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 + INSTALL_KERAS: + UNINSTALL_KERAS: + INSTALL_TENSORFLOW: pip install tensorflow==2.13.0 + INSTALL_ORT: pip install onnxruntime==1.15.0 + INSTALL_KERAS_RESNET: pip install keras-resnet + INSTALL_TRANSFORMERS: pip install transformers==4.2.0 + INSTALL_NUMPY: + NIGHTLY_BUILD_TEST: python run_all_v2.py + + Python38-tf2-oldest-onnx-15: + python.version: '3.8' + ONNX_PATH: onnx==1.15.0 + INSTALL_KERAS: + UNINSTALL_KERAS: + INSTALL_TENSORFLOW: pip install tensorflow==2.8.0 + INSTALL_ORT: pip install onnxruntime==1.15.0 + INSTALL_KERAS_RESNET: pip install keras-resnet + INSTALL_TRANSFORMERS: pip install transformers==4.2.0 + INSTALL_NUMPY: + NIGHTLY_BUILD_TEST: python run_all_v2.py + + Python38-tf2-2.13-onnx-15: + python.version: '3.8' + ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==2.13.0 diff --git a/ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml b/ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml index 6138e4507..7338d5b6a 100644 --- a/ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml +++ b/ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml @@ -11,21 +11,21 @@ jobs: ############ TF Keras Unit Tests ############ Python37-tf-1.15: python.version: '3.7' # Max version that supports tf 1.15 - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.14.1 # Max version that supports python 3.7 TENSORFLOW_PATH: tensorflow==1.15.0 INSTALL_ORT: pip install onnxruntime==1.14.1 # Max version that supports python 3.7 INSTALL_NUMPY: pip install numpy==1.19.0 Python38-tf2-oldest: python.version: '3.8' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.8.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: Python38-tf2-2.13: python.version: '3.8' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.13.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: @@ -33,12 +33,13 @@ jobs: ############ Pure Keras Unit Tests ############ Keras-Py37-tf-1.15: python.version: '3.7' # Max version that supports tf 1.15 - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.14.1 # Max version that supports python 3.7 KERAS: keras==2.4.3 TENSORFLOW_PATH: tensorflow==1.15.0 INSTALL_ORT: pip install onnxruntime==1.14.1 # Max version that supports python 3.7 INSTALL_NUMPY: pip install numpy==1.19.0 + steps: - template: 'templates/keras2onnx_unit_test.yml' parameters: @@ -52,21 +53,21 @@ jobs: ############ TF Keras Unit Tests ############ Python37-tf-1.15: python.version: '3.7' # Max version that supports tf 1.15 - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.14.1 # Max version that supports python 3.7 TENSORFLOW_PATH: tensorflow==1.15.0 INSTALL_ORT: pip install onnxruntime==1.14.1 # Max version that supports python 3.7 INSTALL_NUMPY: pip install numpy==1.19.0 Python38-tf2-oldest: python.version: '3.8' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.8.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: Python38-tf2-2.13: python.version: '3.8' - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.13.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: @@ -74,12 +75,13 @@ jobs: ############ Pure Keras Unit Tests ############ Keras-Py37-tf-1.15: python.version: '3.7' # Max version that supports tf 1.15 - ONNX_PATH: onnx==1.14.1 + ONNX_PATH: onnx==1.14.1 # Max version that supports python 3.7 KERAS: keras==2.4.3 TENSORFLOW_PATH: tensorflow==1.15.0 INSTALL_ORT: pip install onnxruntime==1.14.1 # Max version that supports python 3.7 INSTALL_NUMPY: pip install numpy==1.19.0 + steps: - template: 'templates/keras2onnx_unit_test.yml' parameters: diff --git a/ci_build/azure_pipelines/unit_test-matrix.yml b/ci_build/azure_pipelines/unit_test-matrix.yml index 91759e5cb..03c49819b 100644 --- a/ci_build/azure_pipelines/unit_test-matrix.yml +++ b/ci_build/azure_pipelines/unit_test-matrix.yml @@ -22,6 +22,7 @@ stages: python_versions: ['3.7'] # Max version that supports tf 1.15 platforms: ['windows'] tf_versions: ['1.15.5'] + onnx_versions: ['1.14.1'] # Max version that supports python 3.7 onnx_opsets: ['18', '17', '16', '15'] onnx_backends: {onnxruntime: ['1.14.1']} # Max version that supports python 3.7 job: diff --git a/ci_build/azure_pipelines/unit_test.yml b/ci_build/azure_pipelines/unit_test.yml index b698fb7c7..1266ba7ce 100644 --- a/ci_build/azure_pipelines/unit_test.yml +++ b/ci_build/azure_pipelines/unit_test.yml @@ -22,6 +22,7 @@ stages: python_versions: ['3.7'] # Max version that supports tf 1.15 platforms: ['linux'] tf_versions: ['1.15.5'] + onnx_versions: ['1.14.1'] # Max version that supports python 3.7 onnx_opsets: ['18', '17', '16', '15'] onnx_backends: {onnxruntime: ['1.14.1']} # Max version that supports python 3.7 job: diff --git a/tests/backend_test_base.py b/tests/backend_test_base.py index f2faa010c..2bdee83fc 100644 --- a/tests/backend_test_base.py +++ b/tests/backend_test_base.py @@ -299,6 +299,10 @@ def assert_shapes_correct(self, graph, allow_missing=False, run_checker=True, ch def get_shape(info): if not info.type.tensor_type.HasField("shape"): return None + for d in info.type.tensor_type.shape.dim: + if d.HasField('dim_param') and d.dim_param.startswith("unk"): + return None + return [d.dim_value if d.HasField('dim_value') else -1 for d in info.type.tensor_type.shape.dim] def get_dtype(info): tensor_type = info.type.tensor_type @@ -315,7 +319,7 @@ def get_dtype(info): continue onnx_shape = get_shape(info) tf2onnx_shape = graph.get_shape(info.name) - if onnx_shape is None: + if onnx_shape is None or not onnx_shape: continue if allow_missing and tf2onnx_shape is None: continue diff --git a/tf2onnx/graph.py b/tf2onnx/graph.py index 82c93c695..c1a07958b 100644 --- a/tf2onnx/graph.py +++ b/tf2onnx/graph.py @@ -22,7 +22,7 @@ # todo(pengwa): remove protected-access later -# pylint: disable=broad-except,protected-access +# pylint: disable=broad-except,protected-access,unexpected-keyword-arg class ExternalTensorStorage(): """Passed into graph and node methods to accumulate tensors to save externally""" @@ -267,7 +267,11 @@ def get_attr_str(self, name, encoding="utf-8"): return attr_str.decode(encoding) def set_attr(self, name, value): - self.attr[name] = helper.make_attribute(name, value) + if utils._attr_type_in_signature and not isinstance(value, bytes) and \ + isinstance(value, collections.abc.Sequence) and len(list(value)) == 0: + self.attr[name] = helper.make_attribute(name, value, attr_type=AttributeProto.INTS) + else: + self.attr[name] = helper.make_attribute(name, value) def set_attr_onnx(self, value): self.attr[value.name] = value @@ -640,7 +644,7 @@ def make_node(self, op_type, inputs, attr=None, output_count=1, outputs=None, sk n = self.get_node_by_output_in_current_graph(o) utils.make_sure(n is None, "output tensor named %s already exists in node: \n%s", o, n) - onnx_node = helper.make_node(op_type, inputs, outputs, name=name, domain=domain, **raw_attr) + onnx_node = utils.make_onnx_node_with_attr(op_type, inputs, outputs, name=name, domain=domain, **raw_attr) for name2 in onnx_node.input: self._register_input_name(name2, onnx_node) diff --git a/tf2onnx/schemas.py b/tf2onnx/schemas.py index f20a6cc72..ae22de85c 100644 --- a/tf2onnx/schemas.py +++ b/tf2onnx/schemas.py @@ -151,7 +151,7 @@ def build_onnx_op(node): inferred_model = None try: try: - inferred_model = shape_inference.infer_shapes(model_proto, strict_mode=True) + inferred_model = shape_inference.infer_shapes(model_proto, strict_mode=False) except TypeError: # strict_mode arg doesn't exist in old onnx packages inferred_model = shape_inference.infer_shapes(model_proto) diff --git a/tf2onnx/tf_utils.py b/tf2onnx/tf_utils.py index 7d5719873..16cb76344 100644 --- a/tf2onnx/tf_utils.py +++ b/tf2onnx/tf_utils.py @@ -14,8 +14,9 @@ from tensorflow.core.framework import types_pb2, tensor_pb2, graph_pb2 from tensorflow.python.framework import tensor_util -from onnx import helper, onnx_pb, numpy_helper +from onnx import onnx_pb, numpy_helper +from tf2onnx import utils from tf2onnx.utils import make_sure, is_tf_const_op, port_name, map_onnx_to_numpy_type from . import logging @@ -459,7 +460,7 @@ def tflist_to_onnx(g, shape_override, const_node_values=None, ignore_default=Non if takeit: try: - onnx_node = helper.make_node(node_type, input_names, output_names, name=node.name, **attr) + onnx_node = utils.make_onnx_node_with_attr(node_type, input_names, output_names, name=node.name, **attr) onnx_nodes.append(onnx_node) except Exception as ex: logger.error("pass1 convert failed for %s, ex=%s", node, ex) diff --git a/tf2onnx/tfjs_utils.py b/tf2onnx/tfjs_utils.py index 346825673..21ee54baa 100644 --- a/tf2onnx/tfjs_utils.py +++ b/tf2onnx/tfjs_utils.py @@ -481,7 +481,7 @@ def update_shapes(new_shapes): op_type = 'Identity' graph_inputs = [inp for inp in graph_inputs if inp != node_name + ":0"] - onnx_node = helper.make_node(op_type, input_names, output_names, name=node_name, **onnx_attr) + onnx_node = utils.make_onnx_node_with_attr(op_type, input_names, output_names, name=node_name, **onnx_attr) onnx_nodes.append(onnx_node) for inp in graph_inputs: diff --git a/tf2onnx/tflite_utils.py b/tf2onnx/tflite_utils.py index e69bc5032..ea30ce28c 100644 --- a/tf2onnx/tflite_utils.py +++ b/tf2onnx/tflite_utils.py @@ -482,9 +482,9 @@ def shape_to_tf_shape(dims): output_shapes[out] = None if has_prequantized_output: output_names = [get_prequant(out) for out in output_names] - onnx_node = helper.make_node(optype, input_names, output_names, name=output_names[0], **attr) + onnx_node = utils.make_onnx_node_with_attr(optype, input_names, output_names, name=output_names[0], **attr) node_name = output_names[0] if output_names else utils.make_name(f"{optype}_Output") - onnx_node = helper.make_node(optype, input_names, output_names, name=node_name, **attr) + onnx_node = utils.make_onnx_node_with_attr(optype, input_names, output_names, name=node_name, **attr) onnx_nodes.append(onnx_node) inputs = [tensor_names[tflite_g.Inputs(i)] for i in range(tflite_g.InputsLength())] diff --git a/tf2onnx/utils.py b/tf2onnx/utils.py index d0c14d19c..9d46e3c6a 100644 --- a/tf2onnx/utils.py +++ b/tf2onnx/utils.py @@ -6,6 +6,8 @@ """ import os +import collections +import inspect import re import shutil import tempfile @@ -13,19 +15,22 @@ import zipfile import logging +from typing import Any, Optional, Sequence import requests from requests.adapters import HTTPAdapter from urllib3.util.retry import Retry import numpy as np from google.protobuf import text_format -from onnx import helper, onnx_pb, defs, numpy_helper, ModelProto, __version__ - +from onnx import helper, onnx_pb, defs, numpy_helper, AttributeProto, ModelProto, NodeProto, __version__ from . import constants logger = logging.getLogger(__file__) +# pylint: disable=unexpected-keyword-arg + + # # mapping dtypes from onnx to numpy # @@ -177,6 +182,38 @@ def make_onnx_inputs_outputs(name, elem_type, shape, **kwargs): **kwargs ) +_attr_type_in_signature = inspect.signature(helper.make_attribute).parameters.get("attr_type", None) is not None + + +def make_onnx_node_with_attr(op_type: str, inputs: Sequence[str], outputs: Sequence[str], name: Optional[str] = None, + domain: Optional[str] = None, **kwargs: Any) -> NodeProto: + """ + Since ONNX 1.15.0, helper.make_attribute() does not support empty iterators. + But tf2onnx will leverage ONNX attributes to transfer some extra data along with the ONNX node + across different conversion stages. + This function removes empty lists from kwargs and adds them back with attr_type=INTS attributes by default. + """ + if _attr_type_in_signature: + attr_empty_lists = {} + valid_attrs = {} + if kwargs: + for key, value in sorted(kwargs.items()): + if not isinstance(value, bytes) and \ + isinstance(value, collections.abc.Sequence) and len(list(value)) == 0: + attr_empty_lists[key] = value + else: + valid_attrs[key] = value + + onnx_node = helper.make_node(op_type, inputs, outputs, name=name, domain=domain, **valid_attrs) + + if attr_empty_lists: + for key, value in attr_empty_lists.items(): + onnx_node.attribute.extend([helper.make_attribute(key, value, attr_type=AttributeProto.INTS)]) + else: + onnx_node = helper.make_node(op_type, inputs, outputs, name=name, domain=domain, **kwargs) + + return onnx_node + def find_opset(opset): """Find opset.""" @@ -253,16 +290,19 @@ def save_onnx_model(save_path_root, onnx_file_name, feed_dict, model_proto, incl return target_path + def save_onnx_zip(target_path, model_proto, external_tensor_storage): with zipfile.ZipFile(target_path, 'w') as z: z.writestr("__MODEL_PROTO.onnx", model_proto.SerializeToString()) for k, v in external_tensor_storage.name_to_tensor_data.items(): z.writestr(k, v) + def make_sure(bool_val, error_msg, *args): if not bool_val: raise ValueError("make_sure failure: " + error_msg % args) + def combine_seeds(seed, seed2): """Produces an onnx float seed from two tf int seeds. Returns None if both seeds are 0.""" if seed != 0 or seed2 != 0: @@ -271,6 +311,7 @@ def combine_seeds(seed, seed2): return float(combined_seed) return None + def topological_sort(dependencies): """ Given a dictionary mapping items to lists of dependencies, returns a topological ordering of the items. From f36a3fb6e30501238167c5e97d65cabcb71f08a0 Mon Sep 17 00:00:00 2001 From: Jay Zhang <36183870+fatcat-z@users.noreply.github.com> Date: Wed, 27 Dec 2023 08:04:21 +0800 Subject: [PATCH 03/11] Adjust CI tests coverage in different pipelines. (#2281) * Adjust CI tests coverage in different pipelines. * Correct the way of installing tensorflow-text. * Ignore a test in windows because of tensorflow-text issue. Signed-off-by: Jay Zhang --------- Signed-off-by: Jay Zhang --- .../pretrained_model_test-matrix.yml | 2 +- .../azure_pipelines/pretrained_model_test.yml | 12 +++++- ci_build/azure_pipelines/templates/setup.yml | 39 ++----------------- ci_build/azure_pipelines/unit_test-matrix.yml | 2 +- ci_build/azure_pipelines/unit_test.yml | 16 +++++++- tests/test_string_ops.py | 3 +- 6 files changed, 33 insertions(+), 41 deletions(-) diff --git a/ci_build/azure_pipelines/pretrained_model_test-matrix.yml b/ci_build/azure_pipelines/pretrained_model_test-matrix.yml index aaeeb4fc4..5798cb7df 100755 --- a/ci_build/azure_pipelines/pretrained_model_test-matrix.yml +++ b/ci_build/azure_pipelines/pretrained_model_test-matrix.yml @@ -41,7 +41,7 @@ jobs: platforms: ['linux', 'windows'] python_versions: ['3.8'] tf_versions: ['2.8.0', '2.13.0'] - onnx_opsets: ['14'] + onnx_opsets: ['17', '16', '14'] job: steps: - template: 'pretrained_model_test.yml' diff --git a/ci_build/azure_pipelines/pretrained_model_test.yml b/ci_build/azure_pipelines/pretrained_model_test.yml index 395a051d0..15a817d98 100644 --- a/ci_build/azure_pipelines/pretrained_model_test.yml +++ b/ci_build/azure_pipelines/pretrained_model_test.yml @@ -18,7 +18,17 @@ jobs: platforms: ['linux'] python_versions: ['3.8'] tf_versions: ['2.8.0', '2.13.0'] - onnx_opsets: ['18', '17', '16', '15'] + onnx_opsets: ['18', '15'] job: steps: - template: 'pretrained_model_test.yml' + +- template: 'templates/job_generator.yml' + parameters: + platforms: ['linux'] + python_versions: ['3.10'] + tf_versions: ['2.13.0'] + onnx_opsets: ['18', '15'] + job: + steps: + - template: 'pretrained_model_test.yml' \ No newline at end of file diff --git a/ci_build/azure_pipelines/templates/setup.yml b/ci_build/azure_pipelines/templates/setup.yml index bd6634b57..73a839d0f 100644 --- a/ci_build/azure_pipelines/templates/setup.yml +++ b/ci_build/azure_pipelines/templates/setup.yml @@ -4,7 +4,6 @@ steps: - bash: | set -ex pip install pytest pytest-cov pytest-runner coverage graphviz requests pyyaml pillow pandas parameterized sympy coloredlogs flatbuffers timeout-decorator - pip install $(CI_PIP_TF_NAME) pip install $(CI_PIP_ONNX_NAME) # TF < 2.7 reuires numpy <= 1.19, but onnxruntime >= 1.11 requires numpy >= 1.21 @@ -24,41 +23,7 @@ steps: if [[ $CI_TF_VERSION == 2.* ]] ; then pip install onnxruntime-extensions - - if [[ $CI_TF_VERSION == 2.3* ]] ; - then - pip install tensorflow-text==${CI_TF_VERSION} - fi - if [[ $CI_TF_VERSION == 2.4* ]] ; - then - pip install tensorflow-text==${CI_TF_VERSION} - fi - if [[ $CI_TF_VERSION == 2.5* ]] ; - then - pip install "tensorflow-text>=2.5,<2.6" - fi - if [[ $CI_TF_VERSION == 2.6* ]] ; - then - pip install "tensorflow-text>=2.6,<2.7" - fi - if [[ $CI_TF_VERSION == 2.7* ]] ; - then - pip install "tensorflow-text>=2.7,<2.8" - fi - if [[ $CI_TF_VERSION == 2.8* ]] ; - then - pip install "tensorflow-text>=2.8,<2.9" - fi - if [[ $CI_TF_VERSION == 2.9* ]] ; - then - pip install "tensorflow-text>=2.9,<2.10" - fi - if [[ $CI_TF_VERSION == 2.10* ]] || [[ $CI_TF_VERSION == 2.11* ]] ; - then - pip install "tensorflow-text>=2.10,<2.14" - else - pip install tensorflow-text - fi + pip install "tensorflow-text<=$(CI_TF_VERSION)" if [[ $CI_TF_VERSION < 2.8 ]] ; then @@ -74,6 +39,8 @@ steps: pip install -i https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ ort-nightly fi + pip uninstall -y tensorflow + pip install $(CI_PIP_TF_NAME) pip uninstall -y protobuf pip install "protobuf~=3.20" diff --git a/ci_build/azure_pipelines/unit_test-matrix.yml b/ci_build/azure_pipelines/unit_test-matrix.yml index 03c49819b..d16f50e56 100644 --- a/ci_build/azure_pipelines/unit_test-matrix.yml +++ b/ci_build/azure_pipelines/unit_test-matrix.yml @@ -8,7 +8,7 @@ stages: python_versions: ['3.8'] platforms: ['linux', 'windows'] tf_versions: ['2.8.0', '2.13.0'] - onnx_opsets: ['14'] + onnx_opsets: ['17', '16', '14'] skip_tflite_tests: 'False' skip_tf_tests: 'False' skip_tfjs_tests: 'True' diff --git a/ci_build/azure_pipelines/unit_test.yml b/ci_build/azure_pipelines/unit_test.yml index 1266ba7ce..16c5798f4 100644 --- a/ci_build/azure_pipelines/unit_test.yml +++ b/ci_build/azure_pipelines/unit_test.yml @@ -8,7 +8,21 @@ stages: python_versions: ['3.8'] platforms: ['linux', 'windows'] tf_versions: ['2.8.0', '2.13.0'] - onnx_opsets: ['18', '17', '16', '15'] + onnx_opsets: ['18', '15'] + skip_tflite_tests: 'False' + skip_tf_tests: 'False' + skip_tfjs_tests: 'True' + job: + steps: + - template: 'unit_test.yml' + report_coverage: 'True' + + - template: 'templates/job_generator.yml' + parameters: + python_versions: ['3.10'] + platforms: ['linux'] + tf_versions: ['2.13.0'] + onnx_opsets: ['18', '15'] skip_tflite_tests: 'False' skip_tf_tests: 'False' skip_tfjs_tests: 'True' diff --git a/tests/test_string_ops.py b/tests/test_string_ops.py index de1920d78..025bfb11a 100644 --- a/tests/test_string_ops.py +++ b/tests/test_string_ops.py @@ -8,7 +8,7 @@ import tensorflow as tf from backend_test_base import Tf2OnnxBackendTestBase -from common import requires_custom_ops, check_tf_min_version, check_opset_min_version +from common import requires_custom_ops, check_tf_min_version, check_opset_min_version, get_test_config from tf2onnx import utils from tf2onnx import constants @@ -118,6 +118,7 @@ def func(x1, x2): return tf.identity(mi, name=_TFOUTPUT) self._run_test_case(func, [_OUTPUT], {_INPUT: x_val1, _INPUT1: x_val2}) + @unittest.skipIf(get_test_config().is_windows, "tensorflow-text lacks versions in windows.") @requires_custom_ops("RegexSplitWithOffsets") @check_tf_min_version("2.3", "tensorflow_text") def test_regex_split_with_offsets(self): From 898c069b872022a138a794332c16a75491dfb5c9 Mon Sep 17 00:00:00 2001 From: Jay Zhang <36183870+fatcat-z@users.noreply.github.com> Date: Thu, 28 Dec 2023 19:46:54 +0800 Subject: [PATCH 04/11] Upgrade ort to 1.16.3 in CI. (#2283) * Upgrade ort to 1.16.3 in CI. * Update CI tests and the way of install tensorflow-text. * Change tf version coverage to [2.9.0 ... 2.14.0]. Signed-off-by: Jay Zhang --------- Signed-off-by: Jay Zhang Signed-off-by: Jay Zhang <36183870+fatcat-z@users.noreply.github.com> --- README.md | 4 +-- .../keras2onnx_application_tests.yml | 26 +++++++-------- .../azure_pipelines/keras2onnx_unit_test.yml | 18 ++-------- .../onnxruntime_nightly_test.yml | 6 ++-- .../pretrained_model_test-matrix.yml | 31 ++++++++++++++--- .../azure_pipelines/pretrained_model_test.yml | 16 +++++++-- .../templates/job_generator.yml | 2 +- ci_build/azure_pipelines/templates/setup.yml | 14 +------- .../trimmed_keras2onnx_application_tests.yml | 22 ++++++------- .../trimmed_keras2onnx_unit_test.yml | 30 ++++++++++++----- ci_build/azure_pipelines/unit_test-matrix.yml | 33 +++++++++++++++++-- ci_build/azure_pipelines/unit_test.yml | 22 ++++++++++--- tests/keras2onnx_unit_tests/test_utils.py | 4 +-- 13 files changed, 143 insertions(+), 85 deletions(-) diff --git a/README.md b/README.md index a5a17cc74..e272ab7a9 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ The common issues we run into we try to document here [Troubleshooting Guide](Tr | Build Type | OS | Python | TensorFlow | ONNX opset | Status | | --- | --- | --- | --- | --- | --- | -| Unit Test - Basic | Linux, Windows | 3.7-3.10 | 1.15, 2.8-2.13 | 14-18 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test?branchName=main)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=16&branchName=main) | -| Unit Test - Full | Linux, Windows | 3.7-3.10 | 1.15, 2.8-2.13 | 14-18 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test-matrix?branchName=main)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=18&branchName=main) | | +| Unit Test - Basic | Linux, Windows | 3.7-3.10 | 1.15, 2.9-2.13 | 14-18 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test?branchName=main)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=16&branchName=main) | +| Unit Test - Full | Linux, Windows | 3.7-3.10 | 1.15, 2.9-2.13 | 14-18 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test-matrix?branchName=main)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=18&branchName=main) | |
## Supported Versions diff --git a/ci_build/azure_pipelines/keras2onnx_application_tests.yml b/ci_build/azure_pipelines/keras2onnx_application_tests.yml index 66a0387d4..a81d586df 100644 --- a/ci_build/azure_pipelines/keras2onnx_application_tests.yml +++ b/ci_build/azure_pipelines/keras2onnx_application_tests.yml @@ -62,7 +62,7 @@ jobs: ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: - INSTALL_TENSORFLOW: pip install tensorflow==2.8.0 + INSTALL_TENSORFLOW: pip install tensorflow==2.9.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_KERAS_RESNET: pip install keras-resnet INSTALL_TRANSFORMERS: pip install transformers==4.2.0 @@ -93,6 +93,18 @@ jobs: INSTALL_LEGACY: pip install h5py==2.9.0 NIGHTLY_BUILD_TEST: python run_all_v2.py --exclude "test_keras_applications_v2.py" + Python310-tf2-2.13: + python.version: '3.10' + ONNX_PATH: onnx==1.15.0 + INSTALL_KERAS: + UNINSTALL_KERAS: + INSTALL_TENSORFLOW: pip install tensorflow==2.13.0 + INSTALL_ORT: pip install onnxruntime==1.15.0 + INSTALL_KERAS_RESNET: pip install keras-resnet + INSTALL_TRANSFORMERS: pip install transformers==4.2.0 + INSTALL_NUMPY: + NIGHTLY_BUILD_TEST: python run_all_v2.py + Python39-tf2-2.12: python.version: '3.9' ONNX_PATH: onnx==1.15.0 @@ -129,18 +141,6 @@ jobs: INSTALL_NUMPY: NIGHTLY_BUILD_TEST: python run_all_v2.py - Python310-tf2-oldest: - python.version: '3.10' - ONNX_PATH: onnx==1.15.0 - INSTALL_KERAS: - UNINSTALL_KERAS: - INSTALL_TENSORFLOW: pip install tensorflow==2.8.0 - INSTALL_ORT: pip install onnxruntime==1.15.0 - INSTALL_KERAS_RESNET: pip install keras-resnet - INSTALL_TRANSFORMERS: pip install transformers==4.2.0 - INSTALL_NUMPY: - NIGHTLY_BUILD_TEST: python run_all_v2.py - steps: - template: 'templates/keras2onnx_application_tests.yml' parameters: diff --git a/ci_build/azure_pipelines/keras2onnx_unit_test.yml b/ci_build/azure_pipelines/keras2onnx_unit_test.yml index 2b7eb0c1b..f4523b80b 100644 --- a/ci_build/azure_pipelines/keras2onnx_unit_test.yml +++ b/ci_build/azure_pipelines/keras2onnx_unit_test.yml @@ -36,17 +36,10 @@ jobs: INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: - Python38-tf2-2.9: - python.version: '3.8' - ONNX_PATH: onnx==1.15.0 - TENSORFLOW_PATH: tensorflow==2.9.0 - INSTALL_ORT: pip install onnxruntime==1.15.0 - INSTALL_NUMPY: - Python310-tf2-oldest: python.version: '3.10' ONNX_PATH: onnx==1.15.0 - TENSORFLOW_PATH: tensorflow==2.8.0 + TENSORFLOW_PATH: tensorflow==2.9.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: @@ -98,17 +91,10 @@ jobs: INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: - Python38-tf2-2.9: - python.version: '3.8' - ONNX_PATH: onnx==1.15.0 - TENSORFLOW_PATH: tensorflow==2.9.0 - INSTALL_ORT: pip install onnxruntime==1.15.0 - INSTALL_NUMPY: - Python310-tf2-oldest: python.version: '3.10' ONNX_PATH: onnx==1.15.0 - TENSORFLOW_PATH: tensorflow==2.8.0 + TENSORFLOW_PATH: tensorflow==2.9.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: diff --git a/ci_build/azure_pipelines/onnxruntime_nightly_test.yml b/ci_build/azure_pipelines/onnxruntime_nightly_test.yml index b3e0cdec6..bfeaa75ae 100644 --- a/ci_build/azure_pipelines/onnxruntime_nightly_test.yml +++ b/ci_build/azure_pipelines/onnxruntime_nightly_test.yml @@ -19,7 +19,7 @@ stages: parameters: platforms: ['linux', 'windows'] python_versions: ['3.8'] - tf_versions: ['2.8.0', '2.9.0', '2.13.0'] + tf_versions: ['2.9.0', '2.10.0', '2.13.0'] onnx_backends: {onnxruntime: ['nightly']} job: steps: @@ -30,7 +30,7 @@ stages: parameters: platforms: ['linux', 'windows'] python_versions: ['3.9'] - tf_versions: ['2.10.0', '2.12.0'] + tf_versions: ['2.12.0'] onnx_backends: {onnxruntime: ['nightly']} job: steps: @@ -41,7 +41,7 @@ stages: parameters: platforms: ['linux', 'windows'] python_versions: ['3.10'] - tf_versions: ['2.8.0', '2.13.0'] + tf_versions: ['2.9.0', '2.13.0'] onnx_backends: {onnxruntime: ['nightly']} job: steps: diff --git a/ci_build/azure_pipelines/pretrained_model_test-matrix.yml b/ci_build/azure_pipelines/pretrained_model_test-matrix.yml index 5798cb7df..c29903637 100755 --- a/ci_build/azure_pipelines/pretrained_model_test-matrix.yml +++ b/ci_build/azure_pipelines/pretrained_model_test-matrix.yml @@ -18,7 +18,17 @@ jobs: parameters: platforms: ['windows'] python_versions: ['3.8'] - tf_versions: ['2.8.0', '2.13.0'] + tf_versions: ['2.9.0'] + onnx_opsets: ['18', '17', '16', '15'] + job: + steps: + - template: 'pretrained_model_test.yml' + +- template: 'templates/job_generator.yml' + parameters: + platforms: ['windows'] + python_versions: ['3.9'] + tf_versions: ['2.13.0'] onnx_opsets: ['18', '17', '16', '15'] job: steps: @@ -30,7 +40,7 @@ jobs: python_versions: ['3.7'] # Max version that supports tf 1.15 tf_versions: ['1.15.5'] onnx_versions: ['1.14.1'] # Max version that supports python 3.7 - onnx_opsets: ['14'] + onnx_opsets: ['18', '17', '16', '14'] onnx_backends: {onnxruntime: ['1.14.1']} # Max version that supports python 3.7 job: steps: @@ -40,7 +50,17 @@ jobs: parameters: platforms: ['linux', 'windows'] python_versions: ['3.8'] - tf_versions: ['2.8.0', '2.13.0'] + tf_versions: ['2.9.0'] + onnx_opsets: ['17', '16', '14'] + job: + steps: + - template: 'pretrained_model_test.yml' + +- template: 'templates/job_generator.yml' + parameters: + platforms: ['linux', 'windows'] + python_versions: ['3.9'] + tf_versions: ['2.13.0'] onnx_opsets: ['17', '16', '14'] job: steps: @@ -50,7 +70,7 @@ jobs: parameters: platforms: ['linux', 'windows'] python_versions: ['3.10'] - tf_versions: ['2.8.0'] + tf_versions: ['2.10.0'] job: steps: - template: 'pretrained_model_test.yml' @@ -59,7 +79,7 @@ jobs: parameters: platforms: ['linux', 'windows'] python_versions: ['3.9'] - tf_versions: ['2.10.0', '2.11.0', '2.12.0'] + tf_versions: ['2.11.0', '2.12.0'] job: steps: - template: 'pretrained_model_test.yml' @@ -69,6 +89,7 @@ jobs: platforms: ['linux'] python_versions: ['3.10'] tf_versions: ['2.9.0', '2.13.0'] + onnx_opsets: ['17', '16', '14'] job: steps: - template: 'pretrained_model_test.yml' diff --git a/ci_build/azure_pipelines/pretrained_model_test.yml b/ci_build/azure_pipelines/pretrained_model_test.yml index 15a817d98..3ac548a81 100644 --- a/ci_build/azure_pipelines/pretrained_model_test.yml +++ b/ci_build/azure_pipelines/pretrained_model_test.yml @@ -7,7 +7,7 @@ jobs: python_versions: ['3.7'] # Max version that supports tf 1.15 tf_versions: ['1.15.5'] onnx_versions: ['1.14.1'] # Max version that supports python 3.7 - onnx_opsets: ['18', '17', '16', '15'] + onnx_opsets: ['15'] onnx_backends: {onnxruntime: ['1.14.1']} # Max version that supports python 3.7 job: steps: @@ -17,7 +17,7 @@ jobs: parameters: platforms: ['linux'] python_versions: ['3.8'] - tf_versions: ['2.8.0', '2.13.0'] + tf_versions: ['2.9.0'] onnx_opsets: ['18', '15'] job: steps: @@ -26,9 +26,19 @@ jobs: - template: 'templates/job_generator.yml' parameters: platforms: ['linux'] - python_versions: ['3.10'] + python_versions: ['3.9'] tf_versions: ['2.13.0'] onnx_opsets: ['18', '15'] + job: + steps: + - template: 'pretrained_model_test.yml' + +- template: 'templates/job_generator.yml' + parameters: + platforms: ['linux'] + python_versions: ['3.10'] + tf_versions: ['2.9.0', '2.13.0'] + onnx_opsets: ['18', '15'] job: steps: - template: 'pretrained_model_test.yml' \ No newline at end of file diff --git a/ci_build/azure_pipelines/templates/job_generator.yml b/ci_build/azure_pipelines/templates/job_generator.yml index 1fa3a677f..811949d00 100644 --- a/ci_build/azure_pipelines/templates/job_generator.yml +++ b/ci_build/azure_pipelines/templates/job_generator.yml @@ -6,7 +6,7 @@ parameters: tf_versions: [''] onnx_versions: ['1.15.0'] onnx_opsets: ['18', '17', '16', '15', '14'] - onnx_backends: {onnxruntime: ['1.15.1']} + onnx_backends: {onnxruntime: ['1.16.3']} job: {} run_setup: 'True' report_coverage: 'False' diff --git a/ci_build/azure_pipelines/templates/setup.yml b/ci_build/azure_pipelines/templates/setup.yml index 73a839d0f..2e2e86c98 100644 --- a/ci_build/azure_pipelines/templates/setup.yml +++ b/ci_build/azure_pipelines/templates/setup.yml @@ -5,14 +5,7 @@ steps: set -ex pip install pytest pytest-cov pytest-runner coverage graphviz requests pyyaml pillow pandas parameterized sympy coloredlogs flatbuffers timeout-decorator pip install $(CI_PIP_ONNX_NAME) - - # TF < 2.7 reuires numpy <= 1.19, but onnxruntime >= 1.11 requires numpy >= 1.21 - if [[ $CI_TF_VERSION < 2.7 ]] && [[ $CI_ONNX_BACKEND == "onnxruntime" ]] ; - then - pip install $(CI_PIP_ONNX_BACKEND_NAME) numpy --no-deps -U - else - pip install $(CI_PIP_ONNX_BACKEND_NAME) numpy==1.23.4 - fi + pip install $(CI_PIP_ONNX_BACKEND_NAME) numpy if [[ $CI_SKIP_TFJS_TESTS == "False" ]] ; then @@ -24,11 +17,6 @@ steps: then pip install onnxruntime-extensions pip install "tensorflow-text<=$(CI_TF_VERSION)" - - if [[ $CI_TF_VERSION < 2.8 ]] ; - then - pip install wrapt==1.14.1 - fi fi if [[ $CI_ONNXRUNTIME_NIGHTLY == "true" ]] ; diff --git a/ci_build/azure_pipelines/trimmed_keras2onnx_application_tests.yml b/ci_build/azure_pipelines/trimmed_keras2onnx_application_tests.yml index 51fcab2b6..f30d2f8e4 100644 --- a/ci_build/azure_pipelines/trimmed_keras2onnx_application_tests.yml +++ b/ci_build/azure_pipelines/trimmed_keras2onnx_application_tests.yml @@ -26,44 +26,44 @@ jobs: ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: - INSTALL_TENSORFLOW: pip install tensorflow==2.8.0 - INSTALL_ORT: pip install onnxruntime==1.15.0 + INSTALL_TENSORFLOW: pip install tensorflow==2.9.0 + INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_KERAS_RESNET: pip install keras-resnet INSTALL_TRANSFORMERS: pip install transformers==4.2.0 INSTALL_NUMPY: NIGHTLY_BUILD_TEST: python run_all_v2.py - Python38-tf2-2.13: + Python38-tf2-latest: python.version: '3.8' ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==2.13.0 - INSTALL_ORT: pip install onnxruntime==1.15.0 + INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_KERAS_RESNET: pip install keras-resnet INSTALL_TRANSFORMERS: pip install transformers==4.2.0 INSTALL_NUMPY: NIGHTLY_BUILD_TEST: python run_all_v2.py - Python38-tf2-oldest-onnx-15: - python.version: '3.8' + Python310-tf2-oldest: + python.version: '3.10' ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: - INSTALL_TENSORFLOW: pip install tensorflow==2.8.0 - INSTALL_ORT: pip install onnxruntime==1.15.0 + INSTALL_TENSORFLOW: pip install tensorflow==2.9.0 + INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_KERAS_RESNET: pip install keras-resnet INSTALL_TRANSFORMERS: pip install transformers==4.2.0 INSTALL_NUMPY: NIGHTLY_BUILD_TEST: python run_all_v2.py - Python38-tf2-2.13-onnx-15: - python.version: '3.8' + Python310-tf2-latest: + python.version: '3.10' ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==2.13.0 - INSTALL_ORT: pip install onnxruntime==1.15.0 + INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_KERAS_RESNET: pip install keras-resnet INSTALL_TRANSFORMERS: pip install transformers==4.2.0 INSTALL_NUMPY: diff --git a/ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml b/ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml index 7338d5b6a..4f4aee22e 100644 --- a/ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml +++ b/ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml @@ -19,15 +19,29 @@ jobs: Python38-tf2-oldest: python.version: '3.8' ONNX_PATH: onnx==1.15.0 - TENSORFLOW_PATH: tensorflow==2.8.0 - INSTALL_ORT: pip install onnxruntime==1.15.0 + TENSORFLOW_PATH: tensorflow==2.9.0 + INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_NUMPY: - Python38-tf2-2.13: + Python38-tf2-latest: python.version: '3.8' ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.13.0 - INSTALL_ORT: pip install onnxruntime==1.15.0 + INSTALL_ORT: pip install onnxruntime==1.16.3 + INSTALL_NUMPY: + + Python310-tf2-oldest: + python.version: '3.10' + ONNX_PATH: onnx==1.15.0 + TENSORFLOW_PATH: tensorflow==2.9.0 + INSTALL_ORT: pip install onnxruntime==1.16.3 + INSTALL_NUMPY: + + Python310-tf2-latest: + python.version: '3.10' + ONNX_PATH: onnx==1.15.0 + TENSORFLOW_PATH: tensorflow==2.13.0 + INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_NUMPY: ############ Pure Keras Unit Tests ############ @@ -61,15 +75,15 @@ jobs: Python38-tf2-oldest: python.version: '3.8' ONNX_PATH: onnx==1.15.0 - TENSORFLOW_PATH: tensorflow==2.8.0 - INSTALL_ORT: pip install onnxruntime==1.15.0 + TENSORFLOW_PATH: tensorflow==2.9.0 + INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_NUMPY: - Python38-tf2-2.13: + Python38-tf2-latest: python.version: '3.8' ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.13.0 - INSTALL_ORT: pip install onnxruntime==1.15.0 + INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_NUMPY: ############ Pure Keras Unit Tests ############ diff --git a/ci_build/azure_pipelines/unit_test-matrix.yml b/ci_build/azure_pipelines/unit_test-matrix.yml index d16f50e56..7d51ae95a 100644 --- a/ci_build/azure_pipelines/unit_test-matrix.yml +++ b/ci_build/azure_pipelines/unit_test-matrix.yml @@ -7,7 +7,21 @@ stages: parameters: python_versions: ['3.8'] platforms: ['linux', 'windows'] - tf_versions: ['2.8.0', '2.13.0'] + tf_versions: ['2.9.0'] + onnx_opsets: ['17', '16', '14'] + skip_tflite_tests: 'False' + skip_tf_tests: 'False' + skip_tfjs_tests: 'True' + job: + steps: + - template: 'unit_test.yml' + report_coverage: 'True' + + - template: 'templates/job_generator.yml' + parameters: + python_versions: ['3.9'] + platforms: ['linux', 'windows'] + tf_versions: ['2.13.0'] onnx_opsets: ['17', '16', '14'] skip_tflite_tests: 'False' skip_tf_tests: 'False' @@ -30,6 +44,19 @@ stages: - template: 'unit_test.yml' report_coverage: 'True' + - template: 'templates/job_generator.yml' + parameters: + python_versions: ['3.7'] # Max version that supports tf 1.15 + platforms: ['linux'] + tf_versions: ['1.15.5'] + onnx_versions: ['1.14.1'] # Max version that supports python 3.7 + onnx_opsets: ['18', '17', '16'] + onnx_backends: {onnxruntime: ['1.14.1']} # Max version that supports python 3.7 + job: + steps: + - template: 'unit_test.yml' + report_coverage: 'True' + - template: 'templates/job_generator.yml' parameters: platforms: ['linux', 'windows'] @@ -44,7 +71,7 @@ stages: parameters: platforms: ['linux', 'windows'] python_versions: ['3.9'] - tf_versions: ['2.9.0', '2.10.0',] + tf_versions: ['2.10.0', '2.11.0', '2.12.0'] job: steps: - template: 'unit_test.yml' @@ -54,7 +81,7 @@ stages: parameters: platforms: ['linux', 'windows'] python_versions: ['3.10'] - tf_versions: ['2.8.0', '2.11.0', '2.13.0'] + tf_versions: ['2.9.0', '2.13.0'] job: steps: - template: 'unit_test.yml' diff --git a/ci_build/azure_pipelines/unit_test.yml b/ci_build/azure_pipelines/unit_test.yml index 16c5798f4..2f55d80a7 100644 --- a/ci_build/azure_pipelines/unit_test.yml +++ b/ci_build/azure_pipelines/unit_test.yml @@ -7,7 +7,21 @@ stages: parameters: python_versions: ['3.8'] platforms: ['linux', 'windows'] - tf_versions: ['2.8.0', '2.13.0'] + tf_versions: ['2.9.0'] + onnx_opsets: ['18', '15'] + skip_tflite_tests: 'False' + skip_tf_tests: 'False' + skip_tfjs_tests: 'True' + job: + steps: + - template: 'unit_test.yml' + report_coverage: 'True' + + - template: 'templates/job_generator.yml' + parameters: + python_versions: ['3.9'] + platforms: ['linux', 'windows'] + tf_versions: ['2.13.0'] onnx_opsets: ['18', '15'] skip_tflite_tests: 'False' skip_tf_tests: 'False' @@ -21,7 +35,7 @@ stages: parameters: python_versions: ['3.10'] platforms: ['linux'] - tf_versions: ['2.13.0'] + tf_versions: ['2.9.0', '2.13.0'] onnx_opsets: ['18', '15'] skip_tflite_tests: 'False' skip_tf_tests: 'False' @@ -37,7 +51,7 @@ stages: platforms: ['linux'] tf_versions: ['1.15.5'] onnx_versions: ['1.14.1'] # Max version that supports python 3.7 - onnx_opsets: ['18', '17', '16', '15'] + onnx_opsets: ['15'] onnx_backends: {onnxruntime: ['1.14.1']} # Max version that supports python 3.7 job: steps: @@ -48,7 +62,7 @@ stages: # - template: 'templates/job_generator.yml' # parameters: # python_versions: ['3.9'] - # tf_versions: ['2.8.0'] + # tf_versions: ['2.9.0'] # onnx_opsets: [''] # skip_tfjs_tests: 'False' # skip_tf_tests: 'True' diff --git a/tests/keras2onnx_unit_tests/test_utils.py b/tests/keras2onnx_unit_tests/test_utils.py index d20196ecc..ae46a4fa5 100644 --- a/tests/keras2onnx_unit_tests/test_utils.py +++ b/tests/keras2onnx_unit_tests/test_utils.py @@ -16,11 +16,9 @@ # Mapping opset to ONNXRuntime version. -# TODO: upgrade opset to 18 for 1.14.0 after the below issue is fixed: -# https://github.com/onnx/tensorflow-onnx/issues/2132 ORT_OPSET_VERSION = { "1.6.0": 13, "1.7.0": 13, "1.8.0": 14, "1.9.0": 15, "1.10.0": 15, "1.11.0": 16, - "1.12.0": 17, "1.13.0": 17, "1.14.0": 18, "1.15.0": 18 + "1.12.0": 17, "1.13.0": 17, "1.14.0": 18, "1.15.0": 18, "1.16.0": 18 } working_path = os.path.abspath(os.path.dirname(__file__)) From 655582b7f83e7cd46d02a8fcd4abd06628c4eb9d Mon Sep 17 00:00:00 2001 From: Jay Zhang <36183870+fatcat-z@users.noreply.github.com> Date: Fri, 29 Dec 2023 08:54:09 +0800 Subject: [PATCH 05/11] Update version number for 1.6.0 release. (#2285) Signed-off-by: Jay Zhang --- VERSION_NUMBER | 2 +- tf2onnx/version.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VERSION_NUMBER b/VERSION_NUMBER index ace44233b..15b989e39 100644 --- a/VERSION_NUMBER +++ b/VERSION_NUMBER @@ -1 +1 @@ -1.15.1 +1.16.0 diff --git a/tf2onnx/version.py b/tf2onnx/version.py index c3cfd8d04..b69fa91e2 100644 --- a/tf2onnx/version.py +++ b/tf2onnx/version.py @@ -1,5 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 -version = '1.15.1' -git_version = 'ae4c39ed3bdab7edf487d73d5892a573684d1d6a' +version = '1.16.0' +git_version = '898c069b872022a138a794332c16a75491dfb5c9' From 6a2d99e52c0a7956dc9b89e819321ad02dfb54d1 Mon Sep 17 00:00:00 2001 From: Jay Zhang <36183870+fatcat-z@users.noreply.github.com> Date: Fri, 5 Jan 2024 13:34:45 +0800 Subject: [PATCH 06/11] Correct the required version of protobuf. (#2288) Signed-off-by: Jay Zhang --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 847ec4f2e..85fece3a2 100644 --- a/setup.py +++ b/setup.py @@ -82,7 +82,7 @@ def run(self): author='ONNX', author_email='onnx-technical-discuss@lists.lfaidata.foundation', url='https://github.com/onnx/tensorflow-onnx', - install_requires=['numpy>=1.14.1', 'onnx>=1.4.1', 'requests', 'six', 'flatbuffers>=1.12', 'protobuf~=3.20.2'], + install_requires=['numpy>=1.14.1', 'onnx>=1.4.1', 'requests', 'six', 'flatbuffers>=1.12', 'protobuf~=3.20'], classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', From 13bab8a91e17ccd87541b2f361ab60e8e38359d3 Mon Sep 17 00:00:00 2001 From: Jay Zhang <36183870+fatcat-z@users.noreply.github.com> Date: Tue, 16 Jan 2024 08:45:27 +0800 Subject: [PATCH 07/11] Complete changes to support latest tensorflow. (#2292) Signed-off-by: Jay Zhang --- README.md | 4 +- .../keras2onnx_application_tests.yml | 65 +++++++++---------- .../azure_pipelines/keras2onnx_unit_test.yml | 35 ++++------ .../onnxruntime_nightly_test.yml | 6 +- .../pretrained_model_test-matrix.yml | 43 +++++------- .../azure_pipelines/pretrained_model_test.yml | 4 +- .../trimmed_keras2onnx_application_tests.yml | 18 ++--- .../trimmed_keras2onnx_unit_test.yml | 22 +++---- ci_build/azure_pipelines/unit_test-matrix.yml | 12 ++-- ci_build/azure_pipelines/unit_test.yml | 4 +- tests/test_api.py | 1 - tests/test_tflite_utils.py | 3 +- tf2onnx/tf_loader.py | 60 +++++++++++------ 13 files changed, 138 insertions(+), 139 deletions(-) diff --git a/README.md b/README.md index e272ab7a9..deea4667f 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ The common issues we run into we try to document here [Troubleshooting Guide](Tr | Build Type | OS | Python | TensorFlow | ONNX opset | Status | | --- | --- | --- | --- | --- | --- | -| Unit Test - Basic | Linux, Windows | 3.7-3.10 | 1.15, 2.9-2.13 | 14-18 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test?branchName=main)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=16&branchName=main) | -| Unit Test - Full | Linux, Windows | 3.7-3.10 | 1.15, 2.9-2.13 | 14-18 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test-matrix?branchName=main)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=18&branchName=main) | | +| Unit Test - Basic | Linux, Windows | 3.7-3.10 | 1.15, 2.9-2.15 | 14-18 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test?branchName=main)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=16&branchName=main) | +| Unit Test - Full | Linux, Windows | 3.7-3.10 | 1.15, 2.9-2.15 | 14-18 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test-matrix?branchName=main)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=18&branchName=main) | |
## Supported Versions diff --git a/ci_build/azure_pipelines/keras2onnx_application_tests.yml b/ci_build/azure_pipelines/keras2onnx_application_tests.yml index a81d586df..1db4dce93 100644 --- a/ci_build/azure_pipelines/keras2onnx_application_tests.yml +++ b/ci_build/azure_pipelines/keras2onnx_application_tests.yml @@ -8,18 +8,17 @@ jobs: vmImage: 'ubuntu-latest' strategy: matrix: - Python37-tf-1.15: - python.version: '3.7' # Max version that supports tf 1.15 - ONNX_PATH: onnx==1.14.1 # Max version that supports python 3.7 - INSTALL_KERAS: pip install keras==2.3.1 + Python310-tf2-2.13: + python.version: '3.10' + ONNX_PATH: onnx==1.15.0 + INSTALL_KERAS: UNINSTALL_KERAS: - INSTALL_TENSORFLOW: pip install tensorflow==1.15.0 - INSTALL_ORT: pip install onnxruntime==1.14.1 # Max version that supports python 3.7 + INSTALL_TENSORFLOW: pip install tensorflow==2.13.0 + INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_KERAS_RESNET: pip install keras-resnet - INSTALL_TRANSFORMERS: + INSTALL_TRANSFORMERS: pip install transformers==3.4.0 INSTALL_NUMPY: pip install numpy==1.19.0 - INSTALL_LEGACY: pip install h5py==2.9.0 - NIGHTLY_BUILD_TEST: python run_all_v2.py --exclude "test_keras_applications_v2.py" + NIGHTLY_BUILD_TEST: python run_all_v2.py Python39-tf2-2.12: python.version: '3.9' @@ -45,8 +44,8 @@ jobs: INSTALL_NUMPY: NIGHTLY_BUILD_TEST: python run_all_v2.py - Python38-tf2-2.10: - python.version: '3.8' + Python39-tf2-2.10: + python.version: '3.9' ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: @@ -57,18 +56,6 @@ jobs: INSTALL_NUMPY: NIGHTLY_BUILD_TEST: python run_all_v2.py - Python310-tf2-oldest: - python.version: '3.10' - ONNX_PATH: onnx==1.15.0 - INSTALL_KERAS: - UNINSTALL_KERAS: - INSTALL_TENSORFLOW: pip install tensorflow==2.9.0 - INSTALL_ORT: pip install onnxruntime==1.15.0 - INSTALL_KERAS_RESNET: pip install keras-resnet - INSTALL_TRANSFORMERS: pip install transformers==4.2.0 - INSTALL_NUMPY: - NIGHTLY_BUILD_TEST: python run_all_v2.py - steps: - template: 'templates/keras2onnx_application_tests.yml' parameters: @@ -93,32 +80,32 @@ jobs: INSTALL_LEGACY: pip install h5py==2.9.0 NIGHTLY_BUILD_TEST: python run_all_v2.py --exclude "test_keras_applications_v2.py" - Python310-tf2-2.13: + Python310-tf2-2.15: python.version: '3.10' ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: - INSTALL_TENSORFLOW: pip install tensorflow==2.13.0 + INSTALL_TENSORFLOW: pip install tensorflow==2.15.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_KERAS_RESNET: pip install keras-resnet INSTALL_TRANSFORMERS: pip install transformers==4.2.0 INSTALL_NUMPY: NIGHTLY_BUILD_TEST: python run_all_v2.py - Python39-tf2-2.12: - python.version: '3.9' + Python310-tf2-2.14: + python.version: '3.10' ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: - INSTALL_TENSORFLOW: pip install tensorflow==2.12.0 - INSTALL_ORT: pip install onnxruntime==1.15.1 + INSTALL_TENSORFLOW: pip install tensorflow==2.14.0 + INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_KERAS_RESNET: pip install keras-resnet - INSTALL_TRANSFORMERS: pip install transformers==3.4.0 - INSTALL_NUMPY: pip install numpy==1.19.0 + INSTALL_TRANSFORMERS: pip install transformers==4.2.0 + INSTALL_NUMPY: NIGHTLY_BUILD_TEST: python run_all_v2.py - Python310-tf2-2.11: - python.version: '3.10' + Python39-tf2-2.11: + python.version: '3.9' ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: @@ -141,6 +128,18 @@ jobs: INSTALL_NUMPY: NIGHTLY_BUILD_TEST: python run_all_v2.py + Python38-tf2-2.9: + python.version: '3.8' + ONNX_PATH: onnx==1.15.0 + INSTALL_KERAS: + UNINSTALL_KERAS: + INSTALL_TENSORFLOW: pip install tensorflow==2.9.0 + INSTALL_ORT: pip install onnxruntime==1.15.1 + INSTALL_KERAS_RESNET: pip install keras-resnet + INSTALL_TRANSFORMERS: pip install transformers==4.12.0 + INSTALL_NUMPY: + NIGHTLY_BUILD_TEST: python run_all_v2.py + steps: - template: 'templates/keras2onnx_application_tests.yml' parameters: diff --git a/ci_build/azure_pipelines/keras2onnx_unit_test.yml b/ci_build/azure_pipelines/keras2onnx_unit_test.yml index f4523b80b..47adaf412 100644 --- a/ci_build/azure_pipelines/keras2onnx_unit_test.yml +++ b/ci_build/azure_pipelines/keras2onnx_unit_test.yml @@ -15,8 +15,8 @@ jobs: INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: - Python38-tf2-2.12: - python.version: '3.8' + Python39-tf2-2.12: + python.version: '3.9' ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.12.0 INSTALL_ORT: pip install onnxruntime==1.15.0 @@ -29,20 +29,13 @@ jobs: INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: - Python310-tf2-2.10: - python.version: '3.10' + Python38-tf2-2.10: + python.version: '3.8' ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.10.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: - Python310-tf2-oldest: - python.version: '3.10' - ONNX_PATH: onnx==1.15.0 - TENSORFLOW_PATH: tensorflow==2.9.0 - INSTALL_ORT: pip install onnxruntime==1.15.0 - INSTALL_NUMPY: - ############ Pure Keras Unit Tests ############ Keras-Py37-tf1.15.0: python.version: '3.7' # Max version that supports tf 1.15 @@ -63,9 +56,16 @@ jobs: strategy: matrix: ############ TF Keras Unit Tests ############ - Python310-tf2-2.13: + Python310-tf2-2.14: python.version: '3.10' ONNX_PATH: onnx==1.15.0 + TENSORFLOW_PATH: tensorflow==2.14.0 + INSTALL_ORT: pip install onnxruntime==1.15.0 + INSTALL_NUMPY: + + Python39-tf2-2.13: + python.version: '3.9' + ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.13.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: @@ -84,20 +84,13 @@ jobs: INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: - Python310-tf2-2.10: - python.version: '3.10' + Python38-tf2-2.10: + python.version: '3.8' ONNX_PATH: onnx==1.15.0 TENSORFLOW_PATH: tensorflow==2.10.0 INSTALL_ORT: pip install onnxruntime==1.15.0 INSTALL_NUMPY: - Python310-tf2-oldest: - python.version: '3.10' - ONNX_PATH: onnx==1.15.0 - TENSORFLOW_PATH: tensorflow==2.9.0 - INSTALL_ORT: pip install onnxruntime==1.15.0 - INSTALL_NUMPY: - ############ Pure Keras Unit Tests ############ Keras-Py37-tf1.15.0: python.version: '3.7' # Max version that supports tf 1.15 diff --git a/ci_build/azure_pipelines/onnxruntime_nightly_test.yml b/ci_build/azure_pipelines/onnxruntime_nightly_test.yml index bfeaa75ae..af22662f8 100644 --- a/ci_build/azure_pipelines/onnxruntime_nightly_test.yml +++ b/ci_build/azure_pipelines/onnxruntime_nightly_test.yml @@ -19,7 +19,7 @@ stages: parameters: platforms: ['linux', 'windows'] python_versions: ['3.8'] - tf_versions: ['2.9.0', '2.10.0', '2.13.0'] + tf_versions: ['2.9.0', '2.10.0', '2.15.0'] onnx_backends: {onnxruntime: ['nightly']} job: steps: @@ -30,7 +30,7 @@ stages: parameters: platforms: ['linux', 'windows'] python_versions: ['3.9'] - tf_versions: ['2.12.0'] + tf_versions: ['2.11.0', '2.12.0'] onnx_backends: {onnxruntime: ['nightly']} job: steps: @@ -41,7 +41,7 @@ stages: parameters: platforms: ['linux', 'windows'] python_versions: ['3.10'] - tf_versions: ['2.9.0', '2.13.0'] + tf_versions: ['2.9.0', '2.15.0'] onnx_backends: {onnxruntime: ['nightly']} job: steps: diff --git a/ci_build/azure_pipelines/pretrained_model_test-matrix.yml b/ci_build/azure_pipelines/pretrained_model_test-matrix.yml index c29903637..30af716a2 100755 --- a/ci_build/azure_pipelines/pretrained_model_test-matrix.yml +++ b/ci_build/azure_pipelines/pretrained_model_test-matrix.yml @@ -8,7 +8,7 @@ jobs: python_versions: ['3.7'] # Max version that supports tf 1.15 tf_versions: ['1.15.5'] onnx_versions: ['1.14.1'] # Max version that supports python 3.7 - onnx_opsets: ['18', '17', '16', '15'] + onnx_opsets: ['18', '17', '16', '15', '14'] onnx_backends: {onnxruntime: ['1.14.1']} # Max version that supports python 3.7 job: steps: @@ -16,10 +16,12 @@ jobs: - template: 'templates/job_generator.yml' parameters: - platforms: ['windows'] - python_versions: ['3.8'] - tf_versions: ['2.9.0'] - onnx_opsets: ['18', '17', '16', '15'] + platforms: ['linux'] + python_versions: ['3.7'] # Max version that supports tf 1.15 + tf_versions: ['1.15.5'] + onnx_versions: ['1.14.1'] # Max version that supports python 3.7 + onnx_opsets: ['18', '17', '16', '14'] + onnx_backends: {onnxruntime: ['1.14.1']} # Max version that supports python 3.7 job: steps: - template: 'pretrained_model_test.yml' @@ -28,27 +30,15 @@ jobs: parameters: platforms: ['windows'] python_versions: ['3.9'] - tf_versions: ['2.13.0'] - onnx_opsets: ['18', '17', '16', '15'] - job: - steps: - - template: 'pretrained_model_test.yml' - -- template: 'templates/job_generator.yml' - parameters: - platforms: ['linux', 'windows'] - python_versions: ['3.7'] # Max version that supports tf 1.15 - tf_versions: ['1.15.5'] - onnx_versions: ['1.14.1'] # Max version that supports python 3.7 - onnx_opsets: ['18', '17', '16', '14'] - onnx_backends: {onnxruntime: ['1.14.1']} # Max version that supports python 3.7 + tf_versions: ['2.9.0', '2.15.0'] + onnx_opsets: ['18', '17', '16', '15', '14'] job: steps: - template: 'pretrained_model_test.yml' - template: 'templates/job_generator.yml' parameters: - platforms: ['linux', 'windows'] + platforms: ['linux'] python_versions: ['3.8'] tf_versions: ['2.9.0'] onnx_opsets: ['17', '16', '14'] @@ -58,9 +48,9 @@ jobs: - template: 'templates/job_generator.yml' parameters: - platforms: ['linux', 'windows'] - python_versions: ['3.9'] - tf_versions: ['2.13.0'] + platforms: ['linux'] + python_versions: ['3.10'] + tf_versions: ['2.15.0'] onnx_opsets: ['17', '16', '14'] job: steps: @@ -69,7 +59,7 @@ jobs: - template: 'templates/job_generator.yml' parameters: platforms: ['linux', 'windows'] - python_versions: ['3.10'] + python_versions: ['3.8'] tf_versions: ['2.10.0'] job: steps: @@ -86,10 +76,9 @@ jobs: - template: 'templates/job_generator.yml' parameters: - platforms: ['linux'] + platforms: ['linux', 'windows'] python_versions: ['3.10'] - tf_versions: ['2.9.0', '2.13.0'] - onnx_opsets: ['17', '16', '14'] + tf_versions: ['2.14.0'] job: steps: - template: 'pretrained_model_test.yml' diff --git a/ci_build/azure_pipelines/pretrained_model_test.yml b/ci_build/azure_pipelines/pretrained_model_test.yml index 3ac548a81..a5b757daa 100644 --- a/ci_build/azure_pipelines/pretrained_model_test.yml +++ b/ci_build/azure_pipelines/pretrained_model_test.yml @@ -27,7 +27,7 @@ jobs: parameters: platforms: ['linux'] python_versions: ['3.9'] - tf_versions: ['2.13.0'] + tf_versions: ['2.15.0'] onnx_opsets: ['18', '15'] job: steps: @@ -37,7 +37,7 @@ jobs: parameters: platforms: ['linux'] python_versions: ['3.10'] - tf_versions: ['2.9.0', '2.13.0'] + tf_versions: ['2.9.0', '2.15.0'] onnx_opsets: ['18', '15'] job: steps: diff --git a/ci_build/azure_pipelines/trimmed_keras2onnx_application_tests.yml b/ci_build/azure_pipelines/trimmed_keras2onnx_application_tests.yml index f30d2f8e4..2b0e66dd5 100644 --- a/ci_build/azure_pipelines/trimmed_keras2onnx_application_tests.yml +++ b/ci_build/azure_pipelines/trimmed_keras2onnx_application_tests.yml @@ -19,7 +19,7 @@ jobs: INSTALL_TRANSFORMERS: INSTALL_NUMPY: pip install numpy==1.19.0 INSTALL_LEGACY: pip install h5py==2.9.0 - NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py" + NIGHTLY_BUILD_TEST: python run_all_v2.py --exclude "test_keras_applications_v2.py" Python38-tf2-oldest: python.version: '3.8' @@ -33,36 +33,36 @@ jobs: INSTALL_NUMPY: NIGHTLY_BUILD_TEST: python run_all_v2.py - Python38-tf2-latest: + Python310-tf2-latest: python.version: '3.8' ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: - INSTALL_TENSORFLOW: pip install tensorflow==2.13.0 + INSTALL_TENSORFLOW: pip install tensorflow==2.15.0 INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_KERAS_RESNET: pip install keras-resnet INSTALL_TRANSFORMERS: pip install transformers==4.2.0 INSTALL_NUMPY: NIGHTLY_BUILD_TEST: python run_all_v2.py - Python310-tf2-oldest: - python.version: '3.10' + Python38-tf2-oldest-plus-1: + python.version: '3.8' ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: - INSTALL_TENSORFLOW: pip install tensorflow==2.9.0 + INSTALL_TENSORFLOW: pip install tensorflow==2.10.0 INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_KERAS_RESNET: pip install keras-resnet INSTALL_TRANSFORMERS: pip install transformers==4.2.0 INSTALL_NUMPY: NIGHTLY_BUILD_TEST: python run_all_v2.py - Python310-tf2-latest: - python.version: '3.10' + Python39-tf2-latest-minus-1: + python.version: '3.9' ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: - INSTALL_TENSORFLOW: pip install tensorflow==2.13.0 + INSTALL_TENSORFLOW: pip install tensorflow==2.14.0 INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_KERAS_RESNET: pip install keras-resnet INSTALL_TRANSFORMERS: pip install transformers==4.2.0 diff --git a/ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml b/ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml index 4f4aee22e..6fc84a41d 100644 --- a/ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml +++ b/ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml @@ -23,24 +23,24 @@ jobs: INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_NUMPY: - Python38-tf2-latest: - python.version: '3.8' + Python39-tf2-latest: + python.version: '3.9' ONNX_PATH: onnx==1.15.0 - TENSORFLOW_PATH: tensorflow==2.13.0 + TENSORFLOW_PATH: tensorflow==2.15.0 INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_NUMPY: - Python310-tf2-oldest: - python.version: '3.10' + Python39-tf2-oldest-plus-1: + python.version: '3.9' ONNX_PATH: onnx==1.15.0 - TENSORFLOW_PATH: tensorflow==2.9.0 + TENSORFLOW_PATH: tensorflow==2.10.0 INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_NUMPY: - Python310-tf2-latest: + Python310-tf2-latest-minus-1: python.version: '3.10' ONNX_PATH: onnx==1.15.0 - TENSORFLOW_PATH: tensorflow==2.13.0 + TENSORFLOW_PATH: tensorflow==2.14.0 INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_NUMPY: @@ -79,10 +79,10 @@ jobs: INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_NUMPY: - Python38-tf2-latest: - python.version: '3.8' + Python39-tf2-latest: + python.version: '3.9' ONNX_PATH: onnx==1.15.0 - TENSORFLOW_PATH: tensorflow==2.13.0 + TENSORFLOW_PATH: tensorflow==2.15.0 INSTALL_ORT: pip install onnxruntime==1.16.3 INSTALL_NUMPY: diff --git a/ci_build/azure_pipelines/unit_test-matrix.yml b/ci_build/azure_pipelines/unit_test-matrix.yml index 7d51ae95a..25cc33596 100644 --- a/ci_build/azure_pipelines/unit_test-matrix.yml +++ b/ci_build/azure_pipelines/unit_test-matrix.yml @@ -21,7 +21,7 @@ stages: parameters: python_versions: ['3.9'] platforms: ['linux', 'windows'] - tf_versions: ['2.13.0'] + tf_versions: ['2.15.0'] onnx_opsets: ['17', '16', '14'] skip_tflite_tests: 'False' skip_tf_tests: 'False' @@ -60,8 +60,8 @@ stages: - template: 'templates/job_generator.yml' parameters: platforms: ['linux', 'windows'] - python_versions: ['3.8'] - tf_versions: ['2.12.0'] + python_versions: ['3.10'] + tf_versions: ['2.14.0'] job: steps: - template: 'unit_test.yml' @@ -71,7 +71,7 @@ stages: parameters: platforms: ['linux', 'windows'] python_versions: ['3.9'] - tf_versions: ['2.10.0', '2.11.0', '2.12.0'] + tf_versions: ['2.12.0'] job: steps: - template: 'unit_test.yml' @@ -80,8 +80,8 @@ stages: - template: 'templates/job_generator.yml' parameters: platforms: ['linux', 'windows'] - python_versions: ['3.10'] - tf_versions: ['2.9.0', '2.13.0'] + python_versions: ['3.8'] + tf_versions: ['2.10.0', '2.11.0'] job: steps: - template: 'unit_test.yml' diff --git a/ci_build/azure_pipelines/unit_test.yml b/ci_build/azure_pipelines/unit_test.yml index 2f55d80a7..0149196ed 100644 --- a/ci_build/azure_pipelines/unit_test.yml +++ b/ci_build/azure_pipelines/unit_test.yml @@ -21,7 +21,7 @@ stages: parameters: python_versions: ['3.9'] platforms: ['linux', 'windows'] - tf_versions: ['2.13.0'] + tf_versions: ['2.15.0'] onnx_opsets: ['18', '15'] skip_tflite_tests: 'False' skip_tf_tests: 'False' @@ -35,7 +35,7 @@ stages: parameters: python_versions: ['3.10'] platforms: ['linux'] - tf_versions: ['2.9.0', '2.13.0'] + tf_versions: ['2.9.0', '2.15.0'] onnx_opsets: ['18', '15'] skip_tflite_tests: 'False' skip_tf_tests: 'False' diff --git a/tests/test_api.py b/tests/test_api.py index 7c583e755..19544c733 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -80,7 +80,6 @@ def test_keras_api_large(self): @requires_custom_ops() @check_tf_min_version("1.15") @check_opset_min_version(11, "SparseToDense") - @skip_tf_versions(["2.1", "2.13"], "TF ['2.1', '2.13'] keras model doesn't work; table not initialized") def test_keras_hashtable(self): feature_cols = [ diff --git a/tests/test_tflite_utils.py b/tests/test_tflite_utils.py index e4125c938..4b194fda7 100644 --- a/tests/test_tflite_utils.py +++ b/tests/test_tflite_utils.py @@ -61,9 +61,8 @@ def func(a, b, c): parse_tflite_graph(tflite_graphs[0], opcodes_map, model, tensor_shapes_override=tensor_shapes) self.assertEqual(2, op_cnt['TFL_MUL']) self.assertEqual(1, op_cnt['TFL_ADD']) - self.assertEqual(1, op_cnt['TFL_FULLY_CONNECTED']) - self.assertEqual(1, attr_cnt['WeightsFormat']) + self.assertEqual(1, attr_cnt['PotScaleInt16']) self.assertEqual(names, inputs) self.assertEqual(output_names, outputs) diff --git a/tf2onnx/tf_loader.py b/tf2onnx/tf_loader.py index 7ced1a9c9..b8196404f 100644 --- a/tf2onnx/tf_loader.py +++ b/tf2onnx/tf_loader.py @@ -8,7 +8,6 @@ from packaging.version import Version import tensorflow as tf -import numpy as np from google.protobuf.message import DecodeError from tensorflow.core.framework import tensor_pb2 from tensorflow.core.protobuf import saved_model_pb2 @@ -481,6 +480,26 @@ def _get_hash_table_info_from_trackable(trackable, table_info, placeholder_to_table_info[removed_resource_to_placeholder[table_handle]] = new_table_info[0] +def _get_resources_from_captures(concrete_func, graph_captures): + resource_id_to_placeholder = {} + placeholder_to_resource = {} + keys_to_be_removed = [] + + # pylint: disable=protected-access + variable_handles = {id(v.handle) for v in concrete_func.graph.variables} + for k, v in list(graph_captures.items()): + val_tensor, name_tensor = v + if val_tensor.dtype == tf.resource and id(val_tensor) not in variable_handles: + resource_id_to_placeholder[id(val_tensor)] = name_tensor.name.split(':')[0] + placeholder_to_resource[name_tensor.name.split(':')[0]] = val_tensor + keys_to_be_removed.append(k) + for i in reversed(range(len(concrete_func._captured_inputs))): + if concrete_func._captured_inputs[i] is val_tensor: + concrete_func._captured_inputs.pop(i) + + return resource_id_to_placeholder, placeholder_to_resource, keys_to_be_removed + + def _remove_non_variable_resources_from_captures(concrete_func): """ Removes all non-variable resources (such as tables) from a function's captured inputs to prevent tf from @@ -494,22 +513,24 @@ def _remove_non_variable_resources_from_captures(concrete_func): if hasattr(concrete_func.graph, '_captures') and hasattr(concrete_func, '_captured_inputs'): graph_captures_copy = concrete_func.graph._captures.copy() func_captures_copy = concrete_func._captured_inputs.copy() - variable_handles = {id(v.handle) for v in concrete_func.graph.variables} - for k, v in list(concrete_func.graph._captures.items()): - val_tensor, name_tensor = v - if val_tensor.dtype == tf.resource and id(val_tensor) not in variable_handles: - resource_id_to_placeholder[id(val_tensor)] = name_tensor.name.split(':')[0] - placeholder_to_resource[name_tensor.name.split(':')[0]] = val_tensor - del concrete_func.graph._captures[k] - for i in reversed(range(len(concrete_func._captured_inputs))): - if concrete_func._captured_inputs[i] is val_tensor: - concrete_func._captured_inputs.pop(i) - elif val_tensor.dtype != tf.resource: - npval = val_tensor.numpy() - if not hasattr(npval, 'dtype'): - # Hack around a TF bug until PR is merged: https://github.com/tensorflow/tensorflow/pull/45610 - arr = np.array(npval) - val_tensor.numpy = lambda arr=arr: arr + + resource_id_to_placeholder, placeholder_to_resource, keys_to_be_removed = \ + _get_resources_from_captures(concrete_func, concrete_func.graph._captures) + for key in keys_to_be_removed: + del concrete_func.graph._captures[key] + elif hasattr(concrete_func.graph, 'function_captures') and hasattr(concrete_func, '_captured_inputs'): + # Since tensorflow 2.13.0, _captures has been removed and replaced with function_captures + graph_captures = {} + for k, v in concrete_func.graph.function_captures.by_val_external.items(): + graph_captures[k] = (v, concrete_func.graph.function_captures.by_val_internal[k]) + graph_captures_copy = graph_captures.copy() + func_captures_copy = concrete_func._captured_inputs.copy() + + resource_id_to_placeholder, placeholder_to_resource, keys_to_be_removed = \ + _get_resources_from_captures(concrete_func, graph_captures) + for key in keys_to_be_removed: + del concrete_func.graph.function_captures.by_val_internal[key] + del concrete_func.graph.function_captures.by_val_external[key] else: logger.warning( "Could not search for non-variable resources. Concrete function internal representation may have changed.") @@ -636,14 +657,13 @@ def from_saved_model(model_path, input_names, output_names, tag=None, def from_keras(model_path, input_names, output_names): """Load keras model - experimental for now.""" - from tensorflow.python import keras as _keras - from tensorflow.python.eager import context + from tensorflow import keras as _keras from tensorflow.python.keras.saving import saving_utils as _saving_utils # Handles Keras when Eager mode is enabled. custom_objects = None with tf.device("/cpu:0"): - if context.executing_eagerly(): + if tf.executing_eagerly(): _keras.backend.clear_session() _keras.backend.set_learning_phase(False) keras_model = _keras.models.load_model(model_path, custom_objects) From 15c810350056be3d7cb880fc8c7dfda5bd1ee6e8 Mon Sep 17 00:00:00 2001 From: Jay Zhang <36183870+fatcat-z@users.noreply.github.com> Date: Tue, 16 Jan 2024 17:53:31 +0800 Subject: [PATCH 08/11] Prepare updates for release 1.16.1. (#2293) Signed-off-by: Jay Zhang --- VERSION_NUMBER | 2 +- tf2onnx/version.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VERSION_NUMBER b/VERSION_NUMBER index 15b989e39..41c11ffb7 100644 --- a/VERSION_NUMBER +++ b/VERSION_NUMBER @@ -1 +1 @@ -1.16.0 +1.16.1 diff --git a/tf2onnx/version.py b/tf2onnx/version.py index b69fa91e2..3727236be 100644 --- a/tf2onnx/version.py +++ b/tf2onnx/version.py @@ -1,5 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 -version = '1.16.0' -git_version = '898c069b872022a138a794332c16a75491dfb5c9' +version = '1.16.1' +git_version = '13bab8a91e17ccd87541b2f361ab60e8e38359d3' From baf5ad0855ed709d4857c6effc2b25f65723816c Mon Sep 17 00:00:00 2001 From: Jay Zhang <36183870+fatcat-z@users.noreply.github.com> Date: Wed, 17 Jan 2024 18:11:00 +0800 Subject: [PATCH 09/11] Remove some windows tests. (#2294) Signed-off-by: Jay Zhang --- .../keras2onnx_application_tests.yml | 16 ++-------------- .../azure_pipelines/onnxruntime_nightly_test.yml | 4 ++-- .../pretrained_model_test-matrix.yml | 2 +- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/ci_build/azure_pipelines/keras2onnx_application_tests.yml b/ci_build/azure_pipelines/keras2onnx_application_tests.yml index 1db4dce93..400fdc395 100644 --- a/ci_build/azure_pipelines/keras2onnx_application_tests.yml +++ b/ci_build/azure_pipelines/keras2onnx_application_tests.yml @@ -80,8 +80,8 @@ jobs: INSTALL_LEGACY: pip install h5py==2.9.0 NIGHTLY_BUILD_TEST: python run_all_v2.py --exclude "test_keras_applications_v2.py" - Python310-tf2-2.15: - python.version: '3.10' + Python39-tf2-2.15: + python.version: '3.9' ONNX_PATH: onnx==1.15.0 INSTALL_KERAS: UNINSTALL_KERAS: @@ -92,18 +92,6 @@ jobs: INSTALL_NUMPY: NIGHTLY_BUILD_TEST: python run_all_v2.py - Python310-tf2-2.14: - python.version: '3.10' - ONNX_PATH: onnx==1.15.0 - INSTALL_KERAS: - UNINSTALL_KERAS: - INSTALL_TENSORFLOW: pip install tensorflow==2.14.0 - INSTALL_ORT: pip install onnxruntime==1.15.0 - INSTALL_KERAS_RESNET: pip install keras-resnet - INSTALL_TRANSFORMERS: pip install transformers==4.2.0 - INSTALL_NUMPY: - NIGHTLY_BUILD_TEST: python run_all_v2.py - Python39-tf2-2.11: python.version: '3.9' ONNX_PATH: onnx==1.15.0 diff --git a/ci_build/azure_pipelines/onnxruntime_nightly_test.yml b/ci_build/azure_pipelines/onnxruntime_nightly_test.yml index af22662f8..8a184ec50 100644 --- a/ci_build/azure_pipelines/onnxruntime_nightly_test.yml +++ b/ci_build/azure_pipelines/onnxruntime_nightly_test.yml @@ -19,7 +19,7 @@ stages: parameters: platforms: ['linux', 'windows'] python_versions: ['3.8'] - tf_versions: ['2.9.0', '2.10.0', '2.15.0'] + tf_versions: ['2.9.0', '2.10.0'] onnx_backends: {onnxruntime: ['nightly']} job: steps: @@ -41,7 +41,7 @@ stages: parameters: platforms: ['linux', 'windows'] python_versions: ['3.10'] - tf_versions: ['2.9.0', '2.15.0'] + tf_versions: ['2.13.0', '2.15.0'] onnx_backends: {onnxruntime: ['nightly']} job: steps: diff --git a/ci_build/azure_pipelines/pretrained_model_test-matrix.yml b/ci_build/azure_pipelines/pretrained_model_test-matrix.yml index 30af716a2..f297a3e3c 100755 --- a/ci_build/azure_pipelines/pretrained_model_test-matrix.yml +++ b/ci_build/azure_pipelines/pretrained_model_test-matrix.yml @@ -31,7 +31,7 @@ jobs: platforms: ['windows'] python_versions: ['3.9'] tf_versions: ['2.9.0', '2.15.0'] - onnx_opsets: ['18', '17', '16', '15', '14'] + onnx_opsets: ['18', '17', '16', '15'] job: steps: - template: 'pretrained_model_test.yml' From 9538da86d8e932d0eea8f0999672ea1a6a203b57 Mon Sep 17 00:00:00 2001 From: Martin Simonovsky Date: Mon, 29 Jan 2024 06:47:41 +0100 Subject: [PATCH 10/11] fix types (#2299) Signed-off-by: Martin Simonovsky Co-authored-by: Martin Simonovsky --- tf2onnx/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tf2onnx/utils.py b/tf2onnx/utils.py index 9d46e3c6a..3bbb7639f 100644 --- a/tf2onnx/utils.py +++ b/tf2onnx/utils.py @@ -198,8 +198,8 @@ def make_onnx_node_with_attr(op_type: str, inputs: Sequence[str], outputs: Seque valid_attrs = {} if kwargs: for key, value in sorted(kwargs.items()): - if not isinstance(value, bytes) and \ - isinstance(value, collections.abc.Sequence) and len(list(value)) == 0: + if not isinstance(value, (bytes, str)) and \ + isinstance(value, collections.abc.Iterable) and len(list(value)) == 0: attr_empty_lists[key] = value else: valid_attrs[key] = value From 358b519e14163c9087e778cfe8ff3b603ef88300 Mon Sep 17 00:00:00 2001 From: Jay Zhang <36183870+fatcat-z@users.noreply.github.com> Date: Wed, 6 Mar 2024 15:27:33 +0800 Subject: [PATCH 11/11] Azure pipeline task CondaEnvironment@1 has been deprecated. (#2309) * Replace CondaEnvironment@1 azure task with UsePythonVersion@0. * Remove unnecessary steps. --------- Signed-off-by: Jay Zhang --- .../templates/combine_test_coverage.yml | 8 +++----- .../templates/job_generator.yml | 18 +++--------------- .../templates/keras2onnx_application_tests.yml | 12 +++--------- .../templates/keras2onnx_unit_test.yml | 15 +++------------ 4 files changed, 12 insertions(+), 41 deletions(-) diff --git a/ci_build/azure_pipelines/templates/combine_test_coverage.yml b/ci_build/azure_pipelines/templates/combine_test_coverage.yml index f31b25c3b..53d573abf 100644 --- a/ci_build/azure_pipelines/templates/combine_test_coverage.yml +++ b/ci_build/azure_pipelines/templates/combine_test_coverage.yml @@ -20,12 +20,10 @@ stages: artifactName: '${{ parameters.artifact_name }}' downloadPath: $(System.DefaultWorkingDirectory) - - task: CondaEnvironment@1 + - task: UsePythonVersion@0 inputs: - createCustomEnvironment: 'true' - environmentName: 'tf2onnx' - packageSpecs: 'python=3.7' - updateConda: 'false' + versionSpec: '3.7' + architecture: 'x64' - bash: | pip install -U coverage diff --git a/ci_build/azure_pipelines/templates/job_generator.yml b/ci_build/azure_pipelines/templates/job_generator.yml index 811949d00..826ff03c6 100644 --- a/ci_build/azure_pipelines/templates/job_generator.yml +++ b/ci_build/azure_pipelines/templates/job_generator.yml @@ -78,22 +78,10 @@ jobs: - bash: env displayName: 'Display Environment Variables' -# TODO: ordinary python is preferred but built-in python3.6 does not have libpython3.6m.so, onnxruntime will fail with -# Error: 'libpython3.6m.so.1.0: cannot open shared object file: No such file or directory' -# so have to use conda here, may switch back to UsePythonVersion when the issue is fixed. -# - task: UsePythonVersion@0 -# inputs: -# versionSpec: '$(CI_PYTHON_VERSION)' -# architecture: 'x64' - -# TODO: Conda Environment task is deprecating, move to raw python after issue above is fixed. -# https://github.com/Microsoft/azure-pipelines-tasks/pull/9573 - - task: CondaEnvironment@1 + - task: UsePythonVersion@0 inputs: - createCustomEnvironment: 'true' - environmentName: 'tf2onnx' - packageSpecs: 'python=$(CI_PYTHON_VERSION)' - updateConda: 'false' + versionSpec: '$(CI_PYTHON_VERSION)' + architecture: 'x64' - ${{ if eq(parameters.run_setup, 'True') }}: - template: 'setup.yml' diff --git a/ci_build/azure_pipelines/templates/keras2onnx_application_tests.yml b/ci_build/azure_pipelines/templates/keras2onnx_application_tests.yml index 61d0eb2ad..2c4a54e7c 100644 --- a/ci_build/azure_pipelines/templates/keras2onnx_application_tests.yml +++ b/ci_build/azure_pipelines/templates/keras2onnx_application_tests.yml @@ -9,11 +9,10 @@ steps: - script: sudo install -d -m 0777 /home/vsts/.conda/envs displayName: Fix Conda permissions - - task: CondaEnvironment@1 + - task: UsePythonVersion@0 inputs: - createCustomEnvironment: true - environmentName: 'py$(python.version)' - packageSpecs: 'python=$(python.version)' + versionSpec: '$(python.version)' + architecture: 'x64' - script: | python -m pip install --upgrade pip @@ -80,11 +79,7 @@ steps: - powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" displayName: Add conda to PATH - - script: conda create --yes --quiet --name py$(python.version) -c conda-forge python=$(python.version) numpy protobuf~=3.20 - displayName: Create Anaconda environment - - script: | - call activate py$(python.version) python -m pip install --upgrade pip numpy echo Test numpy installation... && python -c "import numpy" pip install onnxconverter-common @@ -119,7 +114,6 @@ steps: displayName: 'Install dependencies' - script: | - call activate py$(python.version) pip install -e . echo Test onnxruntime installation... && python -c "import onnxruntime" pytest tests/keras2onnx_unit_tests --doctest-modules --junitxml=junit/test-results.xml diff --git a/ci_build/azure_pipelines/templates/keras2onnx_unit_test.yml b/ci_build/azure_pipelines/templates/keras2onnx_unit_test.yml index e0f6cd54b..adb436f0a 100644 --- a/ci_build/azure_pipelines/templates/keras2onnx_unit_test.yml +++ b/ci_build/azure_pipelines/templates/keras2onnx_unit_test.yml @@ -9,11 +9,10 @@ steps: - script: sudo install -d -m 0777 /home/vsts/.conda/envs displayName: Fix Conda permissions - - task: CondaEnvironment@1 + - task: UsePythonVersion@0 inputs: - createCustomEnvironment: true - environmentName: 'py$(python.version)' - packageSpecs: 'python=$(python.version)' + versionSpec: '$(python.version)' + architecture: 'x64' - script: | python -m pip install --upgrade pip @@ -63,14 +62,7 @@ steps: versionSpec: '$(python.version)' architecture: 'x64' - - powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" - displayName: Add conda to PATH - - - script: conda create --yes --quiet --name py$(python.version) -c conda-forge python=$(python.version) numpy protobuf~=3.20 - displayName: Create Anaconda environment - - script: | - call activate py$(python.version) python -m pip install --upgrade pip numpy echo Test numpy installation... && python -c "import numpy" pip install onnxconverter-common @@ -91,7 +83,6 @@ steps: displayName: 'Install dependencies' - script: | - call activate py$(python.version) pip install -e . echo Test onnxruntime installation... && python -c "import onnxruntime" python -c "import onnxconverter_common"