You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/09/14 21:59:51 UTC

[GitHub] [incubator-mxnet] stu1130 commented on a change in pull request #14582: Fix randomized relu

stu1130 commented on a change in pull request #14582: Fix randomized relu
URL: https://github.com/apache/incubator-mxnet/pull/14582#discussion_r324439400
 
 

 ##########
 File path: tests/python/unittest/test_operator.py
 ##########
 @@ -862,6 +863,35 @@ def fselu_grad(grad, x, y):
         check_symbolic_backward(y, [xa], [np.ones(shape)], [ga], rtol=rtol, atol=atol, dtype=dtype)
 
 
+@with_seed()
+def test_rrelu():
+    def rrelu(x, lower_bound):
+        neg_indices = x < 0
+        out = x.copy()
+        out[neg_indices] = lower_bound * out[neg_indices]
+        return out
+    def rrelu_grad(grad, x, lower_bound):
+        neg_indices = x < 0
+        out = np.ones(x.shape)
+        out[neg_indices] = lower_bound
+        return out * grad
+    for ndim in range(1, 4):
+        shape = rand_shape_nd(ndim)
+        x = mx.symbol.Variable("x")
+        eps = 1e-4
+        lower_bound = 1
+        upper_bound = 2
+        for dtype in [np.float16, np.float32, np.float64]:
+            xa = np.random.uniform(low=-1.0,high=1.0,size=shape).astype(dtype)
+            xa[abs(xa) < eps] = 1.0
+            y = mx.symbol.LeakyReLU(data=x, act_type="rrelu",
+                lower_bound=lower_bound, upper_bound=upper_bound)
+            ya = rrelu(xa, lower_bound=lower_bound)
+            ga = rrelu_grad(np.ones(shape), xa, lower_bound=lower_bound)
+            check_symbolic_forward(y, [xa], [ya], rtol=0, atol=1, dtype=dtype)
 
 Review comment:
   the slope was picked randomly, check_numberic_gradient might not be able to apply here

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services