This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[High-Level-API] Update MNIST to use optimizer_func #535
Merged
jetfuel
merged 4 commits into
PaddlePaddle:high-level-api-branch
from
jetfuel:fixOptimzerFuncMnist
Jun 6, 2018
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we rephrase: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, sounds good. |
||
|
||
```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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we elaborate a bit? I like the description of the
train_program
. Can we write something like "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."