Skip to content

Update tf2onnx to support latest tf version. #2131

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ci_build/azure_pipelines/keras2onnx_unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ jobs:
INSTALL_ORT: pip install onnxruntime==1.12.0
INSTALL_NUMPY:

Python310-tf2.10:
python.version: '3.10'
ONNX_PATH: onnx==1.12.0
TENSORFLOW_PATH: tensorflow==2.10.0
INSTALL_ORT: pip install onnxruntime==1.13.1
INSTALL_NUMPY:

############ Pure Keras Unit Tests ############
Keras-Py37-tf1.15.0:
python.version: '3.7'
Expand Down Expand Up @@ -78,6 +85,13 @@ jobs:
INSTALL_ORT: pip install onnxruntime==1.12.0
INSTALL_NUMPY:

Python310-tf2.10:
python.version: '3.10'
ONNX_PATH: onnx==1.12.0
TENSORFLOW_PATH: tensorflow==2.10.0
INSTALL_ORT: pip install onnxruntime==1.13.1
INSTALL_NUMPY:

############ Pure Keras Unit Tests ############
Keras-Py37-tf1.15.0:
python.version: '3.7'
Expand Down
8 changes: 8 additions & 0 deletions ci_build/azure_pipelines/pretrained_model_test-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ jobs:
steps:
- template: 'pretrained_model_test.yml'

- template: 'templates/job_generator.yml'
parameters:
python_versions: ['3.9']
tf_versions: ['2.11.0']
job:
steps:
- template: 'pretrained_model_test.yml'

schedules:
- cron: "0 10 * * *"
displayName: pre-trained model test, full matrix
Expand Down
4 changes: 4 additions & 0 deletions ci_build/azure_pipelines/templates/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ steps:
else
pip install tensorflow-text
fi
if [[ $CI_TF_VERSION < 2.8 ]] ;
then
pip install wrapt==1.14.1
fi
fi

# Protobuf 3.20 results in linker errors on Windows in TF.
Expand Down
24 changes: 18 additions & 6 deletions ci_build/azure_pipelines/trimmed_keras2onnx_application_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,37 @@ jobs:
INSTALL_LEGACY: pip install h5py==2.9.0
NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py"

Python38-tf2-latest:
Python38-tf-2.9:
python.version: '3.8'
ONNX_PATH: onnx==1.12.0
INSTALL_KERAS:
UNINSTALL_KERAS:
INSTALL_TENSORFLOW: pip install tensorflow==2.10.0
INSTALL_ORT: pip install onnxruntime==1.13.1
INSTALL_TENSORFLOW: pip install tensorflow==2.9.1
INSTALL_ORT: pip install onnxruntime==1.12.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-tf-2.x:
Python38-tf2-2.10:
python.version: '3.8'
ONNX_PATH: onnx==1.12.0
INSTALL_KERAS:
UNINSTALL_KERAS:
INSTALL_TENSORFLOW: pip install tensorflow==2.9.1
INSTALL_ORT: pip install onnxruntime==1.12.0
INSTALL_TENSORFLOW: pip install tensorflow==2.10.0
INSTALL_ORT: pip install onnxruntime==1.13.1
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.11:
python.version: '3.9'
ONNX_PATH: onnx==1.13.1
INSTALL_KERAS:
UNINSTALL_KERAS:
INSTALL_TENSORFLOW: pip install tensorflow==2.11.0
INSTALL_ORT: pip install onnxruntime==1.13.1
INSTALL_KERAS_RESNET: pip install keras-resnet
INSTALL_TRANSFORMERS: pip install transformers==4.2.0
INSTALL_NUMPY:
Expand Down
8 changes: 4 additions & 4 deletions ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:

Python310-tf-latest:
python.version: '3.10'
ONNX_PATH: onnx==1.12.0
TENSORFLOW_PATH: tensorflow==2.10.0
ONNX_PATH: onnx==1.13.1
TENSORFLOW_PATH: tensorflow==2.11.0
INSTALL_ORT: pip install onnxruntime==1.13.1
INSTALL_NUMPY:

Expand Down Expand Up @@ -66,8 +66,8 @@ jobs:

Python310-tf-latest:
python.version: '3.10'
ONNX_PATH: onnx==1.12.0
TENSORFLOW_PATH: tensorflow==2.10.0
ONNX_PATH: onnx==1.13.1
TENSORFLOW_PATH: tensorflow==2.11.0
INSTALL_ORT: pip install onnxruntime==1.13.1
INSTALL_NUMPY:

Expand Down
2 changes: 1 addition & 1 deletion ci_build/azure_pipelines/unit_test-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ stages:
parameters:
platforms: ['windows']
python_versions: ['3.9']
tf_versions: ['2.9.0']
tf_versions: ['2.9.1']
onnx_opsets: ['']
job:
steps:
Expand Down
21 changes: 17 additions & 4 deletions ci_build/azure_pipelines/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ stages:
# - template: 'unit_test.yml'
# report_coverage: 'True'

- template: 'templates/job_generator.yml'
parameters:
python_versions: ['3.10']
tf_versions: ['2.11.0']
onnx_opsets: ['']
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.8']
Expand Down Expand Up @@ -132,10 +145,10 @@ stages:

- template: 'templates/job_generator.yml'
parameters:
python_versions: ['3.9']
python_versions: ['3.10']
platforms: ['windows']
tf_versions: ['2.9.1']
onnx_opsets: ['16']
onnx_opsets: ['17']
job:
steps:
- template: 'unit_test.yml'
Expand All @@ -145,8 +158,8 @@ stages:
parameters:
python_versions: ['3.10']
platforms: ['windows']
tf_versions: ['2.9.1']
onnx_opsets: ['17']
tf_versions: ['2.11.0']
onnx_opsets: ['16']
job:
steps:
- template: 'unit_test.yml'
Expand Down
4 changes: 3 additions & 1 deletion tests/keras2onnx_unit_tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@


# 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.12.0": 17, "1.13.0": 17, "1.14.0": 17
}

working_path = os.path.abspath(os.path.dirname(__file__))
Expand Down
40 changes: 40 additions & 0 deletions tf2onnx/tflite/ATan2Options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# SPDX-License-Identifier: Apache-2.0

# automatically generated by the FlatBuffers compiler, do not modify

# namespace: tflite

import flatbuffers
from flatbuffers.compat import import_numpy
np = import_numpy()

class ATan2Options(object):
__slots__ = ['_tab']

@classmethod
def GetRootAs(cls, buf, offset=0):
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
x = ATan2Options()
x.Init(buf, n + offset)
return x

@classmethod
def GetRootAsATan2Options(cls, buf, offset=0):
"""This method is deprecated. Please switch to GetRootAs."""
return cls.GetRootAs(buf, offset)
@classmethod
def ATan2OptionsBufferHasIdentifier(cls, buf, offset, size_prefixed=False):
return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x54\x46\x4C\x33", size_prefixed=size_prefixed)

# ATan2Options
def Init(self, buf, pos):
self._tab = flatbuffers.table.Table(buf, pos)

def Start(builder): builder.StartObject(0)
def ATan2OptionsStart(builder):
"""This method is deprecated. Please switch to Start."""
return Start(builder)
def End(builder): return builder.EndObject()
def ATan2OptionsEnd(builder):
"""This method is deprecated. Please switch to End."""
return End(builder)
7 changes: 7 additions & 0 deletions tf2onnx/tflite/BuiltinOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,11 @@ class BuiltinOperator(object):
MULTINOMIAL = 149
GELU = 150
DYNAMIC_UPDATE_SLICE = 151
RELU_0_TO_1 = 152
UNSORTED_SEGMENT_PROD = 153
UNSORTED_SEGMENT_MAX = 154
UNSORTED_SEGMENT_SUM = 155
ATAN2 = 156
UNSORTED_SEGMENT_MIN = 157
SIGN = 158

6 changes: 6 additions & 0 deletions tf2onnx/tflite/BuiltinOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,10 @@ class BuiltinOptions(object):
BucketizeOptions = 115
GeluOptions = 116
DynamicUpdateSliceOptions = 117
UnsortedSegmentProdOptions = 118
UnsortedSegmentMaxOptions = 119
UnsortedSegmentMinOptions = 120
UnsortedSegmentSumOptions = 121
ATan2Options = 122
SignOptions = 123

40 changes: 40 additions & 0 deletions tf2onnx/tflite/SignOptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# SPDX-License-Identifier: Apache-2.0

# automatically generated by the FlatBuffers compiler, do not modify

# namespace: tflite

import flatbuffers
from flatbuffers.compat import import_numpy
np = import_numpy()

class SignOptions(object):
__slots__ = ['_tab']

@classmethod
def GetRootAs(cls, buf, offset=0):
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
x = SignOptions()
x.Init(buf, n + offset)
return x

@classmethod
def GetRootAsSignOptions(cls, buf, offset=0):
"""This method is deprecated. Please switch to GetRootAs."""
return cls.GetRootAs(buf, offset)
@classmethod
def SignOptionsBufferHasIdentifier(cls, buf, offset, size_prefixed=False):
return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x54\x46\x4C\x33", size_prefixed=size_prefixed)

# SignOptions
def Init(self, buf, pos):
self._tab = flatbuffers.table.Table(buf, pos)

def Start(builder): builder.StartObject(0)
def SignOptionsStart(builder):
"""This method is deprecated. Please switch to Start."""
return Start(builder)
def End(builder): return builder.EndObject()
def SignOptionsEnd(builder):
"""This method is deprecated. Please switch to End."""
return End(builder)
46 changes: 45 additions & 1 deletion tf2onnx/tflite/Tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,39 @@ def ShapeSignatureIsNone(self):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18))
return o == 0

def Start(builder): builder.StartObject(8)
# Tensor
def HasRank(self):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(20))
if o != 0:
return bool(self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos))
return False

# Tensor
def VariantTensors(self, j):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(22))
if o != 0:
x = self._tab.Vector(o)
x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4
x = self._tab.Indirect(x)
from tf2onnx.tflite.VariantSubType import VariantSubType
obj = VariantSubType()
obj.Init(self._tab.Bytes, x)
return obj
return None

# Tensor
def VariantTensorsLength(self):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(22))
if o != 0:
return self._tab.VectorLen(o)
return 0

# Tensor
def VariantTensorsIsNone(self):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(22))
return o == 0

def Start(builder): builder.StartObject(10)
def TensorStart(builder):
"""This method is deprecated. Please switch to Start."""
return Start(builder)
Expand Down Expand Up @@ -178,6 +210,18 @@ def StartShapeSignatureVector(builder, numElems): return builder.StartVector(4,
def TensorStartShapeSignatureVector(builder, numElems):
"""This method is deprecated. Please switch to Start."""
return StartShapeSignatureVector(builder, numElems)
def AddHasRank(builder, hasRank): builder.PrependBoolSlot(8, hasRank, 0)
def TensorAddHasRank(builder, hasRank):
"""This method is deprecated. Please switch to AddHasRank."""
return AddHasRank(builder, hasRank)
def AddVariantTensors(builder, variantTensors): builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(variantTensors), 0)
def TensorAddVariantTensors(builder, variantTensors):
"""This method is deprecated. Please switch to AddVariantTensors."""
return AddVariantTensors(builder, variantTensors)
def StartVariantTensorsVector(builder, numElems): return builder.StartVector(4, numElems, 4)
def TensorStartVariantTensorsVector(builder, numElems):
"""This method is deprecated. Please switch to Start."""
return StartVariantTensorsVector(builder, numElems)
def End(builder): return builder.EndObject()
def TensorEnd(builder):
"""This method is deprecated. Please switch to End."""
Expand Down
1 change: 1 addition & 0 deletions tf2onnx/tflite/TensorType.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ class TensorType(object):
VARIANT = 14
UINT32 = 15
UINT16 = 16
INT4 = 17

13 changes: 12 additions & 1 deletion tf2onnx/tflite/TransposeConvOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ def StrideH(self):
return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos)
return 0

def Start(builder): builder.StartObject(3)
# TransposeConvOptions
def FusedActivationFunction(self):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
if o != 0:
return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos)
return 0

def Start(builder): builder.StartObject(4)
def TransposeConvOptionsStart(builder):
"""This method is deprecated. Please switch to Start."""
return Start(builder)
Expand All @@ -67,6 +74,10 @@ def AddStrideH(builder, strideH): builder.PrependInt32Slot(2, strideH, 0)
def TransposeConvOptionsAddStrideH(builder, strideH):
"""This method is deprecated. Please switch to AddStrideH."""
return AddStrideH(builder, strideH)
def AddFusedActivationFunction(builder, fusedActivationFunction): builder.PrependInt8Slot(3, fusedActivationFunction, 0)
def TransposeConvOptionsAddFusedActivationFunction(builder, fusedActivationFunction):
"""This method is deprecated. Please switch to AddFusedActivationFunction."""
return AddFusedActivationFunction(builder, fusedActivationFunction)
def End(builder): return builder.EndObject()
def TransposeConvOptionsEnd(builder):
"""This method is deprecated. Please switch to End."""
Expand Down
Loading