From bee7e96ffb22bd0f3611757846347ab8e651f8e6 Mon Sep 17 00:00:00 2001 From: fiercex Date: Thu, 11 Apr 2019 15:04:52 +0800 Subject: [PATCH 1/6] fix ELU --- python/mxnet/gluon/nn/activations.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/mxnet/gluon/nn/activations.py b/python/mxnet/gluon/nn/activations.py index c7dc83176e1..fc4507867c1 100644 --- a/python/mxnet/gluon/nn/activations.py +++ b/python/mxnet/gluon/nn/activations.py @@ -158,7 +158,8 @@ def __init__(self, alpha=1.0, **kwargs): self._alpha = alpha def hybrid_forward(self, F, x): - return F.where(x > 0, x, self._alpha * (F.exp(x) - 1.0)) + _x = F.where(x < 0, x, F.zeros_like(x)) + return F.where(x > 0, x, self._alpha * (F.exp(_x) - 1.0)) class SELU(HybridBlock): From 5f3dd279a39434cc96bf849ff002492908a09a18 Mon Sep 17 00:00:00 2001 From: fiercex Date: Wed, 17 Apr 2019 14:23:25 +0800 Subject: [PATCH 2/6] fix --- python/mxnet/gluon/nn/activations.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/mxnet/gluon/nn/activations.py b/python/mxnet/gluon/nn/activations.py index fc4507867c1..7f26922ef01 100644 --- a/python/mxnet/gluon/nn/activations.py +++ b/python/mxnet/gluon/nn/activations.py @@ -158,8 +158,7 @@ def __init__(self, alpha=1.0, **kwargs): self._alpha = alpha def hybrid_forward(self, F, x): - _x = F.where(x < 0, x, F.zeros_like(x)) - return F.where(x > 0, x, self._alpha * (F.exp(_x) - 1.0)) + F.LeakyReLU(x, act_type='elu', slope=self._alpha) class SELU(HybridBlock): From dd523096e538fc61dd06fe1b506a77ce3f62ace2 Mon Sep 17 00:00:00 2001 From: fiercex Date: Thu, 18 Apr 2019 15:37:13 +0800 Subject: [PATCH 3/6] fix --- tests/python/unittest/test_gluon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python/unittest/test_gluon.py b/tests/python/unittest/test_gluon.py index 8c60ef6745f..efa04f4fa47 100644 --- a/tests/python/unittest/test_gluon.py +++ b/tests/python/unittest/test_gluon.py @@ -1180,7 +1180,7 @@ def swish_test(x): elu = mx.gluon.nn.ELU() def elu_test(x): def elu(x): - return 1.0 * (mx.nd.exp(x) - 1) if x < 0 else x + return mx.nd.expm1(x) if x <= 0.0 else x return [elu(x_i) for x_i in x] for test_point, ref_point in zip(elu_test(point_to_validate), elu(point_to_validate)): From fcc7cafe8586489729c248ac324d49146c1db99e Mon Sep 17 00:00:00 2001 From: fiercex Date: Thu, 18 Apr 2019 15:42:09 +0800 Subject: [PATCH 4/6] fix --- python/mxnet/gluon/nn/activations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/mxnet/gluon/nn/activations.py b/python/mxnet/gluon/nn/activations.py index 7f26922ef01..9efb2b4ca81 100644 --- a/python/mxnet/gluon/nn/activations.py +++ b/python/mxnet/gluon/nn/activations.py @@ -158,7 +158,7 @@ def __init__(self, alpha=1.0, **kwargs): self._alpha = alpha def hybrid_forward(self, F, x): - F.LeakyReLU(x, act_type='elu', slope=self._alpha) + return F.LeakyReLU(x, act_type='elu', slope=self._alpha) class SELU(HybridBlock): From fd21ad09622f5f68e0c19eb39ee89d7f875da6d1 Mon Sep 17 00:00:00 2001 From: fiercex Date: Thu, 18 Apr 2019 15:45:49 +0800 Subject: [PATCH 5/6] fix --- python/mxnet/gluon/nn/activations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/mxnet/gluon/nn/activations.py b/python/mxnet/gluon/nn/activations.py index 9efb2b4ca81..15dae627258 100644 --- a/python/mxnet/gluon/nn/activations.py +++ b/python/mxnet/gluon/nn/activations.py @@ -158,7 +158,7 @@ def __init__(self, alpha=1.0, **kwargs): self._alpha = alpha def hybrid_forward(self, F, x): - return F.LeakyReLU(x, act_type='elu', slope=self._alpha) + return F.LeakyReLU(x, act_type='elu', slope=self._alpha) class SELU(HybridBlock): From faa8a3fc4eb8633352951ba8ffe8a98f987c488e Mon Sep 17 00:00:00 2001 From: fiercex Date: Tue, 23 Apr 2019 10:36:58 +0800 Subject: [PATCH 6/6] fix --- python/mxnet/gluon/nn/activations.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/mxnet/gluon/nn/activations.py b/python/mxnet/gluon/nn/activations.py index 15dae627258..8c51b0a5259 100644 --- a/python/mxnet/gluon/nn/activations.py +++ b/python/mxnet/gluon/nn/activations.py @@ -153,6 +153,7 @@ class ELU(HybridBlock): Outputs: - **out**: output tensor with the same shape as `data`. """ + def __init__(self, alpha=1.0, **kwargs): super(ELU, self).__init__(**kwargs) self._alpha = alpha