diff --git a/python/tvm/relay/frontend/tensorflow.py b/python/tvm/relay/frontend/tensorflow.py index 89b36256152e..32dd90c28bc2 100644 --- a/python/tvm/relay/frontend/tensorflow.py +++ b/python/tvm/relay/frontend/tensorflow.py @@ -788,6 +788,15 @@ def _impl(inputs, attr, params, mod): return _impl +def _expm1(): + # op description: https://www.tensorflow.org/api_docs/python/tf/math/expm1 + def _impl(inputs, attr, params, mod): + exp_out = get_relay_op("exp")(inputs[0]) + return exp_out - tvm.relay.const(1.0) + + return _impl + + def _resize(method): def _impl(inputs, attr, params, mod): if attr["_output_shapes"][0] is not None: @@ -2297,6 +2306,7 @@ def _impl(inputs, attr, params, mod): "EuclideanNorm": _euclidean_norm(), "Exp": AttrCvt("exp"), "ExpandDims": _expand_dims(), + "Expm1": _expm1(), "Fill": _fill(), "Floor": AttrCvt("floor"), "FloorDiv": _floordiv(), diff --git a/tests/python/frontend/tensorflow/test_forward.py b/tests/python/frontend/tensorflow/test_forward.py index 0bcac7fb1a21..7130d81488ed 100644 --- a/tests/python/frontend/tensorflow/test_forward.py +++ b/tests/python/frontend/tensorflow/test_forward.py @@ -3488,6 +3488,22 @@ def test_forward_atan2(): compare_tf_with_tvm([np_data_1, np_data_2], ["in_data_1:0", "in_data_2:0"], "atan2:0") +def test_forward_expm1(): + """test operator expm1 """ + + def _test_forward_expm1(shape): + tf.disable_eager_execution() + np_data = np.random.uniform(1, 10, size=shape).astype(np.float32) + tf.reset_default_graph() + in_data = tf.placeholder(tf.float32, shape, name="in_data") + tf.expm1(in_data, name="expm1") + compare_tf_with_tvm([np_data], ["in_data:0"], "expm1:0") + + _test_forward_expm1([1, 100]) + _test_forward_expm1([1, 10, 10]) + _test_forward_expm1([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)