Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
5906baa3
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
5906baa3
编写于
10月 27, 2017
作者:
A
Abhinav Arora
提交者:
GitHub
10月 27, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adding L2 Regularization to Recognize digits MLP example (#5186)
上级
79c5a461
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
24 addition
and
9 deletion
+24
-9
python/paddle/v2/framework/layer_helper.py
python/paddle/v2/framework/layer_helper.py
+6
-4
python/paddle/v2/framework/tests/test_recognize_digits_mlp.py
...on/paddle/v2/framework/tests/test_recognize_digits_mlp.py
+18
-5
未找到文件。
python/paddle/v2/framework/layer_helper.py
浏览文件 @
5906baa3
...
@@ -131,12 +131,14 @@ class LayerHelper(object):
...
@@ -131,12 +131,14 @@ class LayerHelper(object):
return
dtype
return
dtype
def
create_parameter
(
self
,
attr
,
shape
,
dtype
,
suffix
=
'w'
):
def
create_parameter
(
self
,
attr
,
shape
,
dtype
,
suffix
=
'w'
):
if
attr
[
'name'
]
is
None
:
# Deepcopy the attr so that parameters can be shared in program
attr
[
'name'
]
=
unique_name
(
"."
.
join
([
self
.
name
,
suffix
]))
attr_copy
=
copy
.
deepcopy
(
attr
)
if
attr_copy
[
'name'
]
is
None
:
attr_copy
[
'name'
]
=
unique_name
(
"."
.
join
([
self
.
name
,
suffix
]))
self
.
init_program
.
global_block
().
create_parameter
(
self
.
init_program
.
global_block
().
create_parameter
(
dtype
=
dtype
,
shape
=
shape
,
**
attr
)
dtype
=
dtype
,
shape
=
shape
,
**
attr
_copy
)
return
self
.
program
.
global_block
().
create_parameter
(
return
self
.
program
.
global_block
().
create_parameter
(
name
=
attr
[
'name'
],
dtype
=
dtype
,
shape
=
shape
)
name
=
attr
_copy
[
'name'
],
dtype
=
dtype
,
shape
=
shape
)
def
create_tmp_variable
(
self
,
dtype
):
def
create_tmp_variable
(
self
,
dtype
):
return
self
.
program
.
current_block
().
create_var
(
return
self
.
program
.
current_block
().
create_var
(
...
...
python/paddle/v2/framework/tests/test_recognize_digits_mlp.py
浏览文件 @
5906baa3
...
@@ -5,9 +5,11 @@ import paddle.v2.framework.optimizer as optimizer
...
@@ -5,9 +5,11 @@ import paddle.v2.framework.optimizer as optimizer
from
paddle.v2.framework.framework
import
Program
,
g_program
from
paddle.v2.framework.framework
import
Program
,
g_program
from
paddle.v2.framework.executor
import
Executor
from
paddle.v2.framework.executor
import
Executor
from
paddle.v2.framework.regularizer
import
L2DecayRegularizer
import
numpy
as
np
import
numpy
as
np
BATCH_SIZE
=
128
init_program
=
Program
()
init_program
=
Program
()
program
=
Program
()
program
=
Program
()
image
=
layers
.
data
(
image
=
layers
.
data
(
...
@@ -17,22 +19,35 @@ image = layers.data(
...
@@ -17,22 +19,35 @@ image = layers.data(
program
=
program
,
program
=
program
,
init_program
=
init_program
)
init_program
=
init_program
)
param_attr
=
{
'name'
:
None
,
'init_attr'
:
{
'type'
:
'uniform_random'
,
'min'
:
-
1.0
,
'max'
:
1.0
},
'regularization'
:
L2DecayRegularizer
(
0.0005
*
BATCH_SIZE
)
}
hidden1
=
layers
.
fc
(
input
=
image
,
hidden1
=
layers
.
fc
(
input
=
image
,
size
=
128
,
size
=
128
,
act
=
'relu'
,
act
=
'relu'
,
program
=
program
,
program
=
program
,
init_program
=
init_program
)
init_program
=
init_program
,
param_attr
=
param_attr
)
hidden2
=
layers
.
fc
(
input
=
hidden1
,
hidden2
=
layers
.
fc
(
input
=
hidden1
,
size
=
64
,
size
=
64
,
act
=
'relu'
,
act
=
'relu'
,
program
=
program
,
program
=
program
,
init_program
=
init_program
)
init_program
=
init_program
,
param_attr
=
param_attr
)
predict
=
layers
.
fc
(
input
=
hidden2
,
predict
=
layers
.
fc
(
input
=
hidden2
,
size
=
10
,
size
=
10
,
act
=
'softmax'
,
act
=
'softmax'
,
program
=
program
,
program
=
program
,
init_program
=
init_program
)
init_program
=
init_program
,
param_attr
=
param_attr
)
label
=
layers
.
data
(
label
=
layers
.
data
(
name
=
'y'
,
name
=
'y'
,
...
@@ -48,8 +63,6 @@ avg_cost = layers.mean(x=cost, program=program, init_program=init_program)
...
@@ -48,8 +63,6 @@ avg_cost = layers.mean(x=cost, program=program, init_program=init_program)
sgd_optimizer
=
optimizer
.
SGDOptimizer
(
learning_rate
=
0.001
)
sgd_optimizer
=
optimizer
.
SGDOptimizer
(
learning_rate
=
0.001
)
opts
=
sgd_optimizer
.
minimize
(
avg_cost
)
opts
=
sgd_optimizer
.
minimize
(
avg_cost
)
BATCH_SIZE
=
128
train_reader
=
paddle
.
batch
(
train_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
mnist
.
train
(),
buf_size
=
8192
),
paddle
.
dataset
.
mnist
.
train
(),
buf_size
=
8192
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录