Skip to content
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
13 changes: 10 additions & 3 deletions tests/backend_test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
from tf2onnx.graph import ExternalTensorStorage


if is_tf2():
tf_set_random_seed = tf.compat.v1.set_random_seed
tf_tables_initializer = tf.compat.v1.tables_initializer
else:
tf_set_random_seed = tf.set_random_seed
tf_tables_initializer = tf.tables_initializer


class Tf2OnnxBackendTestBase(unittest.TestCase):
def setUp(self):
self.config = get_test_config()
Expand Down Expand Up @@ -133,14 +141,13 @@ def run_test_case(self, func, feed_dict, input_names_with_port, output_names_wit
# use graph to execute the tensorflow func
#
with tf_session() as sess:
tf.set_random_seed(1)
tf_set_random_seed(1)
input_list = []
for k, v in clean_feed_dict.items():
input_list.append(tf_placeholder(name=k, shape=v.shape, dtype=tf.as_dtype(v.dtype)))
func(*input_list)
variables_lib.global_variables_initializer().run()
if not is_tf2():
tf.tables_initializer().run()
tf_tables_initializer().run()
output_dict = []
for out_name in output_names_with_port:
output_dict.append(sess.graph.get_tensor_by_name(out_name))
Expand Down
3 changes: 1 addition & 2 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3391,7 +3391,6 @@ def func(value, filters, output_shape):
rtol=1e-6)

@check_opset_min_version(8, "CategoryMapper")
@skip_tf2()
def test_hashtable_lookup(self):
filnm = "vocab.tmp"
words = ["apple", "pear", "banana", "cherry", "grape"]
Expand All @@ -3404,7 +3403,7 @@ def func(query_holder):
lookup_results = hash_table.lookup(query_holder)
ret = tf.add(lookup_results, 0, name=_TFOUTPUT)
return ret
self._run_test_case(func, [_OUTPUT], {_INPUT: query}, constant_fold=False)
self._run_test_case(func, [_OUTPUT], {_INPUT: query}, constant_fold=False, as_session=True)
os.remove(filnm)

@check_opset_min_version(11)
Expand Down