Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleOCR
提交
9dba4a12
P
PaddleOCR
项目概览
PaddlePaddle
/
PaddleOCR
大约 1 年 前同步成功
通知
1528
Star
32962
Fork
6643
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
108
列表
看板
标记
里程碑
合并请求
7
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
108
Issue
108
列表
看板
标记
里程碑
合并请求
7
合并请求
7
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9dba4a12
编写于
9月 26, 2021
作者:
L
LDOUBLEV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimize the prune
上级
e2ed89fa
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
20 deletion
+37
-20
deploy/slim/prune/sensitivity_anal.py
deploy/slim/prune/sensitivity_anal.py
+36
-19
tools/program.py
tools/program.py
+1
-1
未找到文件。
deploy/slim/prune/sensitivity_anal.py
浏览文件 @
9dba4a12
...
...
@@ -110,25 +110,42 @@ def main(config, device, logger, vdl_writer):
logger
.
info
(
"metric['hmean']: {}"
.
format
(
metric
[
'hmean'
]))
return
metric
[
'hmean'
]
params_sensitive
=
pruner
.
sensitive
(
eval_func
=
eval_fn
,
sen_file
=
"./sen.pickle"
,
skip_vars
=
[
"conv2d_57.w_0"
,
"conv2d_transpose_2.w_0"
,
"conv2d_transpose_3.w_0"
])
logger
.
info
(
"The sensitivity analysis results of model parameters saved in sen.pickle"
)
# calculate pruned params's ratio
params_sensitive
=
pruner
.
_get_ratios_by_loss
(
params_sensitive
,
loss
=
0.02
)
for
key
in
params_sensitive
.
keys
():
logger
.
info
(
"{}, {}"
.
format
(
key
,
params_sensitive
[
key
]))
#params_sensitive = {}
#for param in model.parameters():
# if 'transpose' not in param.name and 'linear' not in param.name:
# params_sensitive[param.name] = 0.1
run_sensitive_analysis
=
False
"""
run_sensitive_analysis=True:
Automatically compute the sensitivities of convolutions in a model.
The sensitivity of a convolution is the losses of accuracy on test dataset in
differenct pruned ratios. The sensitivities can be used to get a group of best
ratios with some condition.
run_sensitive_analysis=False:
Set prune trim ratio to a fixed value, such as 10%. The larger the value,
the more convolution weights will be cropped.
"""
if
run_sensitive_analysis
:
params_sensitive
=
pruner
.
sensitive
(
eval_func
=
eval_fn
,
sen_file
=
"./deploy/slim/prune/sen.pickle"
,
skip_vars
=
[
"conv2d_57.w_0"
,
"conv2d_transpose_2.w_0"
,
"conv2d_transpose_3.w_0"
])
logger
.
info
(
"The sensitivity analysis results of model parameters saved in sen.pickle"
)
# calculate pruned params's ratio
params_sensitive
=
pruner
.
_get_ratios_by_loss
(
params_sensitive
,
loss
=
0.02
)
for
key
in
params_sensitive
.
keys
():
logger
.
info
(
"{}, {}"
.
format
(
key
,
params_sensitive
[
key
]))
else
:
params_sensitive
=
{}
for
param
in
model
.
parameters
():
if
'transpose'
not
in
param
.
name
and
'linear'
not
in
param
.
name
:
# set prune ratio as 10%. The larger the value, the more convolution weights will be cropped
params_sensitive
[
param
.
name
]
=
0.1
plan
=
pruner
.
prune_vars
(
params_sensitive
,
[
0
])
...
...
tools/program.py
浏览文件 @
9dba4a12
...
...
@@ -351,7 +351,7 @@ def eval(model,
valid_dataloader
,
post_process_class
,
eval_class
,
model_type
,
model_type
=
None
,
use_srn
=
False
,
use_sar
=
False
):
model
.
eval
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录