Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
1524f204
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1524f204
编写于
3月 02, 2017
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add testing cost.
上级
1f7134c6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
15 addition
and
9 deletion
+15
-9
demo/mnist/api_train_v2.py
demo/mnist/api_train_v2.py
+5
-4
python/paddle/v2/event.py
python/paddle/v2/event.py
+2
-1
python/paddle/v2/trainer.py
python/paddle/v2/trainer.py
+8
-4
未找到文件。
demo/mnist/api_train_v2.py
浏览文件 @
1524f204
...
@@ -30,10 +30,11 @@ def main():
...
@@ -30,10 +30,11 @@ def main():
result
=
trainer
.
test
(
reader
=
paddle
.
reader
.
batched
(
result
=
trainer
.
test
(
reader
=
paddle
.
reader
.
batched
(
paddle
.
dataset
.
mnist
.
test
(),
batch_size
=
256
))
paddle
.
dataset
.
mnist
.
test
(),
batch_size
=
256
))
print
"Pass %d, Batch %d, Cost %f, %s, Testing metrics %s"
%
(
print
"Pass %d, Batch %d, Cost %.2f, %s, "
\
event
.
pass_id
,
event
.
batch_id
,
event
.
cost
,
event
.
metrics
,
"Testing cost %.2f metrics %s"
%
(
result
.
metrics
)
event
.
pass_id
,
event
.
batch_id
,
event
.
cost
,
event
.
metrics
,
result
.
cost
,
result
.
metrics
)
else
:
else
:
pass
pass
...
...
python/paddle/v2/event.py
浏览文件 @
1524f204
...
@@ -34,8 +34,9 @@ class WithMetric(object):
...
@@ -34,8 +34,9 @@ class WithMetric(object):
class
TestResult
(
WithMetric
):
class
TestResult
(
WithMetric
):
def
__init__
(
self
,
evaluator
):
def
__init__
(
self
,
evaluator
,
cost
):
super
(
TestResult
,
self
).
__init__
(
evaluator
)
super
(
TestResult
,
self
).
__init__
(
evaluator
)
self
.
cost
=
cost
class
BeginPass
(
object
):
class
BeginPass
(
object
):
...
...
python/paddle/v2/trainer.py
浏览文件 @
1524f204
...
@@ -123,9 +123,8 @@ class SGD(ITrainer):
...
@@ -123,9 +123,8 @@ class SGD(ITrainer):
for
each_param
in
self
.
__gradient_machine__
.
getParameters
():
for
each_param
in
self
.
__gradient_machine__
.
getParameters
():
updater
.
update
(
each_param
)
updater
.
update
(
each_param
)
# Get cost. We use numpy to calculate total cost for this batch.
# Get cost. We use numpy to calculate total cost for this batch.
cost_vec
=
out_args
.
getSlotValue
(
0
)
cost_sum
=
out_args
.
sumCosts
()
cost_vec
=
cost_vec
.
copyToNumpyMat
()
cost
=
cost_sum
/
len
(
data_batch
)
cost
=
cost_vec
.
sum
()
/
len
(
data_batch
)
updater
.
finishBatch
(
cost
)
updater
.
finishBatch
(
cost
)
batch_evaluator
.
finish
()
batch_evaluator
.
finish
()
event_handler
(
event_handler
(
...
@@ -154,13 +153,18 @@ class SGD(ITrainer):
...
@@ -154,13 +153,18 @@ class SGD(ITrainer):
evaluator
=
self
.
__gradient_machine__
.
makeEvaluator
()
evaluator
=
self
.
__gradient_machine__
.
makeEvaluator
()
out_args
=
api
.
Arguments
.
createArguments
(
0
)
out_args
=
api
.
Arguments
.
createArguments
(
0
)
evaluator
.
start
()
evaluator
.
start
()
total_cost
=
0
num_samples
=
0.0
for
data_batch
in
reader
():
for
data_batch
in
reader
():
num_samples
+=
len
(
data_batch
)
self
.
__gradient_machine__
.
forward
(
self
.
__gradient_machine__
.
forward
(
feeder
(
data_batch
),
out_args
,
api
.
PASS_TEST
)
feeder
(
data_batch
),
out_args
,
api
.
PASS_TEST
)
total_cost
+=
out_args
.
sumCosts
()
self
.
__gradient_machine__
.
eval
(
evaluator
)
self
.
__gradient_machine__
.
eval
(
evaluator
)
evaluator
.
finish
()
evaluator
.
finish
()
return
v2_event
.
TestResult
(
evaluator
=
evaluator
)
return
v2_event
.
TestResult
(
evaluator
=
evaluator
,
cost
=
total_cost
/
num_samples
)
def
__check_train_args__
(
reader
,
event_handler
,
**
kwargs
):
def
__check_train_args__
(
reader
,
event_handler
,
**
kwargs
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录