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 = '''
28
Op(plain_net), inputs:(W, X, Y), outputs:(Out, fc.out, pre_activation).
Y
Yu Yang 已提交
29
    Op(add_two), inputs:(X, Y), outputs:(Out).
30 31 32 33
    Op(plain_net), inputs:(W, X), outputs:(fc.out, pre_activation).
        Op(plain_net), inputs:(W, X), outputs:(fc.out, pre_activation).
            Op(mul), inputs:(X, W), outputs:(pre_activation).
            Op(sigmoid), inputs:(pre_activation), outputs:(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()