Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b9dd33f8
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b9dd33f8
编写于
2月 23, 2017
作者:
Q
qiaolongfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
hide Topology
上级
53bd4a48
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
17 addition
and
15 deletion
+17
-15
demo/mnist/api_train_v2.py
demo/mnist/api_train_v2.py
+2
-4
python/paddle/v2/parameters.py
python/paddle/v2/parameters.py
+3
-5
python/paddle/v2/topology.py
python/paddle/v2/topology.py
+9
-5
python/paddle/v2/trainer.py
python/paddle/v2/trainer.py
+3
-1
未找到文件。
demo/mnist/api_train_v2.py
浏览文件 @
b9dd33f8
...
@@ -26,9 +26,7 @@ def main():
...
@@ -26,9 +26,7 @@ def main():
act
=
paddle
.
activation
.
Softmax
())
act
=
paddle
.
activation
.
Softmax
())
cost
=
paddle
.
layer
.
classification_cost
(
input
=
inference
,
label
=
label
)
cost
=
paddle
.
layer
.
classification_cost
(
input
=
inference
,
label
=
label
)
topology
=
paddle
.
topology
.
Topology
(
cost
)
parameters
=
paddle
.
parameters
.
create
([
cost
])
parameters
=
paddle
.
parameters
.
create
(
topology
)
for
param_name
in
parameters
.
keys
():
for
param_name
in
parameters
.
keys
():
array
=
parameters
.
get
(
param_name
)
array
=
parameters
.
get
(
param_name
)
array
[:]
=
numpy
.
random
.
uniform
(
low
=-
1.0
,
high
=
1.0
,
size
=
array
.
shape
)
array
[:]
=
numpy
.
random
.
uniform
(
low
=-
1.0
,
high
=
1.0
,
size
=
array
.
shape
)
...
@@ -49,7 +47,7 @@ def main():
...
@@ -49,7 +47,7 @@ def main():
trainer
.
train
(
trainer
.
train
(
train_data_reader
=
train_reader
,
train_data_reader
=
train_reader
,
topology
=
topology
,
topology
=
[
cost
]
,
parameters
=
parameters
,
parameters
=
parameters
,
event_handler
=
event_handler
,
event_handler
=
event_handler
,
batch_size
=
32
)
# batch size should be refactor in Data reader
batch_size
=
32
)
# batch size should be refactor in Data reader
...
...
python/paddle/v2/parameters.py
浏览文件 @
b9dd33f8
...
@@ -7,15 +7,13 @@ import topology as v2_topology
...
@@ -7,15 +7,13 @@ import topology as v2_topology
__all__
=
[
'Parameters'
,
'create'
]
__all__
=
[
'Parameters'
,
'create'
]
def
create
(
topology
):
def
create
(
layers
):
"""
"""
Create parameter pool by topology.
Create parameter pool by topology.
:param
topology
:
:param
layers
:
:return:
:return:
"""
"""
if
not
isinstance
(
topology
,
v2_topology
.
Topology
):
topology
=
v2_topology
.
Topology
(
layers
)
raise
ValueError
(
'create must pass a topology which type is topology.Topology'
)
pool
=
Parameters
()
pool
=
Parameters
()
for
param
in
topology
.
proto
().
parameters
:
for
param
in
topology
.
proto
().
parameters
:
pool
.
__append_config__
(
param
)
pool
.
__append_config__
(
param
)
...
...
python/paddle/v2/topology.py
浏览文件 @
b9dd33f8
...
@@ -12,10 +12,13 @@
...
@@ -12,10 +12,13 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
from
paddle.proto.ModelConfig_pb2
import
ModelConfig
import
collections
import
paddle.trainer_config_helpers
as
conf_helps
import
paddle.trainer_config_helpers
as
conf_helps
import
layer
as
v2_layer
from
paddle.proto.ModelConfig_pb2
import
ModelConfig
import
data_type
import
data_type
import
layer
as
v2_layer
__all__
=
[
'Topology'
]
__all__
=
[
'Topology'
]
...
@@ -26,11 +29,12 @@ class Topology(object):
...
@@ -26,11 +29,12 @@ class Topology(object):
and network configs.
and network configs.
"""
"""
def
__init__
(
self
,
*
layers
):
def
__init__
(
self
,
layers
):
if
not
isinstance
(
layers
,
collections
.
Sequence
):
raise
ValueError
(
"input of Topology should be a list of Layer"
)
for
layer
in
layers
:
for
layer
in
layers
:
if
not
isinstance
(
layer
,
v2_layer
.
LayerV2
):
if
not
isinstance
(
layer
,
v2_layer
.
LayerV2
):
raise
ValueError
(
'create must pass a topologies '
raise
ValueError
(
'layer should have type paddle.layer.Layer'
)
'which type is paddle.layer.Layer'
)
self
.
layers
=
layers
self
.
layers
=
layers
self
.
__model_config__
=
v2_layer
.
parse_network
(
*
layers
)
self
.
__model_config__
=
v2_layer
.
parse_network
(
*
layers
)
assert
isinstance
(
self
.
__model_config__
,
ModelConfig
)
assert
isinstance
(
self
.
__model_config__
,
ModelConfig
)
...
...
python/paddle/v2/trainer.py
浏览文件 @
b9dd33f8
...
@@ -73,7 +73,7 @@ class SGD(ITrainer):
...
@@ -73,7 +73,7 @@ class SGD(ITrainer):
Training method. Will train num_passes of input data.
Training method. Will train num_passes of input data.
:param train_data_reader:
:param train_data_reader:
:param topology:
Network Topology
, use one or more Layers to represent it.
:param topology:
cost layers
, use one or more Layers to represent it.
:param parameters: The parameter pools.
:param parameters: The parameter pools.
:param num_passes: The total train passes.
:param num_passes: The total train passes.
:param test_data_reader:
:param test_data_reader:
...
@@ -87,6 +87,8 @@ class SGD(ITrainer):
...
@@ -87,6 +87,8 @@ class SGD(ITrainer):
if
event_handler
is
None
:
if
event_handler
is
None
:
event_handler
=
default_event_handler
event_handler
=
default_event_handler
topology
=
v2_topology
.
Topology
(
topology
)
__check_train_args__
(
**
locals
())
__check_train_args__
(
**
locals
())
gm
=
api
.
GradientMachine
.
createFromConfigProto
(
gm
=
api
.
GradientMachine
.
createFromConfigProto
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录