From 59d440a82705c625ed7043a3cf972c0d797741e1 Mon Sep 17 00:00:00 2001 From: alter-xp Date: Fri, 23 Oct 2020 20:02:23 +0800 Subject: [PATCH 1/2] TF frontend: add rint op --- python/tvm/relay/frontend/tensorflow.py | 1 + .../python/frontend/tensorflow/test_forward.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/python/tvm/relay/frontend/tensorflow.py b/python/tvm/relay/frontend/tensorflow.py index 2c7adf03bad8..a38892befa1d 100644 --- a/python/tvm/relay/frontend/tensorflow.py +++ b/python/tvm/relay/frontend/tensorflow.py @@ -2391,6 +2391,7 @@ def _impl(inputs, attr, params, mod): "ReverseV2": _reverse_v2(), "RightShift": AttrCvt("right_shift"), "Round": AttrCvt("round"), + "Rint": AttrCvt("round"), "Rsqrt": _rsqrt(), "Select": _where(), "Selu": _selu(), diff --git a/tests/python/frontend/tensorflow/test_forward.py b/tests/python/frontend/tensorflow/test_forward.py index 5ec4562543c2..f0349daf1639 100644 --- a/tests/python/frontend/tensorflow/test_forward.py +++ b/tests/python/frontend/tensorflow/test_forward.py @@ -3520,6 +3520,23 @@ def _test_forward_softsign(shape): _test_forward_softsign([2, 5, 2, 5]) +def test_forward_rint(): + """test operator rint """ + + def _test_forward_rint(shape): + tf.disable_eager_execution() + np_data = np.random.uniform(1, 100, size=shape).astype(np.float32) + tf.reset_default_graph() + in_data = tf.placeholder(tf.float32, shape, name="in_data") + tf.math.rint(in_data, name="rint") + compare_tf_with_tvm([np_data], ["in_data:0"], "rint:0") + + _test_forward_rint([100]) + _test_forward_rint([1, 100]) + _test_forward_rint([1, 10, 10]) + _test_forward_rint([2, 5, 2, 5]) + + def test_forward_negative(): """test tf operator Neg """ np_data = np.random.uniform(-100, 255, size=(224, 224, 3)).astype(np.float32) From 83939c1f3b373adfbe4fe1e3addd15101be2a684 Mon Sep 17 00:00:00 2001 From: xp56 Date: Thu, 5 Nov 2020 21:13:20 +0800 Subject: [PATCH 2/2] Added negative numbers to the test --- python/tvm/relay/frontend/tensorflow.py | 2 +- tests/python/frontend/tensorflow/test_forward.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/tvm/relay/frontend/tensorflow.py b/python/tvm/relay/frontend/tensorflow.py index a38892befa1d..d4bf56d7c894 100644 --- a/python/tvm/relay/frontend/tensorflow.py +++ b/python/tvm/relay/frontend/tensorflow.py @@ -2390,8 +2390,8 @@ def _impl(inputs, attr, params, mod): "ResizeNearestNeighbor": _resize("nearest_neighbor"), "ReverseV2": _reverse_v2(), "RightShift": AttrCvt("right_shift"), - "Round": AttrCvt("round"), "Rint": AttrCvt("round"), + "Round": AttrCvt("round"), "Rsqrt": _rsqrt(), "Select": _where(), "Selu": _selu(), diff --git a/tests/python/frontend/tensorflow/test_forward.py b/tests/python/frontend/tensorflow/test_forward.py index f0349daf1639..5d2f2e6939af 100644 --- a/tests/python/frontend/tensorflow/test_forward.py +++ b/tests/python/frontend/tensorflow/test_forward.py @@ -3525,7 +3525,7 @@ def test_forward_rint(): def _test_forward_rint(shape): tf.disable_eager_execution() - np_data = np.random.uniform(1, 100, size=shape).astype(np.float32) + np_data = np.random.uniform(-100, 100, size=shape).astype(np.float32) tf.reset_default_graph() in_data = tf.placeholder(tf.float32, shape, name="in_data") tf.math.rint(in_data, name="rint")