Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
106e6ae1
B
book
项目概览
PaddlePaddle
/
book
通知
17
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
40
列表
看板
标记
里程碑
合并请求
37
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
B
book
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
40
Issue
40
列表
看板
标记
里程碑
合并请求
37
合并请求
37
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
106e6ae1
编写于
6月 01, 2018
作者:
W
Wang,Jeff
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the incorrect softmax functions
上级
70a91c62
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
11 deletion
+21
-11
02.recognize_digits/README.md
02.recognize_digits/README.md
+6
-4
02.recognize_digits/index.html
02.recognize_digits/index.html
+6
-4
02.recognize_digits/train.py
02.recognize_digits/train.py
+9
-3
未找到文件。
02.recognize_digits/README.md
浏览文件 @
106e6ae1
...
...
@@ -174,9 +174,8 @@ Let us create a data layer for reading images and connect it to the classificati
```
python
def
softmax_regression
():
img
=
fluid
.
layers
.
data
(
name
=
'img'
,
shape
=
[
1
,
28
,
28
],
dtype
=
'float32'
)
predict
=
paddle
.
layer
.
fc
(
input
=
img
,
size
=
10
,
act
=
paddle
.
activation
.
Softmax
())
predict
=
fluid
.
layers
.
fc
(
input
=
img
,
size
=
10
,
act
=
'softmax'
)
return
predict
```
...
...
@@ -233,7 +232,7 @@ Please feel free to modify the code to test different results between `softmax r
def
train_program
():
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
# predict = softmax_regression(
images
) # uncomment for Softmax
# predict = softmax_regression() # uncomment for Softmax
# predict = multilayer_perceptron() # uncomment for MLP
predict
=
convolutional_neural_network
()
# uncomment for LeNet5
...
...
@@ -319,6 +318,8 @@ train_title = "Train cost"
test_title = "Test cost"
cost_ploter = Ploter(train_title, test_title)
step = 0
lists = []
# event_handler to plot a figure
def event_handler_plot(event):
global step
...
...
@@ -336,6 +337,7 @@ def event_handler_plot(event):
avg_cost, acc = trainer.test(
reader=test_reader, feed_order=['img', 'label'])
cost_ploter.append(test_title, step, avg_cost)
lists.append((event.epoch, avg_cost, acc))
```
Now that we setup the event_handler and the reader, we can start training the model. `feed_order` is used to map the data dict to the train_program
...
...
02.recognize_digits/index.html
浏览文件 @
106e6ae1
...
...
@@ -216,9 +216,8 @@ Let us create a data layer for reading images and connect it to the classificati
```python
def softmax_regression():
img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32')
predict = paddle.layer.fc(input=img,
size=10,
act=paddle.activation.Softmax())
predict = fluid.layers.fc(
input=img, size=10, act='softmax')
return predict
```
...
...
@@ -275,7 +274,7 @@ Please feel free to modify the code to test different results between `softmax r
def train_program():
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
# predict = softmax_regression(
images
) # uncomment for Softmax
# predict = softmax_regression() # uncomment for Softmax
# predict = multilayer_perceptron() # uncomment for MLP
predict = convolutional_neural_network() # uncomment for LeNet5
...
...
@@ -361,6 +360,8 @@ train_title = "Train cost"
test_title = "Test cost"
cost_ploter = Ploter(train_title, test_title)
step = 0
lists = []
# event_handler to plot a figure
def event_handler_plot(event):
global step
...
...
@@ -378,6 +379,7 @@ def event_handler_plot(event):
avg_cost, acc = trainer.test(
reader=test_reader, feed_order=['img', 'label'])
cost_ploter.append(test_title, step, avg_cost)
lists.append((event.epoch, avg_cost, acc))
```
Now that we setup the event_handler and the reader, we can start training the model. `feed_order` is used to map the data dict to the train_program
...
...
02.recognize_digits/train.py
浏览文件 @
106e6ae1
...
...
@@ -7,8 +7,7 @@ import paddle.fluid as fluid
def
softmax_regression
():
img
=
fluid
.
layers
.
data
(
name
=
'img'
,
shape
=
[
1
,
28
,
28
],
dtype
=
'float32'
)
predict
=
paddle
.
layer
.
fc
(
input
=
img
,
size
=
10
,
act
=
paddle
.
activation
.
Softmax
())
predict
=
fluid
.
layers
.
fc
(
input
=
img
,
size
=
10
,
act
=
'softmax'
)
return
predict
...
...
@@ -52,7 +51,7 @@ def train_program():
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
# Here we can build the prediction network in different ways. Please
# predict = softmax_regression(
images
) # uncomment for Softmax
# predict = softmax_regression() # uncomment for Softmax
# predict = multilayer_perceptron() # uncomment for MLP
predict
=
convolutional_neural_network
()
# uncomment for LeNet5
...
...
@@ -83,6 +82,13 @@ def main():
lists
=
[]
def
event_handler
(
event
):
if
isinstance
(
event
,
fluid
.
EndStepEvent
):
if
event
.
step
%
100
==
0
:
# event.metrics maps with train program return arguments.
# event.metrics[0] will yeild avg_cost and event.metrics[1] will yeild acc in this example.
print
"Pass %d, Batch %d, Cost %f"
%
(
event
.
step
,
event
.
epoch
,
event
.
metrics
[
0
])
if
isinstance
(
event
,
fluid
.
EndEpochEvent
):
avg_cost
,
acc
=
trainer
.
test
(
reader
=
test_reader
,
feed_order
=
[
'img'
,
'label'
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录