|
|
|
@ -5,12 +5,13 @@ from gradient_checker import GradientChecker
|
|
|
|
|
from op_test_util import OpTestMeta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestClipOp(unittest.TestCase):
|
|
|
|
|
class ClipOp(unittest.TestCase):
|
|
|
|
|
__metaclass__ = OpTestMeta
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
input = np.random.random((16, 16)).astype("float32")
|
|
|
|
|
print "input: %s" % input
|
|
|
|
|
input[np.abs(input - 0.1) < 0.05] = 0.5
|
|
|
|
|
input[np.abs(input - 0.9) < 0.05] = 0.5
|
|
|
|
|
self.type = "clip"
|
|
|
|
|
self.inputs = {'X': input, }
|
|
|
|
|
self.attrs = {}
|
|
|
|
@ -24,14 +25,16 @@ class TestClipOp(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
class TestClipGradOp(GradientChecker):
|
|
|
|
|
def setUp(self):
|
|
|
|
|
input = np.random.random((8, 8)).astype("float32")
|
|
|
|
|
print "input: %s" % input
|
|
|
|
|
self.op = Operator(type="clip", X="X", Out="Out", min=0.1, max=0.9)
|
|
|
|
|
self.inputs = {'X': np.random.random((16, 16)).astype("float32"), }
|
|
|
|
|
self.inputs = {'X': input, }
|
|
|
|
|
|
|
|
|
|
def test_normal(self):
|
|
|
|
|
self.check_grad(
|
|
|
|
|
self.op, self.inputs, set(["X"]), "Out", max_relative_error=0.5)
|
|
|
|
|
|
|
|
|
|
def test_cpu_gpu_compare(self):
|
|
|
|
|
def t_cpu_gpu_compare(self):
|
|
|
|
|
self.compare_grad(self.op, self.inputs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|