Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
a05707ff
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a05707ff
编写于
3月 02, 2017
作者:
L
Luo Tao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test cost
上级
acff4c40
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
30 addition
and
8 deletion
+30
-8
demo/mnist/api_train_v2.py
demo/mnist/api_train_v2.py
+19
-6
python/paddle/v2/event.py
python/paddle/v2/event.py
+2
-1
python/paddle/v2/trainer.py
python/paddle/v2/trainer.py
+9
-1
未找到文件。
demo/mnist/api_train_v2.py
浏览文件 @
a05707ff
...
...
@@ -63,6 +63,8 @@ def main():
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.
predict
=
softmax_regression
(
images
)
#predict = multilayer_perceptron(images)
#predict = convolutional_neural_network(images)
...
...
@@ -80,14 +82,20 @@ def main():
parameters
=
parameters
,
update_equation
=
optimizer
)
list
=
[]
def
event_handler
(
event
):
if
isinstance
(
event
,
paddle
.
event
.
EndIteration
):
if
event
.
batch_id
%
100
==
0
:
print
"Pass %d, Batch %d, Cost %f, %s"
%
(
event
.
pass_id
,
event
.
batch_id
,
event
.
cost
,
event
.
metrics
)
if
isinstance
(
event
,
paddle
.
event
.
EndPass
):
result
=
trainer
.
test
(
reader
=
paddle
.
reader
.
batched
(
paddle
.
dataset
.
mnist
.
test
(),
batch_size
=
128
))
print
"Pass %d, Batch %d, Cost %f, %s, Testing metrics %s"
%
(
event
.
pass_id
,
event
.
batch_id
,
event
.
cost
,
event
.
metrics
,
result
.
metrics
)
print
"Test with Pass %d, Cost %f, %s
\n
"
%
(
event
.
pass_id
,
event
.
cost
,
result
.
metrics
)
list
.
append
((
event
.
pass_id
,
event
.
cost
,
result
.
metrics
[
'classification_error_evaluator'
]))
trainer
.
train
(
reader
=
paddle
.
reader
.
batched
(
...
...
@@ -97,10 +105,15 @@ def main():
event_handler
=
event_handler
,
num_passes
=
100
)
# find the best pass
best
=
sorted
(
list
,
key
=
lambda
list
:
float
(
list
[
1
]))[
0
]
print
'Best pass is %s, testing Avgcost is %s'
%
(
best
[
0
],
best
[
1
])
print
'The classification accuracy is %.2f%%'
%
(
100
-
float
(
best
[
2
])
*
100
)
# output is a softmax layer. It returns probabilities.
# Shape should be (100, 10)
probs
=
paddle
.
infer
(
output
=
inference
,
output
=
predict
,
parameters
=
parameters
,
reader
=
paddle
.
reader
.
batched
(
paddle
.
reader
.
firstn
(
...
...
python/paddle/v2/event.py
浏览文件 @
a05707ff
...
...
@@ -52,8 +52,9 @@ class EndPass(WithMetric):
Event On One Pass Training Complete.
"""
def
__init__
(
self
,
pass_id
,
evaluator
):
def
__init__
(
self
,
pass_id
,
cost
,
evaluator
):
self
.
pass_id
=
pass_id
self
.
cost
=
cost
WithMetric
.
__init__
(
self
,
evaluator
)
...
...
python/paddle/v2/trainer.py
浏览文件 @
a05707ff
...
...
@@ -107,6 +107,8 @@ class SGD(ITrainer):
event_handler
(
v2_event
.
BeginPass
(
pass_id
))
pass_evaluator
.
start
()
updater
.
startPass
()
total_cost_sum
=
0
total_batch
=
0
for
batch_id
,
data_batch
in
enumerate
(
reader
()):
pass_type
=
updater
.
startBatch
(
len
(
data_batch
))
self
.
__gradient_machine__
.
forwardBackward
(
...
...
@@ -127,6 +129,8 @@ class SGD(ITrainer):
cost_vec
=
out_args
.
getSlotValue
(
0
)
cost_vec
=
cost_vec
.
copyToNumpyMat
()
cost
=
cost_vec
.
sum
()
/
len
(
data_batch
)
total_cost_sum
+=
cost_vec
.
sum
()
total_batch
+=
len
(
data_batch
)
updater
.
finishBatch
(
cost
)
batch_evaluator
.
finish
()
event_handler
(
...
...
@@ -138,7 +142,11 @@ class SGD(ITrainer):
updater
.
finishPass
()
pass_evaluator
.
finish
()
event_handler
(
v2_event
.
EndPass
(
pass_id
,
evaluator
=
pass_evaluator
))
event_handler
(
v2_event
.
EndPass
(
pass_id
,
cost
=
total_cost_sum
/
total_batch
,
evaluator
=
pass_evaluator
))
self
.
__gradient_machine__
.
finish
()
def
default_reader_dict
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录