Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
7afd7d4b
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
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):
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
):
def
__init__
(
self
,
mode
,
return_label
=
True
,
sample_num
=
None
):
super
(
MnistDataset
,
self
).
__init__
(
mode
=
mode
)
...
...
@@ -577,32 +549,34 @@ class TestModelFunction(unittest.TestCase):
shutil
.
rmtree
(
save_dir
)
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'
)
paddle
.
disable_static
()
for
initial
in
[
"fit"
,
"train_batch"
,
"eval_batch"
,
"test_batch"
]:
save_dir
=
tempfile
.
mkdtemp
()
if
not
os
.
path
.
exists
(
save_dir
):
os
.
makedirs
(
save_dir
)
net
=
LeNet
()
model
=
Model
(
net
)
model
.
prepare
(
optimizer
=
optim
,
loss
=
CrossEntropyLoss
(
reduction
=
"sum"
))
if
initial
==
"fit"
:
model
.
fit
(
mnist_data
,
batch_size
=
64
,
verbose
=
0
)
net
=
LeNet
()
model
=
Model
(
net
)
optim
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
0.001
,
parameter_list
=
model
.
parameters
())
model
.
prepare
(
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
:
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
:
model
.
test_batch
([
img
])
model
.
save
(
save_dir
,
training
=
False
)
shutil
.
rmtree
(
save_dir
)
model
.
test_batch
([
img
])
model
.
save
(
save_dir
,
training
=
False
)
shutil
.
rmtree
(
save_dir
)
class
TestRaiseError
(
unittest
.
TestCase
):
...
...
@@ -614,7 +588,7 @@ class TestRaiseError(unittest.TestCase):
with
self
.
assertRaises
(
ValueError
):
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
()
net
=
MyModel
()
save_dir
=
tempfile
.
mkdtemp
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录