test_sigmoid_op.py 848 字节
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 17 18 19
class TestSigmoidGradOp(GradientChecker):
    def test_compare_grad(self):
        op = create_op("sigmoid")
        inputs = {"X": np.random.random((11, 17)).astype("float32")}
D
dangqingqing 已提交
20 21
        # compare gpu and cpu results for backward op.
        # skip this test if only compiling CPU version.
22
        self.compare_grad(op, inputs)
D
dangqingqing 已提交
23
        # check gradients 
24 25
        self.check_grad(op, inputs, set("X"), "Y")

26

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