test_fc_op.py 1.3 KB
Newer Older
1 2
import unittest
import numpy as np
L
Liu Yiqun 已提交
3 4
from op_test import OpTest
import paddle.v2.framework.core as core
5
from paddle.v2.framework.op import Operator
6 7


L
Liu Yiqun 已提交
8
class TestFCOp(OpTest):
9
    def setUp(self):
L
Liu Yiqun 已提交
10 11 12 13 14 15 16
        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")
17
        self.inputs = {
L
Liu Yiqun 已提交
18 19 20 21 22 23 24 25 26
            "X": {
                "X0": x0,
                "X1": x1
            },
            "W": {
                "W0": w0,
                "W1": w1
            },
            "b": b
27
        }
L
Liu Yiqun 已提交
28 29 30 31 32
        #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
33 34 35
        self.outputs = {
            "mul_out": mul_out,
            "add_out": add_out,
L
Liu Yiqun 已提交
36
            "Y": sigmoid_out
37
        }
38

L
Liu Yiqun 已提交
39 40 41
    def test_check_output(self):
        self.check_output(core.CPUPlace())
        self.check_output(core.GPUPlace(0))
42

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


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