Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c57954e7
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
提交
c57954e7
编写于
2月 17, 2017
作者:
Q
qiaolongfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use v2.layer in api_train_v2
上级
6dc6814f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
25 deletion
+26
-25
demo/mnist/api_train_v2.py
demo/mnist/api_train_v2.py
+18
-18
python/paddle/v2/__init__.py
python/paddle/v2/__init__.py
+3
-2
python/paddle/v2/layer.py
python/paddle/v2/layer.py
+5
-5
未找到文件。
demo/mnist/api_train_v2.py
浏览文件 @
c57954e7
from
paddle.trainer_config_helpers
import
*
from
paddle.trainer.PyDataProvider2
import
dense_vector
,
integer_value
import
paddle.v2
as
paddle
import
numpy
import
paddle.v2
as
paddle
from
paddle.trainer.PyDataProvider2
import
dense_vector
,
integer_value
import
mnist_util
...
...
@@ -12,32 +12,32 @@ def train_reader():
yield
item
def
network_config
():
imgs
=
data_layer
(
name
=
'pixel'
,
size
=
784
)
hidden1
=
fc_layer
(
input
=
imgs
,
size
=
200
)
hidden2
=
fc_layer
(
input
=
hidden1
,
size
=
200
)
inference
=
fc_layer
(
input
=
hidden2
,
size
=
10
,
act
=
SoftmaxActivation
())
cost
=
classification_cost
(
input
=
inference
,
label
=
data_layer
(
name
=
'label'
,
size
=
10
))
outputs
(
cost
)
def
main
():
paddle
.
init
(
use_gpu
=
False
,
trainer_count
=
1
)
topology
=
parse_network_config
(
network_config
)
# define network topology
images
=
paddle
.
layer
.
data
(
name
=
'pixel'
,
size
=
784
)
label
=
paddle
.
layer
.
data
(
name
=
'label'
,
size
=
10
)
hidden1
=
paddle
.
layer
.
fc
(
input
=
images
,
size
=
200
)
hidden2
=
paddle
.
layer
.
fc
(
input
=
hidden1
,
size
=
200
)
inference
=
paddle
.
layer
.
fc
(
input
=
hidden2
,
size
=
10
,
act
=
paddle
.
activation
.
Softmax
())
cost
=
paddle
.
layer
.
classification_cost
(
input
=
inference
,
label
=
label
)
topology
=
paddle
.
layer
.
parse_network
(
cost
)
print
topology
parameters
=
paddle
.
parameters
.
create
(
topology
)
for
param_name
in
parameters
.
keys
():
array
=
parameters
.
get
(
param_name
)
array
[:]
=
numpy
.
random
.
uniform
(
low
=-
1.0
,
high
=
1.0
,
size
=
array
.
shape
)
parameters
.
set
(
parameter_name
=
param_name
,
value
=
array
)
adam_optimizer
=
paddle
.
optimizer
.
Optimizer
(
learning_rate
=
0.01
,
learning_method
=
AdamOptimizer
())
adam_optimizer
=
paddle
.
optimizer
.
Adam
(
learning_rate
=
0.01
)
def
event_handler
(
event
):
if
isinstance
(
event
,
paddle
.
event
.
EndIteration
):
para
=
parameters
.
get
(
'___fc_
layer_
2__.w0'
)
para
=
parameters
.
get
(
'___fc_2__.w0'
)
print
"Pass %d, Batch %d, Cost %f, Weight Mean Of Fc 2 is %f"
%
(
event
.
pass_id
,
event
.
batch_id
,
event
.
cost
,
para
.
mean
())
...
...
python/paddle/v2/__init__.py
浏览文件 @
c57954e7
...
...
@@ -19,8 +19,9 @@ import trainer
import
event
import
py_paddle.swig_paddle
as
api
__all__
=
[
'optimizer'
,
'layer'
,
'activation'
,
'parameters'
,
'init'
,
'trainer'
,
'event'
]
__all__
=
[
'optimizer'
,
'layer'
,
'activation'
,
'parameters'
,
'init'
,
'trainer'
,
'event'
]
def
init
(
**
kwargs
):
...
...
python/paddle/v2/layer.py
浏览文件 @
c57954e7
...
...
@@ -72,6 +72,11 @@ from paddle.trainer_config_helpers.config_parser_utils import \
from
paddle.trainer_config_helpers.default_decorators
import
wrap_name_default
import
collections
__all__
=
[
'parse_network'
,
'data'
,
'fc'
,
'max_id'
,
'classification_cost'
,
'cross_entropy_cost'
]
def
parse_network
(
*
outputs
):
"""
...
...
@@ -165,11 +170,6 @@ cross_entropy_cost = __convert_to_v2__(
name_prefix
=
'cross_entropy'
,
parent_names
=
[
'input'
,
'label'
])
__all__
=
[
'parse_network'
,
'data'
,
'fc'
,
'max_id'
,
'classification_cost'
,
'cross_entropy_cost'
]
if
__name__
==
'__main__'
:
pixel
=
data
(
name
=
'pixel'
,
size
=
784
)
label
=
data
(
name
=
'label'
,
size
=
10
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录