From 1700cbdd29af6745bb3fdd266c071e75034f8f18 Mon Sep 17 00:00:00 2001 From: qijun Date: Mon, 17 Apr 2017 14:33:07 +0800 Subject: [PATCH] pass pre-commit --- 02.recognize_digits/train.py | 16 ++++++++-------- 08.recommender_system/train.py | 5 +++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/02.recognize_digits/train.py b/02.recognize_digits/train.py index a69548a..d6ea883 100644 --- a/02.recognize_digits/train.py +++ b/02.recognize_digits/train.py @@ -44,13 +44,15 @@ def convolutional_neural_network(img): input=conv_pool_2, size=10, act=paddle.activation.Softmax()) return predict + def main(): paddle.init(use_gpu=False, trainer_count=1) # define network topology images = paddle.layer.data( name='pixel', type=paddle.data_type.dense_vector(784)) - label = paddle.layer.data(name='label', type=paddle.data_type.integer_value(10)) + label = paddle.layer.data( + name='label', type=paddle.data_type.integer_value(10)) # Here we can build the prediction network in different ways. Please # choose one by uncomment corresponding line. @@ -72,7 +74,6 @@ def main(): lists = [] - def event_handler(event): if isinstance(event, paddle.event.EndIteration): if event.batch_id % 100 == 0: @@ -81,12 +82,10 @@ def main(): if isinstance(event, paddle.event.EndPass): result = trainer.test(reader=paddle.batch( paddle.dataset.mnist.test(), batch_size=128)) - print "Test with Pass %d, Cost %f, %s\n" % (event.pass_id, - result.cost, - result.metrics) + print "Test with Pass %d, Cost %f, %s\n" % ( + event.pass_id, result.cost, result.metrics) lists.append((event.pass_id, result.cost, - result.metrics['classification_error_evaluator'])) - + result.metrics['classification_error_evaluator'])) trainer.train( reader=paddle.batch( @@ -100,5 +99,6 @@ def main(): print 'Best pass is %s, testing Avgcost is %s' % (best[0], best[1]) print 'The classification accuracy is %.2f%%' % (100 - float(best[2]) * 100) + if __name__ == '__main__': - main() + main() diff --git a/08.recommender_system/train.py b/08.recommender_system/train.py index 7c6274f..37d35ed 100644 --- a/08.recommender_system/train.py +++ b/08.recommender_system/train.py @@ -3,7 +3,7 @@ import cPickle import copy -def get_usr_combined_features(): +def get_usr_combined_features(): uid = paddle.layer.data( name='user_id', type=paddle.data_type.integer_value( @@ -36,6 +36,7 @@ def get_usr_combined_features(): act=paddle.activation.Tanh()) return usr_combined_features + def get_mov_combined_features(): movie_title_dict = paddle.dataset.movielens.get_movie_title_dict() mov_id = paddle.layer.data( @@ -63,7 +64,7 @@ def get_mov_combined_features(): size=200, act=paddle.activation.Tanh()) return mov_combined_features - + def main(): paddle.init(use_gpu=False) -- GitLab