Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
f2c97b6d
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看板
未验证
提交
f2c97b6d
编写于
9月 24, 2020
作者:
C
Chen Weihang
提交者:
GitHub
9月 24, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
replace dataset with fake data (#27519)
上级
78a27a2b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
26 addition
and
6 deletion
+26
-6
python/paddle/fluid/contrib/tests/test_weight_decay_extend.py
...on/paddle/fluid/contrib/tests/test_weight_decay_extend.py
+26
-6
未找到文件。
python/paddle/fluid/contrib/tests/test_weight_decay_extend.py
浏览文件 @
f2c97b6d
...
...
@@ -14,6 +14,7 @@
from
__future__
import
print_function
import
six
import
unittest
from
functools
import
partial
import
numpy
as
np
...
...
@@ -24,6 +25,24 @@ import contextlib
paddle
.
enable_static
()
def
fake_imdb_reader
(
word_dict_size
,
sample_num
,
lower_seq_len
=
100
,
upper_seq_len
=
200
,
class_dim
=
2
):
def
__reader__
():
for
_
in
six
.
moves
.
range
(
sample_num
):
length
=
np
.
random
.
random_integers
(
low
=
lower_seq_len
,
high
=
upper_seq_len
,
size
=
[
1
])[
0
]
ids
=
np
.
random
.
random_integers
(
low
=
0
,
high
=
word_dict_size
-
1
,
size
=
[
length
]).
astype
(
'int64'
)
label
=
np
.
random
.
random_integers
(
low
=
0
,
high
=
class_dim
-
1
,
size
=
[
1
]).
astype
(
'int64'
)[
0
]
yield
ids
,
label
return
__reader__
def
get_places
():
places
=
[
fluid
.
CPUPlace
()]
if
fluid
.
core
.
is_compiled_with_cuda
():
...
...
@@ -68,10 +87,11 @@ def bow_net(data,
class
TestWeightDecay
(
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
=
2
)()
self
.
train_data
=
[
next
(
reader
)
for
_
in
range
(
5
)]
self
.
word_dict_len
=
5147
batch_size
=
2
reader
=
fake_imdb_reader
(
self
.
word_dict_len
,
batch_size
*
100
)
reader
=
paddle
.
batch
(
reader
,
batch_size
=
batch_size
)()
self
.
train_data
=
[
next
(
reader
)
for
_
in
range
(
3
)]
self
.
learning_rate
=
.
5
def
run_program
(
self
,
place
,
feed_list
):
...
...
@@ -103,7 +123,7 @@ class TestWeightDecay(unittest.TestCase):
data
=
fluid
.
layers
.
data
(
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_dict_len
)
AdamW
=
fluid
.
contrib
.
extend_with_decoupled_weight_decay
(
fluid
.
optimizer
.
Adam
)
...
...
@@ -127,7 +147,7 @@ class TestWeightDecay(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_dict_len
)
param_list
=
[(
var
,
var
*
self
.
learning_rate
)
for
var
in
main_prog
.
block
(
0
).
all_parameters
()]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录