test_fc_op.py 1.2 KB
Newer Older
1 2
import unittest
import numpy as np
L
Liu Yiqun 已提交
3
from op_test import OpTest
4 5


L
Liu Yiqun 已提交
6
class TestFCOp(OpTest):
7
    def setUp(self):
L
Liu Yiqun 已提交
8 9 10 11 12 13 14
        print "Run"
        self.op_type = "fc"
        x0 = np.random.random((32, 256)).astype("float32")
        x1 = np.random.random((32, 256)).astype("float32")
        w0 = np.random.random((256, 100)).astype("float32")
        w1 = np.random.random((256, 100)).astype("float32")
        b = np.random.random(100).astype("float32")
15
        self.inputs = {
L
Liu Yiqun 已提交
16 17 18 19 20 21 22 23 24
            "X": {
                "X0": x0,
                "X1": x1
            },
            "W": {
                "W0": w0,
                "W1": w1
            },
            "b": b
25
        }
L
Liu Yiqun 已提交
26 27 28 29 30
        #self.attrs = {"activation": "sigmoid"}
        mul_out = np.dot(x0, w0) + np.dot(x1, w1)
        add_out = np.add(mul_out, b)
        #sigmoid_out = 1 / (1 + np.exp(-add_out))
        sigmoid_out = add_out
31 32 33
        self.outputs = {
            "mul_out": mul_out,
            "add_out": add_out,
L
Liu Yiqun 已提交
34
            "Y": sigmoid_out
35
        }
36

L
Liu Yiqun 已提交
37
    def test_check_output(self):
38
        self.check_output()
39

L
Liu Yiqun 已提交
40 41
    #def test_check_grad(self):
    #    self.check_grad(["X0", "X1", "W0", "W1", "b"], "Y")
42 43 44 45


if __name__ == '__main__':
    unittest.main()