test_sigmoid_op.py 620 字节
Newer Older
Q
qijun 已提交
1 2
import unittest
import numpy as np
3 4
from op_test import OpTest
import paddle.v2.framework.core as core
Q
qijun 已提交
5 6


7
class TestSigmoid(OpTest):
Q
qijun 已提交
8
    def setUp(self):
9 10 11 12
        self.op_type = "sigmoid"
        self.inputs = {
            'X': np.random.uniform(0.1, 1, [11, 17]).astype("float32")
        }
D
dangqingqing 已提交
13
        self.outputs = {'Y': 1 / (1 + np.exp(-self.inputs['X']))}
Q
qijun 已提交
14

15 16 17
    def test_check_output(self):
        self.check_output(core.CPUPlace())
        self.check_output(core.GPUPlace(0))
Q
qijun 已提交
18

19 20
    def test_check_grad(self):
        self.check_grad(["X"], "Y", max_relative_error=0.007)
21

22

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