From bd99369652571f9401039728faf055c61f48a0be Mon Sep 17 00:00:00 2001 From: "Wang,Jeff" Date: Tue, 5 Jun 2018 17:52:47 -0700 Subject: [PATCH 1/4] Change to use optimzer func --- 02.recognize_digits/train.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/02.recognize_digits/train.py b/02.recognize_digits/train.py index d9947e4e..8b91432e 100644 --- a/02.recognize_digits/train.py +++ b/02.recognize_digits/train.py @@ -62,6 +62,10 @@ def train_program(): return [avg_cost, acc] +def optimizer_program(): + return fluid.optimizer.Adam(learning_rate=0.001) + + def main(): train_reader = paddle.batch( paddle.reader.shuffle(paddle.dataset.mnist.train(), buf_size=500), @@ -71,10 +75,9 @@ def main(): use_cuda = os.getenv('WITH_GPU', '0') != '0' place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() - optimizer = fluid.optimizer.Adam(learning_rate=0.001) trainer = fluid.Trainer( - train_func=train_program, place=place, optimizer=optimizer) + train_func=train_program, place=place, optimizer_func=optimizer_program) # Save the parameter into a directory. The Inferencer can load the parameters from it to do infer params_dirname = "recognize_digits_network.inference.model" From be85a58dbc4d0faadec6b208bd653132be953737 Mon Sep 17 00:00:00 2001 From: "Wang,Jeff" Date: Tue, 5 Jun 2018 17:56:02 -0700 Subject: [PATCH 2/4] Change to use optimizer func in markdown --- 02.recognize_digits/README.md | 13 ++++++++++--- 02.recognize_digits/index.html | 13 ++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/02.recognize_digits/README.md b/02.recognize_digits/README.md index 66e526bd..754f0838 100644 --- a/02.recognize_digits/README.md +++ b/02.recognize_digits/README.md @@ -245,6 +245,15 @@ def train_program(): return [avg_cost, acc] ``` +#### Optimizer Function Configuration + +In the following `Adam` optimizer, `learning_rate` means the speed at which the network training converges. + +```python +def optimizer_program(): + return fluid.optimizer.Adam(learning_rate=0.001) +``` + ### Data Feeders Configuration Then we specify the training data `paddle.dataset.mnist.train()` and testing data `paddle.dataset.mnist.test()`. These two methods are *reader creators*. Once called, a reader creator returns a *reader*. A reader is a Python method, which, once called, returns a Python generator, which yields instances of data. @@ -266,15 +275,13 @@ test_reader = paddle.batch( ### Trainer Configuration Now, we need to setup the trainer. The trainer need to take in `train_program`, `place`, and `optimizer`. -In the following `Adam` optimizer, `learning_rate` means the speed at which the network training converges. ```python use_cuda = False # set to True if training with GPU place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() -optimizer = fluid.optimizer.Adam(learning_rate=0.001) trainer = fluid.Trainer( - train_func=train_program, place=place, optimizer=optimizer) + train_func=train_program, place=place, optimizer_func=optimizer_program) ``` #### Event Handler diff --git a/02.recognize_digits/index.html b/02.recognize_digits/index.html index c83d5bce..9436cb28 100644 --- a/02.recognize_digits/index.html +++ b/02.recognize_digits/index.html @@ -287,6 +287,15 @@ return [avg_cost, acc] ``` +#### Optimizer Function Configuration + +In the following `Adam` optimizer, `learning_rate` means the speed at which the network training converges. + +```python +def optimizer_program(): + return fluid.optimizer.Adam(learning_rate=0.001) +``` + ### Data Feeders Configuration Then we specify the training data `paddle.dataset.mnist.train()` and testing data `paddle.dataset.mnist.test()`. These two methods are *reader creators*. Once called, a reader creator returns a *reader*. A reader is a Python method, which, once called, returns a Python generator, which yields instances of data. @@ -308,15 +317,13 @@ ### Trainer Configuration Now, we need to setup the trainer. The trainer need to take in `train_program`, `place`, and `optimizer`. -In the following `Adam` optimizer, `learning_rate` means the speed at which the network training converges. ```python use_cuda = False # set to True if training with GPU place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() -optimizer = fluid.optimizer.Adam(learning_rate=0.001) trainer = fluid.Trainer( - train_func=train_program, place=place, optimizer=optimizer) + train_func=train_program, place=place, optimizer_func=optimizer_program) ``` #### Event Handler From 432f051712f18b43571b5319fa5fe94557d55a17 Mon Sep 17 00:00:00 2001 From: "Wang,Jeff" Date: Wed, 6 Jun 2018 11:16:13 -0700 Subject: [PATCH 3/4] Update the Mnist tutorial to use optimizer_func --- 02.recognize_digits/README.cn.md | 15 +++++++++++---- 02.recognize_digits/README.md | 2 +- 02.recognize_digits/index.cn.html | 15 +++++++++++---- 02.recognize_digits/index.html | 2 +- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/02.recognize_digits/README.cn.md b/02.recognize_digits/README.cn.md index bf7b5ce4..b7d6ab7e 100644 --- a/02.recognize_digits/README.cn.md +++ b/02.recognize_digits/README.cn.md @@ -139,7 +139,7 @@ PaddlePaddle在API中提供了自动加载[MNIST](http://yann.lecun.com/exdb/mni 1. `train_program`:指定如何从 `inference_program` 和`标签值`中获取 `loss` 的函数。 这是指定损失计算的地方。 -1. `optimizer`: 配置如何最小化损失。PaddlePaddle 支持最主要的优化方法。 +1. `optimizer_func`: 配置如何最小化损失。PaddlePaddle 支持最主要的优化方法。 1. `Trainer`:PaddlePaddle Trainer 管理由 `train_program` 和 `optimizer` 指定的训练过程。 通过 `event_handler` 回调函数,用户可以监控培训的进展。 @@ -238,6 +238,15 @@ def train_program(): # 该模型运行在单个CPU上 ``` +#### Optimizer Function 配置 + +在下面的 `Adam optimizer`,`learning_rate` 是训练的速度,与网络的训练收敛速度有关系。 + +```python +def optimizer_program(): + return fluid.optimizer.Adam(learning_rate=0.001) +``` + ### 数据集 Feeders 配置 下一步,我们开始训练过程。`paddle.dataset.movielens.train()`和`paddle.dataset.movielens.test()`分别做训练和测试数据集。这两个函数各自返回一个reader——PaddlePaddle中的reader是一个Python函数,每次调用的时候返回一个Python yield generator。 @@ -259,16 +268,14 @@ test_reader = paddle.batch( ### Trainer 配置 现在,我们需要配置 `Trainer`。`Trainer` 需要接受训练程序 `train_program`, `place` 和优化器 `optimizer`。 -在下面的 `Adam optimizer`,`learning_rate` 是训练的速度,与网络的训练收敛速度有关系。 ```python # 该模型运行在单个CPU上 use_cuda = False # set to True if training with GPU place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() -optimizer = fluid.optimizer.Adam(learning_rate=0.001) trainer = fluid.Trainer( - train_func=train_program, place=place, optimizer=optimizer) + train_func=train_program, place=place, optimizer_func=optimizer_program) ``` #### Event Handler 配置 diff --git a/02.recognize_digits/README.md b/02.recognize_digits/README.md index 754f0838..32fcfb3e 100644 --- a/02.recognize_digits/README.md +++ b/02.recognize_digits/README.md @@ -146,7 +146,7 @@ Here are the quick overview on the major fluid API complements. This is where you specify the network flow. 1. `train_program`: A function that specify how to get avg_cost from `inference_program` and labels. This is where you specify the loss calculations. -1. `optimizer`: Configure how to minimize the loss. Paddle supports most major optimization methods. +1. `optimizer_func`: Configure how to minimize the loss. Paddle supports most major optimization methods. 1. `Trainer`: Fluid trainer manages the training process specified by the `train_program` and `optimizer`. Users can monitor the training progress through the `event_handler` callback function. 1. `Inferencer`: Fluid inferencer loads the `inference_program` and the parameters trained by the Trainer. diff --git a/02.recognize_digits/index.cn.html b/02.recognize_digits/index.cn.html index 48289298..f7e9266a 100644 --- a/02.recognize_digits/index.cn.html +++ b/02.recognize_digits/index.cn.html @@ -181,7 +181,7 @@ 1. `train_program`:指定如何从 `inference_program` 和`标签值`中获取 `loss` 的函数。 这是指定损失计算的地方。 -1. `optimizer`: 配置如何最小化损失。PaddlePaddle 支持最主要的优化方法。 +1. `optimizer_func`: 配置如何最小化损失。PaddlePaddle 支持最主要的优化方法。 1. `Trainer`:PaddlePaddle Trainer 管理由 `train_program` 和 `optimizer` 指定的训练过程。 通过 `event_handler` 回调函数,用户可以监控培训的进展。 @@ -280,6 +280,15 @@ # 该模型运行在单个CPU上 ``` +#### Optimizer Function 配置 + +在下面的 `Adam optimizer`,`learning_rate` 是训练的速度,与网络的训练收敛速度有关系。 + +```python +def optimizer_program(): + return fluid.optimizer.Adam(learning_rate=0.001) +``` + ### 数据集 Feeders 配置 下一步,我们开始训练过程。`paddle.dataset.movielens.train()`和`paddle.dataset.movielens.test()`分别做训练和测试数据集。这两个函数各自返回一个reader——PaddlePaddle中的reader是一个Python函数,每次调用的时候返回一个Python yield generator。 @@ -301,16 +310,14 @@ ### Trainer 配置 现在,我们需要配置 `Trainer`。`Trainer` 需要接受训练程序 `train_program`, `place` 和优化器 `optimizer`。 -在下面的 `Adam optimizer`,`learning_rate` 是训练的速度,与网络的训练收敛速度有关系。 ```python # 该模型运行在单个CPU上 use_cuda = False # set to True if training with GPU place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() -optimizer = fluid.optimizer.Adam(learning_rate=0.001) trainer = fluid.Trainer( - train_func=train_program, place=place, optimizer=optimizer) + train_func=train_program, place=place, optimizer_func=optimizer_program) ``` #### Event Handler 配置 diff --git a/02.recognize_digits/index.html b/02.recognize_digits/index.html index 9436cb28..026d7c0e 100644 --- a/02.recognize_digits/index.html +++ b/02.recognize_digits/index.html @@ -188,7 +188,7 @@ This is where you specify the network flow. 1. `train_program`: A function that specify how to get avg_cost from `inference_program` and labels. This is where you specify the loss calculations. -1. `optimizer`: Configure how to minimize the loss. Paddle supports most major optimization methods. +1. `optimizer_func`: Configure how to minimize the loss. Paddle supports most major optimization methods. 1. `Trainer`: Fluid trainer manages the training process specified by the `train_program` and `optimizer`. Users can monitor the training progress through the `event_handler` callback function. 1. `Inferencer`: Fluid inferencer loads the `inference_program` and the parameters trained by the Trainer. From babc05d17d071da5200c7e00808ef411ff37d111 Mon Sep 17 00:00:00 2001 From: "Wang,Jeff" Date: Wed, 6 Jun 2018 12:04:42 -0700 Subject: [PATCH 4/4] Rephrase the sentences to improve the readiability --- 02.recognize_digits/README.cn.md | 2 +- 02.recognize_digits/README.md | 4 ++-- 02.recognize_digits/index.cn.html | 2 +- 02.recognize_digits/index.html | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/02.recognize_digits/README.cn.md b/02.recognize_digits/README.cn.md index b7d6ab7e..110ee121 100644 --- a/02.recognize_digits/README.cn.md +++ b/02.recognize_digits/README.cn.md @@ -139,7 +139,7 @@ PaddlePaddle在API中提供了自动加载[MNIST](http://yann.lecun.com/exdb/mni 1. `train_program`:指定如何从 `inference_program` 和`标签值`中获取 `loss` 的函数。 这是指定损失计算的地方。 -1. `optimizer_func`: 配置如何最小化损失。PaddlePaddle 支持最主要的优化方法。 +1. `optimizer_func`: “指定优化器配置的函数。优化器负责减少损失并驱动培训。Paddle 支持多种不同的优化器。 1. `Trainer`:PaddlePaddle Trainer 管理由 `train_program` 和 `optimizer` 指定的训练过程。 通过 `event_handler` 回调函数,用户可以监控培训的进展。 diff --git a/02.recognize_digits/README.md b/02.recognize_digits/README.md index 32fcfb3e..7c6792ff 100644 --- a/02.recognize_digits/README.md +++ b/02.recognize_digits/README.md @@ -146,7 +146,7 @@ Here are the quick overview on the major fluid API complements. This is where you specify the network flow. 1. `train_program`: A function that specify how to get avg_cost from `inference_program` and labels. This is where you specify the loss calculations. -1. `optimizer_func`: Configure how to minimize the loss. Paddle supports most major optimization methods. +1. `optimizer_func`:"A function that specifies the configuration of the the optimizer. The optimizer is responsible for minimizing the loss and driving the training. Paddle supports many different optimizers." 1. `Trainer`: Fluid trainer manages the training process specified by the `train_program` and `optimizer`. Users can monitor the training progress through the `event_handler` callback function. 1. `Inferencer`: Fluid inferencer loads the `inference_program` and the parameters trained by the Trainer. @@ -247,7 +247,7 @@ def train_program(): #### Optimizer Function Configuration -In the following `Adam` optimizer, `learning_rate` means the speed at which the network training converges. +In the following `Adam` optimizer, `learning_rate` specifies the learning rate in the optimization procedure. ```python def optimizer_program(): diff --git a/02.recognize_digits/index.cn.html b/02.recognize_digits/index.cn.html index f7e9266a..6a7e018c 100644 --- a/02.recognize_digits/index.cn.html +++ b/02.recognize_digits/index.cn.html @@ -181,7 +181,7 @@ 1. `train_program`:指定如何从 `inference_program` 和`标签值`中获取 `loss` 的函数。 这是指定损失计算的地方。 -1. `optimizer_func`: 配置如何最小化损失。PaddlePaddle 支持最主要的优化方法。 +1. `optimizer_func`: “指定优化器配置的函数。优化器负责减少损失并驱动培训。Paddle 支持多种不同的优化器。 1. `Trainer`:PaddlePaddle Trainer 管理由 `train_program` 和 `optimizer` 指定的训练过程。 通过 `event_handler` 回调函数,用户可以监控培训的进展。 diff --git a/02.recognize_digits/index.html b/02.recognize_digits/index.html index 026d7c0e..800113c2 100644 --- a/02.recognize_digits/index.html +++ b/02.recognize_digits/index.html @@ -188,7 +188,7 @@ This is where you specify the network flow. 1. `train_program`: A function that specify how to get avg_cost from `inference_program` and labels. This is where you specify the loss calculations. -1. `optimizer_func`: Configure how to minimize the loss. Paddle supports most major optimization methods. +1. `optimizer_func`:"A function that specifies the configuration of the the optimizer. The optimizer is responsible for minimizing the loss and driving the training. Paddle supports many different optimizers." 1. `Trainer`: Fluid trainer manages the training process specified by the `train_program` and `optimizer`. Users can monitor the training progress through the `event_handler` callback function. 1. `Inferencer`: Fluid inferencer loads the `inference_program` and the parameters trained by the Trainer. @@ -289,7 +289,7 @@ #### Optimizer Function Configuration -In the following `Adam` optimizer, `learning_rate` means the speed at which the network training converges. +In the following `Adam` optimizer, `learning_rate` specifies the learning rate in the optimization procedure. ```python def optimizer_program():