Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
7afd7d4b
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
提交
7afd7d4b
编写于
9月 27, 2020
作者:
L
LiuChiaChi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix unittests bugs
上级
cc71c7b9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
22 addition
and
48 deletion
+22
-48
python/paddle/tests/test_model.py
python/paddle/tests/test_model.py
+22
-48
未找到文件。
python/paddle/tests/test_model.py
浏览文件 @
7afd7d4b
...
@@ -66,34 +66,6 @@ class LeNetDygraph(paddle.nn.Layer):
...
@@ -66,34 +66,6 @@ class LeNetDygraph(paddle.nn.Layer):
return
x
return
x
class
LeNetDeclarative
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
num_classes
=
10
):
super
(
LeNetDeclarative
,
self
).
__init__
()
self
.
num_classes
=
num_classes
self
.
features
=
Sequential
(
Conv2d
(
1
,
6
,
3
,
stride
=
1
,
padding
=
1
),
ReLU
(),
Pool2D
(
2
,
'max'
,
2
),
Conv2d
(
6
,
16
,
5
,
stride
=
1
,
padding
=
0
),
ReLU
(),
Pool2D
(
2
,
'max'
,
2
))
if
num_classes
>
0
:
self
.
fc
=
Sequential
(
Linear
(
400
,
120
),
Linear
(
120
,
84
),
Linear
(
84
,
10
))
@
declarative
def
forward
(
self
,
inputs
):
x
=
self
.
features
(
inputs
)
if
self
.
num_classes
>
0
:
x
=
fluid
.
layers
.
flatten
(
x
,
1
)
x
=
self
.
fc
(
x
)
return
x
class
MnistDataset
(
MNIST
):
class
MnistDataset
(
MNIST
):
def
__init__
(
self
,
mode
,
return_label
=
True
,
sample_num
=
None
):
def
__init__
(
self
,
mode
,
return_label
=
True
,
sample_num
=
None
):
super
(
MnistDataset
,
self
).
__init__
(
mode
=
mode
)
super
(
MnistDataset
,
self
).
__init__
(
mode
=
mode
)
...
@@ -577,32 +549,34 @@ class TestModelFunction(unittest.TestCase):
...
@@ -577,32 +549,34 @@ class TestModelFunction(unittest.TestCase):
shutil
.
rmtree
(
save_dir
)
shutil
.
rmtree
(
save_dir
)
paddle
.
enable_static
()
paddle
.
enable_static
()
def
test_
export_deploy_model_without_inputs_in_dygraph
(
self
):
def
test_
dygraph_export_deploy_model_without_inputs
(
self
):
mnist_data
=
MnistDataset
(
mode
=
'train'
)
mnist_data
=
MnistDataset
(
mode
=
'train'
)
paddle
.
disable_static
()
paddle
.
disable_static
()
for
initial
in
[
"fit"
,
"train_batch"
,
"eval_batch"
,
"test_batch"
]:
for
initial
in
[
"fit"
,
"train_batch"
,
"eval_batch"
,
"test_batch"
]:
save_dir
=
tempfile
.
mkdtemp
()
save_dir
=
tempfile
.
mkdtemp
()
if
not
os
.
path
.
exists
(
save_dir
):
if
not
os
.
path
.
exists
(
save_dir
):
os
.
makedirs
(
save_dir
)
os
.
makedirs
(
save_dir
)
net
=
LeNet
()
net
=
LeNet
()
model
=
Model
(
net
)
model
=
Model
(
net
)
model
.
prepare
(
optim
=
fluid
.
optimizer
.
Adam
(
optimizer
=
optim
,
loss
=
CrossEntropyLoss
(
reduction
=
"sum"
))
learning_rate
=
0.001
,
parameter_list
=
model
.
parameters
())
if
initial
==
"fit"
:
model
.
prepare
(
model
.
fit
(
mnist_data
,
batch_size
=
64
,
verbose
=
0
)
optimizer
=
optim
,
loss
=
CrossEntropyLoss
(
reduction
=
"sum"
))
if
initial
==
"fit"
:
model
.
fit
(
mnist_data
,
batch_size
=
64
,
verbose
=
0
)
else
:
img
=
np
.
array
(
np
.
random
.
random
((
1
,
1
,
28
,
28
)),
dtype
=
np
.
float32
)
label
=
np
.
array
(
np
.
random
.
rand
(
1
,
1
),
dtype
=
np
.
int64
)
if
initial
==
"train_batch"
:
model
.
train_batch
([
img
],
[
label
])
elif
initial
==
"eval_batch"
:
model
.
eval_batch
([
img
],
[
label
])
else
:
else
:
img
=
np
.
array
(
model
.
test_batch
([
img
])
np
.
random
.
random
((
1
,
1
,
28
,
28
)),
dtype
=
np
.
float32
)
label
=
np
.
array
(
np
.
random
.
rand
(
1
,
1
),
dtype
=
np
.
int64
)
model
.
save
(
save_dir
,
training
=
False
)
if
initial
==
"train_batch"
:
shutil
.
rmtree
(
save_dir
)
model
.
train_batch
([
img
],
[
label
])
elif
initial
==
"eval_batch"
:
model
.
eval_batch
([
img
],
[
label
])
else
:
model
.
test_batch
([
img
])
model
.
save
(
save_dir
,
training
=
False
)
shutil
.
rmtree
(
save_dir
)
class
TestRaiseError
(
unittest
.
TestCase
):
class
TestRaiseError
(
unittest
.
TestCase
):
...
@@ -614,7 +588,7 @@ class TestRaiseError(unittest.TestCase):
...
@@ -614,7 +588,7 @@ class TestRaiseError(unittest.TestCase):
with
self
.
assertRaises
(
ValueError
):
with
self
.
assertRaises
(
ValueError
):
model
=
Model
(
net
,
inputs
,
labels
)
model
=
Model
(
net
,
inputs
,
labels
)
def
test_
export_deploy
_model_without_inputs_and_run_in_dygraph
(
self
):
def
test_
save_infer
_model_without_inputs_and_run_in_dygraph
(
self
):
paddle
.
disable_static
()
paddle
.
disable_static
()
net
=
MyModel
()
net
=
MyModel
()
save_dir
=
tempfile
.
mkdtemp
()
save_dir
=
tempfile
.
mkdtemp
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录