test_net.py 1.8 KB
Newer Older
D
dzhwinter 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
#  Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserve.
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
Q
Qiao Longfei 已提交
14 15
import paddle.v2.fluid.core as core
from paddle.v2.fluid.op import Operator
Y
Yu Yang 已提交
16 17 18
import unittest


19 20 21
def fc(X, W, Y):
    ret_v = core.Net.create()

Y
Yu Yang 已提交
22
    ret_v.append_op(Operator("mul", X="X", Y="W", Out="pre_activation"))
F
fengjiayi 已提交
23
    ret_v.append_op(Operator("sigmoid", X="pre_activation", Out=Y))
24 25 26 27
    ret_v.complete_add_op(True)
    return ret_v


Y
Yu Yang 已提交
28 29 30
class TestNet(unittest.TestCase):
    def test_net_all(self):
        net = core.Net.create()
Y
Fix CI  
Yu Yang 已提交
31
        op1 = Operator("sum", X=["X", "Y"], Out="Out")
Y
Yu Yang 已提交
32
        net.append_op(op1)
Y
Yu Yang 已提交
33 34

        net2 = core.Net.create()
Y
Yu Yang 已提交
35
        net2.append_op(fc(X="X", W="w", Y="fc.out"))
Y
Yu Yang 已提交
36
        net2.complete_add_op(True)
Y
Yu Yang 已提交
37
        net.append_op(net2)
Y
Yu Yang 已提交
38
        net.complete_add_op(True)
Y
Yu Yang 已提交
39 40

        expected = '''
Y
Yu Yang 已提交
41
Op(plain_net), inputs:{all[W, X, Y]}, outputs:{all[Out, fc.out, pre_activation]}.
Y
Fix CI  
Yu Yang 已提交
42
    Op(sum), inputs:{X[X, Y]}, outputs:{Out[Out]}.
Y
Yu Yang 已提交
43 44 45
    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]}.
F
fengjiayi 已提交
46
            Op(sigmoid), inputs:{X[pre_activation]}, outputs:{Out[fc.out]}.
Y
Yu Yang 已提交
47
'''
Y
Yu Yang 已提交
48
        self.assertEqual(expected, "\n" + str(net))
Y
Yu Yang 已提交
49 50


Q
qijun 已提交
51
if __name__ == "__main__":
Y
Yu Yang 已提交
52
    unittest.main()