Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
6a161828
P
PaddleSlim
项目概览
PaddlePaddle
/
PaddleSlim
1 年多 前同步成功
通知
51
Star
1434
Fork
344
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
16
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSlim
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
16
合并请求
16
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
6a161828
编写于
6月 09, 2022
作者:
C
Chang Xu
提交者:
GitHub
6月 09, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
speedup eval in demo (#1159)
上级
a620089a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
12 addition
and
9 deletion
+12
-9
demo/auto_compression/image_classification/run.py
demo/auto_compression/image_classification/run.py
+12
-9
未找到文件。
demo/auto_compression/image_classification/run.py
浏览文件 @
6a161828
...
...
@@ -26,14 +26,15 @@ add_arg('save_dir', str, None, "directory to save
add_arg
(
'batch_size'
,
int
,
1
,
"train batch size."
)
add_arg
(
'config_path'
,
str
,
None
,
"path of compression strategy config."
)
add_arg
(
'data_dir'
,
str
,
None
,
"path of dataset"
)
add_arg
(
'input_name'
,
str
,
"inputs"
,
"input name of the model"
)
# yapf: enable
def
reader_wrapper
(
reader
):
def
reader_wrapper
(
reader
,
input_name
):
def
gen
():
for
i
,
data
in
enumerate
(
reader
()):
imgs
=
np
.
float32
([
item
[
0
]
for
item
in
data
])
yield
{
"inputs"
:
imgs
}
yield
{
input_name
:
imgs
}
return
gen
...
...
@@ -45,16 +46,17 @@ def eval_reader(data_dir, batch_size):
def
eval_function
(
exe
,
compiled_test_program
,
test_feed_names
,
test_fetch_list
):
val_reader
=
eval_reader
(
data_dir
,
batch_size
=
1
)
val_reader
=
eval_reader
(
data_dir
,
batch_size
=
args
.
batch_size
)
image
=
paddle
.
static
.
data
(
name
=
'x'
,
shape
=
[
None
,
3
,
224
,
224
],
dtype
=
'float32'
)
name
=
args
.
input_name
,
shape
=
[
None
,
3
,
224
,
224
],
dtype
=
'float32'
)
label
=
paddle
.
static
.
data
(
name
=
'label'
,
shape
=
[
None
,
1
],
dtype
=
'int64'
)
results
=
[]
for
batch_id
,
data
in
enumerate
(
val_reader
()):
# top1_acc, top5_acc
if
len
(
test_feed_names
)
==
1
:
image
=
data
[
0
][
0
].
reshape
((
1
,
3
,
224
,
224
))
image
=
np
.
array
([[
d
[
0
]]
for
d
in
data
])
image
=
image
.
reshape
((
len
(
data
),
3
,
224
,
224
))
label
=
[[
d
[
1
]]
for
d
in
data
]
pred
=
exe
.
run
(
compiled_test_program
,
feed
=
{
test_feed_names
[
0
]:
image
},
...
...
@@ -73,7 +75,8 @@ def eval_function(exe, compiled_test_program, test_feed_names, test_fetch_list):
results
.
append
([
top_1
,
top_5
])
else
:
# eval "eval model", which inputs are image and label, output is top1 and top5 accuracy
image
=
data
[
0
][
0
].
reshape
((
1
,
3
,
224
,
224
))
image
=
np
.
array
([[
d
[
0
]]
for
d
in
data
])
image
=
image
.
reshape
((
len
(
data
),
3
,
224
,
224
))
label
=
[[
d
[
1
]]
for
d
in
data
]
result
=
exe
.
run
(
compiled_test_program
,
...
...
@@ -82,7 +85,7 @@ def eval_function(exe, compiled_test_program, test_feed_names, test_fetch_list):
fetch_list
=
test_fetch_list
)
result
=
[
np
.
mean
(
r
)
for
r
in
result
]
results
.
append
(
result
)
if
batch_id
%
50
00
==
0
:
if
batch_id
%
50
==
0
:
print
(
'Eval iter: '
,
batch_id
)
result
=
np
.
mean
(
np
.
array
(
results
),
axis
=
0
)
return
result
[
0
]
...
...
@@ -97,7 +100,7 @@ if __name__ == '__main__':
train_reader
=
paddle
.
batch
(
reader
.
train
(
data_dir
=
data_dir
),
batch_size
=
args
.
batch_size
)
train_dataloader
=
reader_wrapper
(
train_reader
)
train_dataloader
=
reader_wrapper
(
train_reader
,
args
.
input_name
)
ac
=
AutoCompression
(
model_dir
=
args
.
model_dir
,
...
...
@@ -108,6 +111,6 @@ if __name__ == '__main__':
train_config
=
train_config
,
train_dataloader
=
train_dataloader
,
eval_callback
=
eval_function
,
eval_dataloader
=
reader_wrapper
(
eval_reader
(
data_dir
,
64
))
)
eval_dataloader
=
reader_wrapper
(
eval_reader
(
data_dir
,
args
.
batch_size
)),
args
.
input_name
)
ac
.
compress
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录