Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
5c162fe6
P
Paddle
项目概览
机器未来
/
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看板
未验证
提交
5c162fe6
编写于
12月 28, 2020
作者:
L
littletomatodonkey
提交者:
GitHub
12月 28, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix reg api ut fail (#29921)
上级
a4b9daf9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
16 addition
and
13 deletion
+16
-13
python/paddle/fluid/tests/unittests/test_regularizer.py
python/paddle/fluid/tests/unittests/test_regularizer.py
+8
-7
python/paddle/fluid/tests/unittests/test_regularizer_api.py
python/paddle/fluid/tests/unittests/test_regularizer_api.py
+8
-6
未找到文件。
python/paddle/fluid/tests/unittests/test_regularizer.py
浏览文件 @
5c162fe6
...
...
@@ -18,6 +18,7 @@ import unittest
from
functools
import
partial
import
contextlib
import
numpy
as
np
import
random
import
paddle
import
paddle.fluid.core
as
core
import
paddle.fluid
as
fluid
...
...
@@ -29,6 +30,7 @@ from paddle.fluid.backward import append_backward
class
TestL2DecayRegularizer
(
unittest
.
TestCase
):
def
test_l2decay_regularizer
(
self
):
paddle
.
enable_static
()
program
=
framework
.
Program
()
block
=
program
.
global_block
()
mul_x
=
block
.
create_parameter
(
...
...
@@ -66,6 +68,7 @@ class TestL2DecayRegularizer(unittest.TestCase):
class
TestL1DecayRegularizer
(
unittest
.
TestCase
):
def
test_l2decay_regularizer
(
self
):
paddle
.
enable_static
()
program
=
framework
.
Program
()
block
=
program
.
global_block
()
mul_x
=
block
.
create_parameter
(
...
...
@@ -124,16 +127,14 @@ def bow_net(data,
prediction
=
fluid
.
layers
.
fc
(
input
=
[
fc_2
],
size
=
class_dim
,
act
=
"softmax"
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
prediction
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
cost
)
return
avg_cost
class
TestRegularizer
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
word_dict
=
paddle
.
dataset
.
imdb
.
word_dict
()
reader
=
paddle
.
batch
(
paddle
.
dataset
.
imdb
.
train
(
self
.
word_dict
),
batch_size
=
1
)()
self
.
train_data
=
[
next
(
reader
)
for
_
in
range
(
1
)]
self
.
word_len
=
1500
self
.
train_data
=
[[(
random
.
sample
(
range
(
1000
),
10
),
[
0
])]
for
_
in
range
(
2
)]
def
get_places
(
self
):
places
=
[
core
.
CPUPlace
()]
...
...
@@ -179,7 +180,7 @@ class TestRegularizer(unittest.TestCase):
name
=
"words"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
1
],
dtype
=
"int64"
)
avg_cost
=
model
(
data
,
label
,
len
(
self
.
word_dict
)
)
avg_cost
=
model
(
data
,
label
,
self
.
word_len
)
optimizer
=
fluid
.
optimizer
.
Adagrad
(
learning_rate
=
0.1
,
...
...
@@ -200,7 +201,7 @@ class TestRegularizer(unittest.TestCase):
name
=
"words"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
1
],
dtype
=
"int64"
)
avg_cost_l2
=
model
(
data
,
label
,
len
(
self
.
word_dict
)
)
avg_cost_l2
=
model
(
data
,
label
,
self
.
word_len
)
param_list
=
fluid
.
default_main_program
().
block
(
0
).
all_parameters
()
para_sum
=
[]
...
...
python/paddle/fluid/tests/unittests/test_regularizer_api.py
浏览文件 @
5c162fe6
...
...
@@ -18,6 +18,7 @@ import unittest
from
functools
import
partial
import
contextlib
import
numpy
as
np
import
random
import
paddle
import
paddle.fluid.core
as
core
import
paddle.fluid
as
fluid
...
...
@@ -55,10 +56,9 @@ def bow_net(data,
class
TestRegularizer
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
word_dict
=
paddle
.
dataset
.
imdb
.
word_dict
()
reader
=
paddle
.
batch
(
paddle
.
dataset
.
imdb
.
train
(
self
.
word_dict
),
batch_size
=
1
)()
self
.
train_data
=
[
next
(
reader
)
for
_
in
range
(
1
)]
self
.
word_len
=
1500
self
.
train_data
=
[[(
random
.
sample
(
range
(
1000
),
10
),
[
0
])]
for
_
in
range
(
2
)]
def
get_places
(
self
):
places
=
[
core
.
CPUPlace
()]
...
...
@@ -104,7 +104,7 @@ class TestRegularizer(unittest.TestCase):
name
=
"words"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
1
],
dtype
=
"int64"
)
avg_cost
=
model
(
data
,
label
,
len
(
self
.
word_dict
)
)
avg_cost
=
model
(
data
,
label
,
self
.
word_len
)
optimizer
=
fluid
.
optimizer
.
Adagrad
(
learning_rate
=
0.1
,
...
...
@@ -125,7 +125,7 @@ class TestRegularizer(unittest.TestCase):
name
=
"words"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
1
],
dtype
=
"int64"
)
avg_cost_l2
=
model
(
data
,
label
,
len
(
self
.
word_dict
)
)
avg_cost_l2
=
model
(
data
,
label
,
self
.
word_len
)
param_list
=
fluid
.
default_main_program
().
block
(
0
).
all_parameters
()
para_sum
=
[]
...
...
@@ -140,6 +140,7 @@ class TestRegularizer(unittest.TestCase):
return
param_sum
def
test_l2
(
self
):
paddle
.
enable_static
()
for
place
in
self
.
get_places
():
dense_sparse_p_sum
=
[]
for
sparse
in
[
True
,
False
]:
...
...
@@ -159,6 +160,7 @@ class TestRegularizer(unittest.TestCase):
rtol
=
5e-5
)
def
test_repeated_regularization
(
self
):
paddle
.
enable_static
()
l1
=
paddle
.
regularizer
.
L1Decay
(
0.1
)
l2
=
paddle
.
regularizer
.
L2Decay
(
0.01
)
fc_param_attr
=
fluid
.
ParamAttr
(
regularizer
=
l1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录