Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DMLL
Paddle
提交
cafb075e
P
Paddle
项目概览
DMLL
/
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,发现更多精彩内容 >>
提交
cafb075e
编写于
2月 20, 2017
作者:
J
jacquesqiao
提交者:
GitHub
2月 20, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1361 from jacquesqiao/hide-parse_network
hide parse_config
上级
02b49b6c
695b5a7f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
19 deletion
+21
-19
demo/mnist/api_train_v2.py
demo/mnist/api_train_v2.py
+2
-3
python/paddle/v2/parameters.py
python/paddle/v2/parameters.py
+13
-13
python/paddle/v2/trainer.py
python/paddle/v2/trainer.py
+6
-3
未找到文件。
demo/mnist/api_train_v2.py
浏览文件 @
cafb075e
...
...
@@ -25,8 +25,7 @@ def main():
act
=
paddle
.
activation
.
Softmax
())
cost
=
paddle
.
layer
.
classification_cost
(
input
=
inference
,
label
=
label
)
topology
=
paddle
.
layer
.
parse_network
(
cost
)
parameters
=
paddle
.
parameters
.
create
(
topology
)
parameters
=
paddle
.
parameters
.
create
(
cost
)
for
param_name
in
parameters
.
keys
():
array
=
parameters
.
get
(
param_name
)
array
[:]
=
numpy
.
random
.
uniform
(
low
=-
1.0
,
high
=
1.0
,
size
=
array
.
shape
)
...
...
@@ -46,7 +45,7 @@ def main():
trainer
=
paddle
.
trainer
.
SGD
(
update_equation
=
adam_optimizer
)
trainer
.
train
(
train_data_reader
=
train_reader
,
topology
=
topology
,
topology
=
cost
,
parameters
=
parameters
,
event_handler
=
event_handler
,
batch_size
=
32
,
# batch size should be refactor in Data reader
...
...
python/paddle/v2/parameters.py
浏览文件 @
cafb075e
import
numpy
as
np
from
paddle.proto.ModelConfig_pb2
import
ModelConfig
from
paddle.proto.ParameterConfig_pb2
import
ParameterConfig
from
.
import
layer
as
v2_layer
import
py_paddle.swig_paddle
as
api
from
paddle.proto.ParameterConfig_pb2
import
ParameterConfig
__all__
=
[
'Parameters'
,
'create'
]
def
create
(
*
topologie
s
):
def
create
(
*
layer
s
):
"""
Create parameter pool by topologies.
Create parameter pool by layers. In paddle, layer can be represent a
model config.
:param
topologie
s:
:param
layer
s:
:return:
"""
pool
=
Parameters
()
for
topo
in
topologies
:
if
not
isinstance
(
topo
,
ModelConfig
):
for
layer
in
layers
:
if
not
isinstance
(
layer
,
v2_layer
.
Layer
):
raise
ValueError
(
'create must pass a topologies which type is ModelConfig'
)
for
param
in
topo
.
parameters
:
pool
.
__append_config__
(
param
)
'create must pass a topologies which type is paddle.layer.Layer'
)
model_config
=
v2_layer
.
parse_network
(
*
layers
)
pool
=
Parameters
()
for
param
in
model_config
.
parameters
:
pool
.
__append_config__
(
param
)
return
pool
...
...
python/paddle/v2/trainer.py
浏览文件 @
cafb075e
import
collections
import
py_paddle.swig_paddle
as
api
from
paddle.proto.ModelConfig_pb2
import
ModelConfig
from
py_paddle
import
DataProviderConverter
from
paddle.proto.ModelConfig_pb2
import
ModelConfig
from
.
import
event
as
v2_event
from
.
import
layer
as
v2_layer
from
.
import
optimizer
as
v2_optimizer
from
.
import
parameters
as
v2_parameters
from
.
import
event
as
v2_event
__all__
=
[
'ITrainer'
,
'SGD'
]
...
...
@@ -73,7 +74,7 @@ class SGD(ITrainer):
Training method. Will train num_passes of input data.
:param train_data_reader:
:param topology: Network Topology,
a protobuf ModelConfig message
.
:param topology: Network Topology,
use one or more Layers to represent it
.
:param parameters: The parameter pools.
:param num_passes: The total train passes.
:param test_data_reader:
...
...
@@ -87,6 +88,8 @@ class SGD(ITrainer):
if
event_handler
is
None
:
event_handler
=
default_event_handler
topology
=
v2_layer
.
parse_network
(
topology
)
__check_train_args__
(
**
locals
())
gm
=
api
.
GradientMachine
.
createFromConfigProto
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录