test_sigmoid_op.py 885 字节
Newer Older
Q
qijun 已提交
1 2
import unittest
import numpy as np
3 4
from op_test_util import OpTestMeta
from gradient_checker import GradientChecker, create_op
Q
qijun 已提交
5 6 7 8 9 10 11


class TestSigmoidOp(unittest.TestCase):
    __metaclass__ = OpTestMeta

    def setUp(self):
        self.type = "sigmoid"
12
        self.inputs = {'X': np.random.random((15, 31)).astype("float32")}
D
dangqingqing 已提交
13
        self.outputs = {'Y': 1 / (1 + np.exp(-self.inputs['X']))}
Q
qijun 已提交
14 15


16
class TestSigmoidGradOp(GradientChecker):
17
    def test_grad(self):
18
        op = create_op("sigmoid")
19
        inputs = {"X": np.random.uniform(0.1, 1, [11, 17]).astype("float32")}
D
dangqingqing 已提交
20
        # compare gpu and cpu results for backward op.
21
        # this test will be skiped if only compiling CPU version.
22
        self.compare_grad(op, inputs)
D
dangqingqing 已提交
23
        # check gradients 
24
        self.check_grad(op, inputs, set("X"), "Y", max_relative_error=0.007)
25

26

Q
qijun 已提交
27 28
if __name__ == '__main__':
    unittest.main()