Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ steps:
pip install $(ONNX_PATH)
pip uninstall -y protobuf
pip install "protobuf<4.21.0"
pip install h5py==2.9.0
pip install h5py==3.7.0
pip install parameterized
pip install coloredlogs flatbuffers
$(INSTALL_TENSORFLOW)
Expand Down Expand Up @@ -85,7 +85,7 @@ steps:
pip install %ONNX_PATH%
pip uninstall -y protobuf
pip install "protobuf<4.21.0"
pip install h5py==2.9.0
pip install h5py==3.7.0
pip install parameterized
pip install coloredlogs flatbuffers
%INSTALL_TENSORFLOW%
Expand Down
4 changes: 2 additions & 2 deletions ci_build/azure_pipelines/templates/keras2onnx_unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ steps:
pip install $(ONNX_PATH)
pip uninstall -y protobuf
pip install "protobuf<4.21.0"
pip install h5py==2.9.0
pip install h5py==3.7.0
pip install parameterized
pip install coloredlogs flatbuffers
pip install $(TENSORFLOW_PATH)
Expand Down Expand Up @@ -75,7 +75,7 @@ steps:
pip install %ONNX_PATH%
pip uninstall -y protobuf
pip install "protobuf<4.21.0"
pip install h5py==2.9.0
pip install h5py==3.7.0
pip install parameterized
pip install coloredlogs flatbuffers
pip install %TENSORFLOW_PATH%
Expand Down
19 changes: 12 additions & 7 deletions ci_build/azure_pipelines/templates/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@ steps:
pip install pytest pytest-cov pytest-runner coverage graphviz requests pyyaml pillow pandas parameterized sympy coloredlogs flatbuffers
pip install $(CI_PIP_TF_NAME) $(CI_PIP_ONNX_NAME)

# Protobuf 3.20 results in linker errors on Windows in TF.
# Protobuf 4.0 is binary incompatible with what C++ TF uses.
# https://github.com/tensorflow/tensorflow/blob/c3337c73306b2b859d82fe130912f18e6a1c5c23/tensorflow/tools/pip_package/setup.py#L88
pip uninstall -y protobuf
pip install "protobuf<3.20.0"

# 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)
pip install $(CI_PIP_ONNX_BACKEND_NAME) numpy==1.23.4
fi
# TF 1.10 requires numpy <=1.14.5 and >=1.13.3, but onnxruntime 0.2.1 does not work with numpy <= 1.14.5
# Upgrade numpy only within constraints from other packages if any.
Expand All @@ -34,6 +28,11 @@ steps:
pip install -i https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ ort-nightly
fi

if [[ $CI_TF_VERSION < 2.0 ]] ;
then
pip install h5py==2.9.0
fi

if [[ $CI_SKIP_TFJS_TESTS == "False" ]] ;
then
pip install tensorflowjs==3.18.0
Expand Down Expand Up @@ -80,6 +79,12 @@ steps:
fi
fi

# Protobuf 3.20 results in linker errors on Windows in TF.
# Protobuf 4.0 is binary incompatible with what C++ TF uses.
# https://github.com/tensorflow/tensorflow/blob/c3337c73306b2b859d82fe130912f18e6a1c5c23/tensorflow/tools/pip_package/setup.py#L88
pip uninstall -y protobuf
pip install "protobuf==3.20.3"

python setup.py install

if [[ $ONNX_TEST == "true" ]] ;
Expand Down
69 changes: 36 additions & 33 deletions ci_build/azure_pipelines/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
stages:
- stage:
jobs:
- template: 'templates/job_generator.yml'
parameters:
python_versions: ['3.9']
tf_versions: ['2.8.0']
onnx_opsets: ['']
skip_tfjs_tests: 'False'
skip_tf_tests: 'True'
job:
steps:
- template: 'unit_test.yml'
report_coverage: 'True'
# TODO: Enable these tests once https://github.com/onnx/tensorflow-onnx/issues/2118 is fixed.
# - template: 'templates/job_generator.yml'
# parameters:
# python_versions: ['3.9']
# tf_versions: ['2.8.0']
# onnx_opsets: ['']
# skip_tfjs_tests: 'False'
# skip_tf_tests: 'True'
# job:
# steps:
# - template: 'unit_test.yml'
# report_coverage: 'True'

- template: 'templates/job_generator.yml'
parameters:
Expand All @@ -37,17 +38,18 @@ stages:
- template: 'unit_test.yml'
report_coverage: 'True'

- template: 'templates/job_generator.yml'
parameters:
python_versions: ['3.9']
tf_versions: ['2.7.4']
onnx_opsets: ['']
skip_tfjs_tests: 'False'
skip_tf_tests: 'True'
job:
steps:
- template: 'unit_test.yml'
report_coverage: 'True'
# TODO: Enable these tests once https://github.com/onnx/tensorflow-onnx/issues/2118 is fixed.
# - template: 'templates/job_generator.yml'
# parameters:
# python_versions: ['3.9']
# tf_versions: ['2.7.4']
# onnx_opsets: ['']
# skip_tfjs_tests: 'False'
# skip_tf_tests: 'True'
# job:
# steps:
# - template: 'unit_test.yml'
# report_coverage: 'True'

- template: 'templates/job_generator.yml'
parameters:
Expand All @@ -61,17 +63,18 @@ stages:
- template: 'unit_test.yml'
report_coverage: 'True'

- template: 'templates/job_generator.yml'
parameters:
python_versions: ['3.10']
tf_versions: ['2.9.1']
onnx_opsets: ['']
skip_tfjs_tests: 'False'
skip_tf_tests: 'True'
job:
steps:
- template: 'unit_test.yml'
report_coverage: 'True'
# TODO: Enable these tests once https://github.com/onnx/tensorflow-onnx/issues/2118 is fixed.
# - template: 'templates/job_generator.yml'
# parameters:
# python_versions: ['3.10']
# tf_versions: ['2.9.1']
# onnx_opsets: ['']
# skip_tfjs_tests: 'False'
# skip_tf_tests: 'True'
# job:
# steps:
# - template: 'unit_test.yml'
# report_coverage: 'True'

- template: 'templates/job_generator.yml'
parameters:
Expand Down
2 changes: 1 addition & 1 deletion tests/run_pretrained_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def run_tflite():
inputs[k] = np_value.astype(expected_dtype)
else:
if expected_dtype == "string":
inputs[k] = self.make_input(v).astype(np.str).astype(object)
inputs[k] = self.make_input(v).astype(str).astype(object)
else:
inputs[k] = self.make_input(v).astype(expected_dtype)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_keras_hashtable(self):
model.compile(optimizer='adam', loss=tf.keras.losses.mean_squared_error)

inp1 = np.array([[2.], [3.]], dtype=np.float32)
inp2 = np.array([["a"], ["b"]], dtype=np.str)
inp2 = np.array([["a"], ["b"]], dtype=str)
if not is_tf2():
tf.keras.backend.get_session().run(tf.tables_initializer(name='init_all_tables'))
k_res = model.predict([inp1, inp2])
Expand Down
22 changes: 11 additions & 11 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,8 +1648,8 @@ def func(x1, x2, x3):
self._run_test_case(func, [_OUTPUT], {_INPUT: x_val1, _INPUT1: x_val2, "input3:0": x_val3})

def test_concat_const_string(self):
x_val1 = np.array([["Hello world", "abc"], ["def", "♦♥♠♣"]], dtype=np.str)
const_val = np.array([["Hello there", "wxyz"], ["", "π"]], dtype=np.str)
x_val1 = np.array([["Hello world", "abc"], ["def", "♦♥♠♣"]], dtype=str)
const_val = np.array([["Hello there", "wxyz"], ["", "π"]], dtype=str)
def func(x1):
x_ = tf.concat([x1, const_val], 0)
return tf.identity(x_, name=_TFOUTPUT)
Expand Down Expand Up @@ -3513,9 +3513,9 @@ def func(x1, x2):
def test_where_string(self):
x_val = np.array([1, 2, -3, 4, -5, -6, -7, 8, 9, 0], dtype=np.float32)
true_result = np.array([111, 222, 333, 444, 555, 666, 777, 888, 999, 1000],
dtype=np.str)
dtype=str)
false_result = np.array([-111, -222, -333, -444, -555, -666, -777, -888, -999, -1000],
dtype=np.str)
dtype=str)
def func(x):
picks = tf.where(x > -1, true_result, false_result)
return tf.identity(picks, name=_TFOUTPUT)
Expand Down Expand Up @@ -3613,7 +3613,7 @@ def func(x):
@check_tf_min_version("1.14", "tf.strings.lower")
@check_opset_min_version(10, "StringNormalizer")
def test_string_lower(self):
text_val1 = np.array([["a", "Test 1 2 3", "♠♣"], ["Hi there", "test test", "♥♦"]], dtype=np.str)
text_val1 = np.array([["a", "Test 1 2 3", "♠♣"], ["Hi there", "test test", "♥♦"]], dtype=str)
def func(text1):
x = tf.strings.lower(text1)
x_ = tf.identity(x, name=_TFOUTPUT)
Expand All @@ -3623,7 +3623,7 @@ def func(text1):
@check_tf_min_version("1.14", "tf.strings.lower")
@check_opset_min_version(10, "StringNormalizer")
def test_string_lower_flat(self):
text_val1 = np.array(["a", "Test 1 2 3", "♠♣", "Hi there", "test test", "♥♦"], dtype=np.str)
text_val1 = np.array(["a", "Test 1 2 3", "♠♣", "Hi there", "test test", "♥♦"], dtype=str)
def func(text1):
x = tf.strings.lower(text1)
x_ = tf.identity(x, name=_TFOUTPUT)
Expand All @@ -3633,7 +3633,7 @@ def func(text1):
@check_tf_min_version("1.14", "tf.strings.lower")
@check_opset_min_version(10, "StringNormalizer")
def test_string_upper(self):
text_val1 = np.array([["a", "Test 1 2 3", "♠♣"], ["Hi there", "test test", "♥♦"]], dtype=np.str)
text_val1 = np.array([["a", "Test 1 2 3", "♠♣"], ["Hi there", "test test", "♥♦"]], dtype=str)
def func(text1):
x = tf.strings.upper(text1)
x_ = tf.identity(x, name=_TFOUTPUT)
Expand Down Expand Up @@ -4709,9 +4709,9 @@ def func(x, y, z):
@check_opset_min_version(11, "ScatterND")
@skip_tflite("Conversion crashes")
def test_tensor_scatter_update_str(self):
x_val = np.array(['A', '♠♣♥♦', 'B', 'C'], dtype=np.str).reshape((4))
x_val = np.array(['A', '♠♣♥♦', 'B', 'C'], dtype=str).reshape((4))
y_val = np.array([0, 2], dtype=np.int64).reshape((2, 1))
z_val = np.array(['☺', '11'], dtype=np.str).reshape((2))
z_val = np.array(['☺', '11'], dtype=str).reshape((2))

def func(x, y, z):
x_ = tf.tensor_scatter_nd_update(x, y, z)
Expand All @@ -4722,9 +4722,9 @@ def func(x, y, z):
@check_opset_min_version(11, "ScatterND")
@skip_tflite("Conversion crashes")
def test_tensor_scatter_update_str_const(self):
x_val = np.array(['A', '♠♣♥♦', 'B', 'C'], dtype=np.str).reshape((4))
x_val = np.array(['A', '♠♣♥♦', 'B', 'C'], dtype=str).reshape((4))
y_val = np.array([0, 2], dtype=np.int64).reshape((2, 1))
z_val = np.array(['☺', '11'], dtype=np.str).reshape((2))
z_val = np.array(['☺', '11'], dtype=str).reshape((2))

def func(x, y):
z = tf.constant(z_val)
Expand Down
24 changes: 12 additions & 12 deletions tests/test_string_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class StringOpsTests(Tf2OnnxBackendTestBase):

@requires_custom_ops("StringRegexReplace")
def test_static_regex_replace(self):
text_val = np.array([["Hello world!", "Test 1 2 3"], ["Hi there", "test test"]], dtype=np.str)
text_val = np.array([["Hello world!", "Test 1 2 3"], ["Hi there", "test test"]], dtype=str)
def func(text):
x_ = tf.strings.regex_replace(text, " ", "_", replace_global=True)
return tf.identity(x_, name=_TFOUTPUT)
Expand All @@ -44,9 +44,9 @@ def func(text):
@requires_custom_ops("StringJoin")
@check_opset_min_version(8, "Expand")
def test_string_join(self):
text_val1 = np.array([["a", "Test 1 2 3"], ["Hi there", "test test"]], dtype=np.str)
text_val2 = np.array([["b", "Test 1 2 3"], ["Hi there", "suits ♠♣♥♦"]], dtype=np.str)
text_val3 = np.array("Some scalar text", dtype=np.str)
text_val1 = np.array([["a", "Test 1 2 3"], ["Hi there", "test test"]], dtype=str)
text_val2 = np.array([["b", "Test 1 2 3"], ["Hi there", "suits ♠♣♥♦"]], dtype=str)
text_val3 = np.array("Some scalar text", dtype=str)
def func(text1, text2, text3):
x_ = tf.strings.join([text1, text2, text3], separator="±")
return tf.identity(x_, name=_TFOUTPUT)
Expand All @@ -55,7 +55,7 @@ def func(text1, text2, text3):
@requires_custom_ops("StringSplit")
@check_tf_min_version("2.0", "result is sparse not ragged in tf1")
def test_string_split(self):
text_val = np.array([["a", "Test 1 2 3"], ["Hi there", "test test"]], dtype=np.str)
text_val = np.array([["a", "Test 1 2 3"], ["Hi there", "test test"]], dtype=str)
def func(text):
x = tf.strings.split(text, sep=' ').flat_values
x_ = tf.identity(x, name=_TFOUTPUT)
Expand All @@ -64,7 +64,7 @@ def func(text):

@requires_custom_ops("StringToHashBucketFast")
def test_string_to_hash_bucket_fast(self):
text_val = np.array([["a", "Test 1 2 3", "♠♣"], ["Hi there", "test test", "♥♦"]], dtype=np.str)
text_val = np.array([["a", "Test 1 2 3", "♠♣"], ["Hi there", "test test", "♥♦"]], dtype=str)
def func(text):
x = tf.strings.to_hash_bucket_fast(text, 20)
x_ = tf.identity(x, name=_TFOUTPUT)
Expand All @@ -73,8 +73,8 @@ def func(text):

@requires_custom_ops("StringEqual")
def test_string_equal(self):
text_val1 = np.array([["a", "Test 1 2 3", "♠♣"], ["Hi there", "test test", "♥♦"]], dtype=np.str)
text_val2 = np.array([["a", "Test 2 4 6", "♠♣"], ["Hello", "test test", "♥ ♦"]], dtype=np.str)
text_val1 = np.array([["a", "Test 1 2 3", "♠♣"], ["Hi there", "test test", "♥♦"]], dtype=str)
text_val2 = np.array([["a", "Test 2 4 6", "♠♣"], ["Hello", "test test", "♥ ♦"]], dtype=str)
def func(text1, text2):
x = tf.equal(text1, text2)
x_ = tf.identity(x, name=_TFOUTPUT)
Expand All @@ -83,8 +83,8 @@ def func(text1, text2):

@requires_custom_ops("StringNotEqual")
def test_string_not_equal(self):
text_val1 = np.array([["a", "Test 1 2 3", "♠♣"], ["Hi there", "test test", "♥♦"]], dtype=np.str)
text_val2 = np.array([["a", "Test 2 4 6", "♠♣"], ["Hello", "test test", "♥ ♦"]], dtype=np.str)
text_val1 = np.array([["a", "Test 1 2 3", "♠♣"], ["Hi there", "test test", "♥♦"]], dtype=str)
text_val2 = np.array([["a", "Test 2 4 6", "♠♣"], ["Hello", "test test", "♥ ♦"]], dtype=str)
def func(text1, text2):
x = tf.not_equal(text1, text2)
x_ = tf.identity(x, name=_TFOUTPUT)
Expand Down Expand Up @@ -116,7 +116,7 @@ def test_regex_split_with_offsets(self):
from tensorflow_text.python.ops.regex_split_ops import (
gen_regex_split_ops as lib_gen_regex_split_ops)
text_val = np.array(["a Test 1 2 3 ♠♣",
"Hi there test test ♥♦"], dtype=np.str)
"Hi there test test ♥♦"], dtype=str)
def func(text):
tokens, begin_offsets, end_offsets, row_splits = lib_gen_regex_split_ops.regex_split_with_offsets(
text, "(\\s)", "")
Expand Down Expand Up @@ -153,7 +153,7 @@ def _CreateTable(vocab, num_oov=1):
init, num_oov, lookup_key_dtype=tf.string)

vocab = _CreateTable(["great", "they", "the", "##'", "##re", "##est"])
text_val = np.array(["they're", "the", "greatest"], dtype=np.str)
text_val = np.array(["they're", "the", "greatest"], dtype=str)

def func(text):
inputs = ragged_tensor.convert_to_tensor_or_ragged_tensor(text)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tfjs_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_tfjs_runner(self):
float_array = np.array([[1.1, 2.2], [3.3, 4.4]], np.float32)
int_array = np.array([[1, 2], [3, 4]], np.int32)
bool_array = np.array([[True, False], [True, True]], bool)
string_array = np.array([['Hello world', ''], ['π', 'Tensor']], np.str)
string_array = np.array([['Hello world', ''], ['π', 'Tensor']], str)
complex_array = np.array([[1 + 0.1j, 2 + 0.2j], [3 + 0.3j, 4 + 0.4j]], np.complex64)

arrays = [float_array, int_array, bool_array, string_array, complex_array]
Expand Down
2 changes: 1 addition & 1 deletion tf2onnx/tf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def tf_to_onnx_tensor(tensor, name=""):
# in which each item is of str while the whole dtype is of object.
try:
# Faster but fails on Unicode
np_data = np_data.astype(np.str).astype(object)
np_data = np_data.astype(str).astype(object)
except UnicodeDecodeError:
decode = np.vectorize(lambda x: x.decode('UTF-8'))
np_data = decode(np_data).astype(object)
Expand Down