The fifth day, train the neural network

Ready to work

To PaddlePaddle Fluid stand-alone training, you need to prepare the data  and configure a simple network  . When the configuration simple network  After completion, can be two ,  and . By default, you can use to  get global .  fluid.Program startup_program main_program fluid.default_startup_program()fluid.default_main_program() fluid.Program

import paddle.fluid as fluid

image = fluid.layers.data(name="image", shape=[784])
label = fluid.layers.data(name="label", shape=[1])
hidden = fluid.layers.fc(input=image, size=100, act='relu')
prediction = fluid.layers.fc(input=hidden, size=10, act='softmax')
loss = fluid.layers.cross_entropy(input=prediction, label=label)
loss = fluid.layers.mean(loss)

sgd = fluid.optimizer.SGD(learning_rate=0.001)
sgd.minimize(loss)

# Here the fluid.default_startup_program() and fluid.default_main_program()
# has been constructed

 

Guess you like

Origin www.cnblogs.com/liuzhiqaingxyz/p/11389165.html