Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
b9dd33f8
P
Paddle
项目概览
Crayon鑫
/
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看板
提交
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():
act
=
paddle
.
activation
.
Softmax
())
cost
=
paddle
.
layer
.
classification_cost
(
input
=
inference
,
label
=
label
)
topology
=
paddle
.
topology
.
Topology
(
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
)
...
...
@@ -49,7 +47,7 @@ def main():
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
浏览文件 @
b9dd33f8
...
...
@@ -7,15 +7,13 @@ import topology as v2_topology
__all__
=
[
'Parameters'
,
'create'
]
def
create
(
topology
):
def
create
(
layers
):
"""
Create parameter pool by topology.
:param
topology
:
:param
layers
:
:return:
"""
if
not
isinstance
(
topology
,
v2_topology
.
Topology
):
raise
ValueError
(
'create must pass a topology which type is topology.Topology'
)
topology
=
v2_topology
.
Topology
(
layers
)
pool
=
Parameters
()
for
param
in
topology
.
proto
().
parameters
:
pool
.
__append_config__
(
param
)
...
...
python/paddle/v2/topology.py
浏览文件 @
b9dd33f8
...
...
@@ -12,10 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from
paddle.proto.ModelConfig_pb2
import
ModelConfig
import
collections
import
paddle.trainer_config_helpers
as
conf_helps
import
layer
as
v2_layer
from
paddle.proto.ModelConfig_pb2
import
ModelConfig
import
data_type
import
layer
as
v2_layer
__all__
=
[
'Topology'
]
...
...
@@ -26,11 +29,12 @@ class Topology(object):
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
:
if
not
isinstance
(
layer
,
v2_layer
.
LayerV2
):
raise
ValueError
(
'create must pass a topologies '
'which type is paddle.layer.Layer'
)
raise
ValueError
(
'layer should have type paddle.layer.Layer'
)
self
.
layers
=
layers
self
.
__model_config__
=
v2_layer
.
parse_network
(
*
layers
)
assert
isinstance
(
self
.
__model_config__
,
ModelConfig
)
...
...
python/paddle/v2/trainer.py
浏览文件 @
b9dd33f8
...
...
@@ -73,7 +73,7 @@ class SGD(ITrainer):
Training method. Will train num_passes of input data.
: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 num_passes: The total train passes.
:param test_data_reader:
...
...
@@ -87,6 +87,8 @@ class SGD(ITrainer):
if
event_handler
is
None
:
event_handler
=
default_event_handler
topology
=
v2_topology
.
Topology
(
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录