From 4cfa05abd3461f12e626bacd0feec5a06cc74de9 Mon Sep 17 00:00:00 2001 From: David Fan Date: Tue, 12 May 2020 21:31:27 -0700 Subject: [PATCH] test --- .../linux-CI-keras-applications-nightly.yml | 10 +++--- .azure-pipelines/linux-conda-CI-tf-keras.yml | 4 +-- .azure-pipelines/linux-conda-CI.yml | 4 +-- .../win32-CI-keras-applications-nightly.yml | 10 +++--- .azure-pipelines/win32-conda-CI-tf-keras.yml | 4 +-- .azure-pipelines/win32-conda-CI.yml | 4 +-- keras2onnx/_builtin.py | 10 ++++++ keras2onnx/_consts.py | 1 + tests/test_layers.py | 33 ++++++++++++++++++- 9 files changed, 61 insertions(+), 19 deletions(-) diff --git a/.azure-pipelines/linux-CI-keras-applications-nightly.yml b/.azure-pipelines/linux-CI-keras-applications-nightly.yml index ed6df241..9845ef11 100644 --- a/.azure-pipelines/linux-CI-keras-applications-nightly.yml +++ b/.azure-pipelines/linux-CI-keras-applications-nightly.yml @@ -21,7 +21,7 @@ jobs: INSTALL_KERAS: pip install keras==2.1.6 UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==1.15.0 - INSTALL_ORT: pip install onnxruntime==1.1.1 + INSTALL_ORT: pip install onnxruntime==1.2.0 INSTALL_KERAS_RESNET: INSTALL_TRANSFORMERS: NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py" @@ -32,14 +32,14 @@ jobs: INSTALL_KERAS: pip install keras==2.2.4 UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==1.15.0 - INSTALL_ORT: pip install onnxruntime==1.1.1 + INSTALL_ORT: pip install onnxruntime==1.2.0 INSTALL_KERAS_RESNET: pip install keras-resnet INSTALL_TRANSFORMERS: NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py" Python37: python.version: '3.7.3' - ONNX_PATH: onnx==1.6.0 + ONNX_PATH: onnx==1.7.0 INSTALL_KERAS: pip install keras UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==1.15.0 @@ -54,14 +54,14 @@ jobs: INSTALL_KERAS: pip install keras UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==1.15.0 - INSTALL_ORT: pip install onnxruntime==1.1.1 + INSTALL_ORT: pip install onnxruntime==1.2.0 INSTALL_KERAS_RESNET: pip install keras-resnet INSTALL_TRANSFORMERS: NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py" Python37-tf2: python.version: '3.7.3' - ONNX_PATH: onnx==1.6.0 + ONNX_PATH: onnx==1.7.0 INSTALL_KERAS: UNINSTALL_KERAS: pip uninstall keras -y INSTALL_TENSORFLOW: pip install tensorflow==2.2.0 diff --git a/.azure-pipelines/linux-conda-CI-tf-keras.yml b/.azure-pipelines/linux-conda-CI-tf-keras.yml index cf98957b..5de2ad1f 100644 --- a/.azure-pipelines/linux-conda-CI-tf-keras.yml +++ b/.azure-pipelines/linux-conda-CI-tf-keras.yml @@ -18,13 +18,13 @@ jobs: python.version: '3.5' ONNX_PATH: onnx==1.2.3 TENSORFLOW_PATH: tensorflow==1.11.0 - INSTALL_ORT: pip install onnxruntime==1.1.1 + INSTALL_ORT: pip install onnxruntime==1.2.0 Python36: python.version: '3.6' ONNX_PATH: onnx==1.5.0 TENSORFLOW_PATH: tensorflow==1.15.0 - INSTALL_ORT: pip install onnxruntime==1.1.1 + INSTALL_ORT: pip install onnxruntime==1.2.0 Python37: python.version: '3.7' diff --git a/.azure-pipelines/linux-conda-CI.yml b/.azure-pipelines/linux-conda-CI.yml index 3474e8b8..218c1844 100644 --- a/.azure-pipelines/linux-conda-CI.yml +++ b/.azure-pipelines/linux-conda-CI.yml @@ -19,14 +19,14 @@ jobs: ONNX_PATH: onnx==1.2.3 KERAS: keras==2.1.6 TENSORFLOW_PATH: tensorflow==1.11.0 - INSTALL_ORT: pip install onnxruntime==1.1.1 + INSTALL_ORT: pip install onnxruntime==1.2.0 Python36-tf1150: python.version: '3.6' ONNX_PATH: onnx==1.5.0 KERAS: keras==2.2.5 TENSORFLOW_PATH: tensorflow==1.15.0 - INSTALL_ORT: pip install onnxruntime==1.1.1 + INSTALL_ORT: pip install onnxruntime==1.2.0 Python37-tf200: python.version: '3.7' diff --git a/.azure-pipelines/win32-CI-keras-applications-nightly.yml b/.azure-pipelines/win32-CI-keras-applications-nightly.yml index ae7c29af..eedb5645 100644 --- a/.azure-pipelines/win32-CI-keras-applications-nightly.yml +++ b/.azure-pipelines/win32-CI-keras-applications-nightly.yml @@ -21,7 +21,7 @@ jobs: INSTALL_KERAS: pip install keras==2.1.6 UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==1.14.0 - INSTALL_ORT: pip install onnxruntime==1.1.1 + INSTALL_ORT: pip install onnxruntime==1.2.0 INSTALL_KERAS_RESNET: INSTALL_TRANSFORMERS: NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py test_mask_rcnn.py" @@ -32,14 +32,14 @@ jobs: INSTALL_KERAS: pip install keras==2.2.4 UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==1.14.0 - INSTALL_ORT: pip install onnxruntime==1.1.1 + INSTALL_ORT: pip install onnxruntime==1.2.0 INSTALL_KERAS_RESNET: pip install keras-resnet INSTALL_TRANSFORMERS: NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py test_mask_rcnn.py" Python37: python.version: '3.7' - ONNX_PATH: onnx==1.6.0 + ONNX_PATH: onnx==1.7.0 INSTALL_KERAS: pip install keras UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==1.14.0 @@ -54,7 +54,7 @@ jobs: INSTALL_KERAS: pip install keras UNINSTALL_KERAS: INSTALL_TENSORFLOW: pip install tensorflow==1.14.0 - INSTALL_ORT: pip install onnxruntime==1.1.1 + INSTALL_ORT: pip install onnxruntime==1.2.0 INSTALL_KERAS_RESNET: pip install keras-resnet INSTALL_TRANSFORMERS: NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py test_mask_rcnn.py" @@ -65,7 +65,7 @@ jobs: INSTALL_KERAS: UNINSTALL_KERAS: pip uninstall keras -y INSTALL_TENSORFLOW: pip install tensorflow==2.2.0 - INSTALL_ORT: pip install onnxruntime==1.1.1 + INSTALL_ORT: pip install onnxruntime==1.2.0 INSTALL_KERAS_RESNET: pip install keras-resnet INSTALL_TRANSFORMERS: pip install transformers NIGHTLY_BUILD_TEST: pytest test_keras_applications_v2.py test_transformers.py test_efn.py --doctest-modules --junitxml=junit/test-results-v2.xml diff --git a/.azure-pipelines/win32-conda-CI-tf-keras.yml b/.azure-pipelines/win32-conda-CI-tf-keras.yml index 69cd7d35..8b21df75 100644 --- a/.azure-pipelines/win32-conda-CI-tf-keras.yml +++ b/.azure-pipelines/win32-conda-CI-tf-keras.yml @@ -18,13 +18,13 @@ jobs: python.version: '3.5' ONNX_PATH: onnx==1.2.3 TENSORFLOW_PATH: tensorflow==1.11.0 - INSTALL_ORT: pip install onnxruntime==1.1.1 + INSTALL_ORT: pip install onnxruntime==1.2.0 Python36: python.version: '3.6' ONNX_PATH: onnx==1.5.0 TENSORFLOW_PATH: tensorflow==1.14.0 - INSTALL_ORT: pip install onnxruntime==1.1.1 + INSTALL_ORT: pip install onnxruntime==1.2.0 Python37: python.version: '3.7' diff --git a/.azure-pipelines/win32-conda-CI.yml b/.azure-pipelines/win32-conda-CI.yml index 33636663..dcd84631 100644 --- a/.azure-pipelines/win32-conda-CI.yml +++ b/.azure-pipelines/win32-conda-CI.yml @@ -19,14 +19,14 @@ jobs: ONNX_PATH: onnx==1.2.3 KERAS: keras==2.1.6 TENSORFLOW_PATH: tensorflow==1.11.0 - INSTALL_ORT: pip install onnxruntime==1.1.1 + INSTALL_ORT: pip install onnxruntime==1.2.0 Python36-tf1140: python.version: '3.6' ONNX_PATH: onnx==1.5.0 KERAS: keras==2.2.5 TENSORFLOW_PATH: tensorflow==1.15.0 - INSTALL_ORT: pip install onnxruntime==1.1.1 + INSTALL_ORT: pip install onnxruntime==1.2.0 Python37-tf200: python.version: '3.7' diff --git a/keras2onnx/_builtin.py b/keras2onnx/_builtin.py index 88b9be3c..d3c6f292 100644 --- a/keras2onnx/_builtin.py +++ b/keras2onnx/_builtin.py @@ -900,6 +900,16 @@ def _convert_tf_maximum_minimum(scope, operator, container, oopb, apply_func): name=operator.full_name + '_identity') +@converter_func(TYPES.MatrixInverse) +def convert_tf_logical_not(scope, operator, container): + oopb = OnnxOperatorBuilder(container, scope) + oopb.add_node_with_output('Inverse', + operator.input_full_names, + operator.output_full_names, + name=operator.full_name, + op_domain='com.microsoft', + op_version=1) + @converter_func(TYPES.Maximum) def convert_tf_maximum(scope, operator, container): oopb = OnnxOperatorBuilder(container, scope) diff --git a/keras2onnx/_consts.py b/keras2onnx/_consts.py index 96a190f5..96d76709 100644 --- a/keras2onnx/_consts.py +++ b/keras2onnx/_consts.py @@ -42,6 +42,7 @@ class TYPES: LogicalNot = 'LogicalNot' LogSoftmax = 'LogSoftmax' MatMul = 'MatMul' + MatrixInverse = 'MatrixInverse' Max = 'Max' Maximum = 'Maximum' Mean = 'Mean' diff --git a/tests/test_layers.py b/tests/test_layers.py index c7517c92..f8476a5b 100644 --- a/tests/test_layers.py +++ b/tests/test_layers.py @@ -6,7 +6,7 @@ import pytest import keras2onnx import numpy as np -from onnxconverter_common.onnx_ex import get_maximum_opset_supported +from onnxconverter_common.onnx_ex import get_maximum_opset_supported, onnx_builtin_opset_version from keras2onnx.proto.tfcompat import is_tf2, tensorflow as tf from keras2onnx.proto import (keras, is_tf_keras, is_tensorflow_older_than, is_tensorflow_later_than, @@ -167,6 +167,37 @@ def test_tf_bias_add(runner): assert runner('onnx_bias_add', onnx_model, data, expected) +def test_tf_clip(runner): + model = Sequential() + model.add(Lambda(lambda x: K.clip(x, 0, 10), input_shape=[5, 5])) + data = np.random.randint(-5, 15, size=(1, 5, 5)).astype(np.float32) + expected = model.predict(data) + onnx_model = keras2onnx.convert_keras(model, 'test_tf_clip') + assert runner('onnx_tf_clip', onnx_model, data, expected) + + +@pytest.mark.skipif(onnx_builtin_opset_version() < 12, + reason="Inverse is not supported until opset 12") +def test_tf_inverse(runner): + model = Sequential() + model.add(Lambda(lambda x: tf.linalg.inv(x), input_shape=[5, 5])) + data = np.random.rand(3, 5, 5).astype(np.float32) + expected = model.predict(data) + onnx_model = keras2onnx.convert_keras(model, 'test_tf_inverse') + assert runner('onnx_tf_inverse', onnx_model, data, expected) + + +def test_tf_pow(runner): + model = Sequential() + y = tf.constant([[2.0, 2.0], [2.0, 2.0]]) + model.add(Lambda(lambda x: tf.math.pow(tf.cast(x, tf.int32), tf.cast(y, tf.int32)), input_shape=[2, 2])) + data = (100 * np.random.rand(3, 2, 2)).astype(np.float32) + expected = model.predict(data) + onnx_model = keras2onnx.convert_keras(model, 'test_tf_pow', target_opset=12) + keras2onnx.save_model(onnx_model, 'pow.onnx') + assert runner('onnx_tf_pow', onnx_model, data, expected) + + def test_tf_concat(runner): def my_func_1(x): return tf.concat([x[0], x[1]], 1)