From c0e687b939904b60232f3f01f7acbba3164dfbd2 Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Tue, 20 Dec 2016 17:32:57 +0800 Subject: [PATCH] Refine Code --- demo/mnist/api_train.py | 12 ++++++++++++ demo/mnist/simple_mnist_network.py | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 demo/mnist/api_train.py create mode 100644 demo/mnist/simple_mnist_network.py diff --git a/demo/mnist/api_train.py b/demo/mnist/api_train.py new file mode 100644 index 00000000000..6abb5d4e562 --- /dev/null +++ b/demo/mnist/api_train.py @@ -0,0 +1,12 @@ +import py_paddle.swig_paddle as api +from paddle.trainer.config_parser import parse_config + + +def main(): + api.initPaddle("-use_gpu=false", "-trainer_count=4") # use 4 cpu cores + config = parse_config('simple_mnist_network.py', '') + m = api.GradientMachine.createFromConfigProto(config.model_config) + + +if __name__ == '__main__': + main() diff --git a/demo/mnist/simple_mnist_network.py b/demo/mnist/simple_mnist_network.py new file mode 100644 index 00000000000..41f4e51657d --- /dev/null +++ b/demo/mnist/simple_mnist_network.py @@ -0,0 +1,16 @@ +from paddle.trainer_config_helpers import * + +settings(learning_rate=1e-4, learning_method=AdamOptimizer(), batch_size=1000) + +imgs = data_layer(name='pixel', size=784) + +hidden1 = fc_layer(input=imgs, size=200) +hidden2 = fc_layer(input=hidden1, size=200) + +inference = fc_layer(input=hidden2, size=10, act=SoftmaxActivation()) + +cost = classification_cost( + input=inference, label=data_layer( + name='label', size=10)) + +outputs(cost) -- GitLab