diff --git a/python/tvm/relay/frontend/tensorflow.py b/python/tvm/relay/frontend/tensorflow.py index 1f5786f911cb..6a23c8da9739 100644 --- a/python/tvm/relay/frontend/tensorflow.py +++ b/python/tvm/relay/frontend/tensorflow.py @@ -1923,6 +1923,16 @@ def _impl(inputs, attr, params, mod): return _impl +def _softsign(): + # op description: https://www.tensorflow.org/api_docs/python/tf/math/softsign + def _impl(inputs, attr, params, mod): + abs_out = get_relay_op("abs")(inputs[0]) + add_out = abs_out + tvm.relay.const(1, attr["T"].name) + return inputs[0] / add_out + + return _impl + + def _softplus(): # op description: https://www.tensorflow.org/api_docs/python/tf/math/softplus def _impl(inputs, attr, params, mod): @@ -2381,6 +2391,7 @@ def _impl(inputs, attr, params, mod): "Slice": _slice(), "Softmax": _softmax(), "Softplus": _softplus(), + "Softsign": _softsign(), "SpaceToBatchND": _space_to_batch_nd(), "SpaceToDepth": _space_to_depth(), "Split": _split(False), diff --git a/tests/python/frontend/tensorflow/test_forward.py b/tests/python/frontend/tensorflow/test_forward.py index 713993ea40a4..df6682e28a9d 100644 --- a/tests/python/frontend/tensorflow/test_forward.py +++ b/tests/python/frontend/tensorflow/test_forward.py @@ -3504,6 +3504,22 @@ def _test_forward_expm1(shape): _test_forward_expm1([2, 5, 2, 5]) +def test_forward_softsign(): + """test operator softsign """ + + def _test_forward_softsign(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.nn.softsign(in_data, name="softsign") + compare_tf_with_tvm([np_data], ["in_data:0"], "softsign:0") + + _test_forward_softsign([1, 100]) + _test_forward_softsign([1, 10, 10]) + _test_forward_softsign([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)