diff --git a/python/tvm/relay/frontend/keras.py b/python/tvm/relay/frontend/keras.py index 16764cd58110..205b2be490a0 100644 --- a/python/tvm/relay/frontend/keras.py +++ b/python/tvm/relay/frontend/keras.py @@ -120,6 +120,8 @@ def _convert_activation( if act_type == "hard_sigmoid": x = (_expr.const(0.2, dtype="float32") * inexpr) + _expr.const(0.5, dtype="float32") return _op.clip(x, a_min=0.0, a_max=1.0) + if act_type == "swish": + return inexpr * _op.sigmoid(inexpr) raise tvm.error.OpNotImplemented(f"Operator {act_type} is not supported in frontend Keras.") diff --git a/tests/python/frontend/keras/test_forward.py b/tests/python/frontend/keras/test_forward.py index cdc253bc5d04..80460f6063d7 100644 --- a/tests/python/frontend/keras/test_forward.py +++ b/tests/python/frontend/keras/test_forward.py @@ -66,7 +66,7 @@ def pytest_generate_tests(metafunc): # Scenarios: # - classic keras, using keras from "import keras" # - tensorflow keras, using keras from "from tensorflow import keras as tf_keras" -USING_CALSSIC_KERAS = ("keras", {"keras_mod": keras}) +USING_CLASSIC_KERAS = ("keras", {"keras_mod": keras}) USING_TENSORFLOW_KERAS = ("tf_keras", {"keras_mod": tf_keras}) @@ -134,7 +134,7 @@ def get_mobilenet(keras_mod): class TestKeras: """Keras test""" - scenarios = [USING_CALSSIC_KERAS, USING_TENSORFLOW_KERAS] + scenarios = [USING_CLASSIC_KERAS, USING_TENSORFLOW_KERAS] def test_forward_merge(self, keras_mod): """test_forward_merge""" @@ -213,6 +213,7 @@ def test_forward_activations(self, keras_mod): keras_mod.layers.Activation("tanh"), keras_mod.layers.Activation("linear"), keras_mod.layers.Activation("selu"), + keras_mod.layers.Activation("swish"), keras_mod.layers.ReLU(), keras_mod.layers.ReLU(max_value=6.0), keras_mod.layers.ReLU(max_value=6.0, threshold=0.0),