Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
迷途归一
Paddle
提交
dcc332a8
P
Paddle
项目概览
迷途归一
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dcc332a8
编写于
2月 27, 2017
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Follow qq's comments
上级
f3f24604
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
8 addition
and
16 deletion
+8
-16
demo/mnist/api_train_v2.py
demo/mnist/api_train_v2.py
+1
-1
python/paddle/v2/trainer.py
python/paddle/v2/trainer.py
+7
-15
未找到文件。
demo/mnist/api_train_v2.py
浏览文件 @
dcc332a8
...
...
@@ -37,7 +37,7 @@ def main():
trainer
=
paddle
.
trainer
.
SGD
(
update_equation
=
adam_optimizer
)
trainer
.
train
(
train_
reader
=
paddle
.
reader
.
batched
(
reader
=
paddle
.
reader
.
batched
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
mnist
.
train_creator
(),
buf_size
=
8192
),
batch_size
=
32
),
topology
=
cost
,
...
...
python/paddle/v2/trainer.py
浏览文件 @
dcc332a8
...
...
@@ -28,19 +28,13 @@ class ITrainer(object):
The interface of Trainer. The only exposed method is `train`.
"""
def
train
(
self
,
train_reader_creator
,
topology
,
parameters
,
test_data_reader
=
None
,
event_handler
=
None
):
def
train
(
self
,
reader
,
topology
,
parameters
,
event_handler
=
None
):
"""
train method.
:param
train_reader_creato
r:
:param
reade
r:
:param topology:
:param parameters:
:param test_data_reader:
:param event_handler:
:return:
"""
...
...
@@ -62,7 +56,7 @@ class SGD(ITrainer):
self
.
__optimizer__
=
update_equation
def
train
(
self
,
train_
reader
,
reader
,
topology
,
parameters
,
num_passes
=
1
,
...
...
@@ -72,7 +66,7 @@ class SGD(ITrainer):
"""
Training method. Will train num_passes of input data.
:param
train_
reader:
:param reader:
:param topology: Network Topology, use one or more Layers to represent it.
:param parameters: The parameter pools.
:param num_passes: The total train passes.
...
...
@@ -104,7 +98,7 @@ class SGD(ITrainer):
for
pass_id
in
xrange
(
num_passes
):
updater
.
startPass
()
for
batch_id
,
data_batch
in
enumerate
(
train_
reader
()):
for
batch_id
,
data_batch
in
enumerate
(
reader
()):
pass_type
=
updater
.
startBatch
(
len
(
data_batch
))
gm
.
forwardBackward
(
feeder
(
data_batch
),
out_args
,
pass_type
)
for
each_param
in
gm
.
getParameters
():
...
...
@@ -122,13 +116,11 @@ class SGD(ITrainer):
gm
.
finish
()
def
__check_train_args__
(
train_reader
,
topology
,
parameters
,
event_handler
,
**
kwargs
):
def
__check_train_args__
(
reader
,
topology
,
parameters
,
event_handler
,
**
kwargs
):
"""
Check train function's argument types
"""
if
not
callable
(
train_reader
)
or
not
isinstance
(
train_reader
(),
collections
.
Iterator
):
if
not
callable
(
reader
)
or
not
isinstance
(
reader
(),
collections
.
Iterator
):
raise
TypeError
(
'train_data_reader should be a function, '
'which can return a iterator'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录