Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
c6720990
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看板
未验证
提交
c6720990
编写于
4月 08, 2019
作者:
Y
Yan Xu
提交者:
GitHub
4月 08, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix seresnext unit test (#16689)
comment np.array(x.get_tensor()) in imperaitve mode to avoid OOM.
上级
169829c8
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
90 addition
and
81 deletion
+90
-81
python/paddle/fluid/tests/unittests/test_imperative_se_resnext.py
...addle/fluid/tests/unittests/test_imperative_se_resnext.py
+90
-81
未找到文件。
python/paddle/fluid/tests/unittests/test_imperative_se_resnext.py
浏览文件 @
c6720990
...
@@ -56,7 +56,7 @@ def optimizer_setting(params):
...
@@ -56,7 +56,7 @@ def optimizer_setting(params):
#bd = [step * e for e in ls["epochs"]]
#bd = [step * e for e in ls["epochs"]]
#base_lr = params["lr"]
#base_lr = params["lr"]
#lr = [base_lr * (0.1**i) for i in range(len(bd) + 1)]
#lr = [base_lr * (0.1**i) for i in range(len(bd) + 1)]
optimizer
=
fluid
.
optimizer
.
SGD
(
learning_rate
=
0.1
)
optimizer
=
fluid
.
optimizer
.
SGD
(
learning_rate
=
0.
0
1
)
return
optimizer
return
optimizer
...
@@ -109,7 +109,7 @@ class SqueezeExcitation(fluid.dygraph.Layer):
...
@@ -109,7 +109,7 @@ class SqueezeExcitation(fluid.dygraph.Layer):
size
=
num_channels
,
size
=
num_channels
,
param_attr
=
fluid
.
ParamAttr
(
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Constant
(
value
=
0.05
)),
initializer
=
fluid
.
initializer
.
Constant
(
value
=
0.05
)),
act
=
'
relu
'
)
act
=
'
sigmoid
'
)
def
forward
(
self
,
input
):
def
forward
(
self
,
input
):
y
=
self
.
_pool
(
input
)
y
=
self
.
_pool
(
input
)
...
@@ -316,6 +316,7 @@ class TestImperativeResneXt(unittest.TestCase):
...
@@ -316,6 +316,7 @@ class TestImperativeResneXt(unittest.TestCase):
batch_size
=
train_parameters
[
"batch_size"
]
batch_size
=
train_parameters
[
"batch_size"
]
batch_num
=
2
batch_num
=
2
epoch_num
=
1
with
fluid
.
dygraph
.
guard
():
with
fluid
.
dygraph
.
guard
():
fluid
.
default_startup_program
().
random_seed
=
seed
fluid
.
default_startup_program
().
random_seed
=
seed
fluid
.
default_main_program
().
random_seed
=
seed
fluid
.
default_main_program
().
random_seed
=
seed
...
@@ -327,19 +328,23 @@ class TestImperativeResneXt(unittest.TestCase):
...
@@ -327,19 +328,23 @@ class TestImperativeResneXt(unittest.TestCase):
random
.
seed
=
seed
random
.
seed
=
seed
train_reader
=
paddle
.
batch
(
train_reader
=
paddle
.
batch
(
paddle
.
dataset
.
flowers
.
train
(
use_xmap
=
False
),
paddle
.
dataset
.
flowers
.
train
(
use_xmap
=
False
),
batch_size
=
batch_size
)
batch_size
=
batch_size
,
drop_last
=
True
)
dy_param_init_value
=
{}
dy_param_init_value
=
{}
for
param
in
se_resnext
.
parameters
():
for
param
in
se_resnext
.
parameters
():
dy_param_init_value
[
param
.
name
]
=
param
.
_numpy
()
dy_param_init_value
[
param
.
name
]
=
param
.
_numpy
()
for
epoch_id
in
range
(
epoch_num
):
for
batch_id
,
data
in
enumerate
(
train_reader
()):
for
batch_id
,
data
in
enumerate
(
train_reader
()):
if
batch_id
>=
batch_num
:
if
batch_id
>=
batch_num
and
batch_num
!=
-
1
:
break
break
dy_x_data
=
np
.
array
(
dy_x_data
=
np
.
array
(
[
x
[
0
].
reshape
(
3
,
224
,
224
)
for
x
in
data
]).
astype
(
'float32'
)
[
x
[
0
].
reshape
(
3
,
224
,
224
)
y_data
=
np
.
array
([
x
[
1
]
for
x
in
data
]).
astype
(
'int64'
).
reshape
(
for
x
in
data
]).
astype
(
'float32'
)
y_data
=
np
.
array
(
[
x
[
1
]
for
x
in
data
]).
astype
(
'int64'
).
reshape
(
batch_size
,
1
)
batch_size
,
1
)
img
=
to_variable
(
dy_x_data
)
img
=
to_variable
(
dy_x_data
)
...
@@ -356,16 +361,14 @@ class TestImperativeResneXt(unittest.TestCase):
...
@@ -356,16 +361,14 @@ class TestImperativeResneXt(unittest.TestCase):
for
param
in
se_resnext
.
parameters
():
for
param
in
se_resnext
.
parameters
():
if
param
.
name
not
in
dy_param_init_value
:
if
param
.
name
not
in
dy_param_init_value
:
dy_param_init_value
[
param
.
name
]
=
param
.
_numpy
()
dy_param_init_value
[
param
.
name
]
=
param
.
_numpy
()
avg_loss
.
_backward
()
avg_loss
.
_backward
()
dy_grad_value
=
{}
#dy_grad_value = {}
for
param
in
se_resnext
.
parameters
():
#for param in se_resnext.parameters():
if
param
.
trainable
:
# if param.trainable:
np_array
=
np
.
array
(
param
.
_ivar
.
_grad_ivar
().
value
()
# np_array = np.array(param._ivar._grad_ivar().value()
.
get_tensor
())
# .get_tensor())
dy_grad_value
[
param
.
name
+
core
.
grad_var_suffix
(
# dy_grad_value[param.name + core.grad_var_suffix()] = np_array
)]
=
np_array
optimizer
.
minimize
(
avg_loss
)
optimizer
.
minimize
(
avg_loss
)
se_resnext
.
clear_gradients
()
se_resnext
.
clear_gradients
()
...
@@ -389,7 +392,8 @@ class TestImperativeResneXt(unittest.TestCase):
...
@@ -389,7 +392,8 @@ class TestImperativeResneXt(unittest.TestCase):
random
.
seed
=
seed
random
.
seed
=
seed
train_reader
=
paddle
.
batch
(
train_reader
=
paddle
.
batch
(
paddle
.
dataset
.
flowers
.
train
(
use_xmap
=
False
),
paddle
.
dataset
.
flowers
.
train
(
use_xmap
=
False
),
batch_size
=
batch_size
)
batch_size
=
batch_size
,
drop_last
=
True
)
img
=
fluid
.
layers
.
data
(
img
=
fluid
.
layers
.
data
(
name
=
'pixel'
,
shape
=
[
3
,
224
,
224
],
dtype
=
'float32'
)
name
=
'pixel'
,
shape
=
[
3
,
224
,
224
],
dtype
=
'float32'
)
...
@@ -415,20 +419,23 @@ class TestImperativeResneXt(unittest.TestCase):
...
@@ -415,20 +419,23 @@ class TestImperativeResneXt(unittest.TestCase):
for
i
in
range
(
len
(
static_param_name_list
)):
for
i
in
range
(
len
(
static_param_name_list
)):
static_param_init_value
[
static_param_name_list
[
i
]]
=
out
[
i
]
static_param_init_value
[
static_param_name_list
[
i
]]
=
out
[
i
]
for
epoch_id
in
range
(
epoch_num
):
for
batch_id
,
data
in
enumerate
(
train_reader
()):
for
batch_id
,
data
in
enumerate
(
train_reader
()):
if
batch_id
>=
batch_num
:
if
batch_id
>=
batch_num
and
batch_num
!=
-
1
:
break
break
static_x_data
=
np
.
array
(
static_x_data
=
np
.
array
(
[
x
[
0
].
reshape
(
3
,
224
,
224
)
for
x
in
data
]).
astype
(
'float32'
)
[
x
[
0
].
reshape
(
3
,
224
,
224
)
y_data
=
np
.
array
([
x
[
1
]
for
x
in
data
]).
astype
(
'int64'
).
reshape
(
for
x
in
data
]).
astype
(
'float32'
)
y_data
=
np
.
array
(
[
x
[
1
]
for
x
in
data
]).
astype
(
'int64'
).
reshape
(
[
batch_size
,
1
])
[
batch_size
,
1
])
fetch_list
=
[
avg_loss
.
name
]
fetch_list
=
[
avg_loss
.
name
]
fetch_list
.
extend
(
static_param_name_list
)
fetch_list
.
extend
(
static_param_name_list
)
fetch_list
.
extend
(
static_grad_name_list
)
fetch_list
.
extend
(
static_grad_name_list
)
out
=
exe
.
run
(
fluid
.
default_main_program
(),
out
=
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
{
"pixel"
:
static_x_data
,
feed
=
{
"pixel"
:
static_x_data
,
"label"
:
y_data
},
"label"
:
y_data
},
fetch_list
=
fetch_list
)
fetch_list
=
fetch_list
)
...
@@ -437,8 +444,10 @@ class TestImperativeResneXt(unittest.TestCase):
...
@@ -437,8 +444,10 @@ class TestImperativeResneXt(unittest.TestCase):
static_grad_value
=
{}
static_grad_value
=
{}
static_out
=
out
[
0
]
static_out
=
out
[
0
]
param_start_pos
=
1
param_start_pos
=
1
grad_start_pos
=
len
(
static_param_name_list
)
+
param_start_pos
grad_start_pos
=
len
(
for
i
in
range
(
param_start_pos
,
static_param_name_list
)
+
param_start_pos
for
i
in
range
(
param_start_pos
,
len
(
static_param_name_list
)
+
param_start_pos
):
len
(
static_param_name_list
)
+
param_start_pos
):
static_param_value
[
static_param_name_list
[
static_param_value
[
static_param_name_list
[
i
-
param_start_pos
]]
=
out
[
i
]
i
-
param_start_pos
]]
=
out
[
i
]
...
@@ -454,12 +463,12 @@ class TestImperativeResneXt(unittest.TestCase):
...
@@ -454,12 +463,12 @@ class TestImperativeResneXt(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
value
,
dy_param_init_value
[
key
]))
self
.
assertTrue
(
np
.
allclose
(
value
,
dy_param_init_value
[
key
]))
self
.
assertTrue
(
np
.
isfinite
(
value
.
all
()))
self
.
assertTrue
(
np
.
isfinite
(
value
.
all
()))
self
.
assertFalse
(
np
.
isnan
(
value
.
any
()))
self
.
assertFalse
(
np
.
isnan
(
value
.
any
()))
# FIXME(Yancey1989): np.array(_ivar.value().get_tensor()) leads to memory lake
self
.
assertEqual
(
len
(
dy_grad_value
),
len
(
static_grad_value
))
#
self.assertEqual(len(dy_grad_value), len(static_grad_value))
for
key
,
value
in
six
.
iteritems
(
static_grad_value
):
#
for key, value in six.iteritems(static_grad_value):
self
.
assertTrue
(
np
.
allclose
(
value
,
dy_grad_value
[
key
]))
#
self.assertTrue(np.allclose(value, dy_grad_value[key]))
self
.
assertTrue
(
np
.
isfinite
(
value
.
all
()))
#
self.assertTrue(np.isfinite(value.all()))
self
.
assertFalse
(
np
.
isnan
(
value
.
any
()))
#
self.assertFalse(np.isnan(value.any()))
self
.
assertEqual
(
len
(
dy_param_value
),
len
(
static_param_value
))
self
.
assertEqual
(
len
(
dy_param_value
),
len
(
static_param_value
))
for
key
,
value
in
six
.
iteritems
(
static_param_value
):
for
key
,
value
in
six
.
iteritems
(
static_param_value
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录