test_net.py 1.2 KB
Newer Older
Y
Yu Yang 已提交
1
import paddle.v2.framework.core as core
Y
Yu Yang 已提交
2
from paddle.v2.framework.op import Operator
Y
Yu Yang 已提交
3 4 5
import unittest


6 7 8 9 10 11 12 13 14
def fc(X, W, Y):
    ret_v = core.Net.create()

    ret_v.add_op(Operator("mul", X="X", Y="W", Out="pre_activation"))
    ret_v.add_op(Operator("sigmoid", X="pre_activation", Y=Y))
    ret_v.complete_add_op(True)
    return ret_v


Y
Yu Yang 已提交
15 16 17
class TestNet(unittest.TestCase):
    def test_net_all(self):
        net = core.Net.create()
Y
Yu Yang 已提交
18
        op1 = Operator("add_two", X="X", Y="Y", Out="Out")
Y
Yu Yang 已提交
19 20 21
        net.add_op(op1)

        net2 = core.Net.create()
22
        net2.add_op(fc(X="X", W="w", Y="fc.out"))
Y
Yu Yang 已提交
23 24 25
        net2.complete_add_op(True)
        net.add_op(net2)
        net.complete_add_op(True)
Y
Yu Yang 已提交
26 27

        expected = '''
Y
Yu Yang 已提交
28 29 30 31 32 33
Op(plain_net), inputs:{all[W, X, Y]}, outputs:{all[Out, fc.out, pre_activation]}.
    Op(add_two), inputs:{X[X], Y[Y]}, outputs:{Out[Out]}.
    Op(plain_net), inputs:{all[W, X]}, outputs:{all[fc.out, pre_activation]}.
        Op(plain_net), inputs:{all[W, X]}, outputs:{all[fc.out, pre_activation]}.
            Op(mul), inputs:{X[X], Y[W]}, outputs:{Out[pre_activation]}.
            Op(sigmoid), inputs:{X[pre_activation]}, outputs:{Y[fc.out]}.
Y
Yu Yang 已提交
34
'''
Y
Yu Yang 已提交
35
        self.assertEqual(expected, "\n" + str(net))
Y
Yu Yang 已提交
36 37 38 39


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