Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
43ac17b2
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看板
未验证
提交
43ac17b2
编写于
1月 07, 2020
作者:
W
whs
提交者:
GitHub
1月 07, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix sensitive API. (#30)
上级
d1f3229b
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
21 addition
and
15 deletion
+21
-15
paddleslim/prune/pruner.py
paddleslim/prune/pruner.py
+21
-15
未找到文件。
paddleslim/prune/pruner.py
浏览文件 @
43ac17b2
...
@@ -81,7 +81,8 @@ class Pruner():
...
@@ -81,7 +81,8 @@ class Pruner():
pruned_idx
=
self
.
_cal_pruned_idx
(
param_t
,
ratio
,
axis
=
0
)
pruned_idx
=
self
.
_cal_pruned_idx
(
param_t
,
ratio
,
axis
=
0
)
param
=
graph
.
var
(
param
)
param
=
graph
.
var
(
param
)
conv_op
=
param
.
outputs
()[
0
]
conv_op
=
param
.
outputs
()[
0
]
walker
=
conv2d_walker
(
conv_op
,
pruned_params
=
pruned_params
,
visited
=
visited
)
walker
=
conv2d_walker
(
conv_op
,
pruned_params
=
pruned_params
,
visited
=
visited
)
walker
.
prune
(
param
,
pruned_axis
=
0
,
pruned_idx
=
pruned_idx
)
walker
.
prune
(
param
,
pruned_axis
=
0
,
pruned_idx
=
pruned_idx
)
merge_pruned_params
=
{}
merge_pruned_params
=
{}
...
@@ -94,9 +95,12 @@ class Pruner():
...
@@ -94,9 +95,12 @@ class Pruner():
for
param_name
in
merge_pruned_params
:
for
param_name
in
merge_pruned_params
:
for
pruned_axis
in
merge_pruned_params
[
param_name
]:
for
pruned_axis
in
merge_pruned_params
[
param_name
]:
pruned_idx
=
np
.
concatenate
(
merge_pruned_params
[
param_name
][
pruned_axis
])
pruned_idx
=
np
.
concatenate
(
merge_pruned_params
[
param_name
][
pruned_axis
])
param
=
graph
.
var
(
param_name
)
param
=
graph
.
var
(
param_name
)
_logger
.
debug
(
"{}
\t
{}
\t
{}"
.
format
(
param
.
name
(),
pruned_axis
,
len
(
pruned_idx
)))
if
not
lazy
:
_logger
.
debug
(
"{}
\t
{}
\t
{}"
.
format
(
param
.
name
(
),
pruned_axis
,
len
(
pruned_idx
)))
if
param_shape_backup
is
not
None
:
if
param_shape_backup
is
not
None
:
origin_shape
=
copy
.
deepcopy
(
param
.
shape
())
origin_shape
=
copy
.
deepcopy
(
param
.
shape
())
param_shape_backup
[
param
.
name
()]
=
origin_shape
param_shape_backup
[
param
.
name
()]
=
origin_shape
...
@@ -105,8 +109,10 @@ class Pruner():
...
@@ -105,8 +109,10 @@ class Pruner():
param
.
set_shape
(
new_shape
)
param
.
set_shape
(
new_shape
)
if
not
only_graph
:
if
not
only_graph
:
param_t
=
scope
.
find_var
(
param
.
name
()).
get_tensor
()
param_t
=
scope
.
find_var
(
param
.
name
()).
get_tensor
()
if
param_backup
is
not
None
and
(
param
.
name
()
not
in
param_backup
):
if
param_backup
is
not
None
and
(
param_backup
[
param
.
name
()]
=
copy
.
deepcopy
(
np
.
array
(
param_t
))
param
.
name
()
not
in
param_backup
):
param_backup
[
param
.
name
()]
=
copy
.
deepcopy
(
np
.
array
(
param_t
))
try
:
try
:
pruned_param
=
self
.
_prune_tensor
(
pruned_param
=
self
.
_prune_tensor
(
np
.
array
(
param_t
),
np
.
array
(
param_t
),
...
@@ -114,11 +120,11 @@ class Pruner():
...
@@ -114,11 +120,11 @@ class Pruner():
pruned_axis
=
pruned_axis
,
pruned_axis
=
pruned_axis
,
lazy
=
lazy
)
lazy
=
lazy
)
except
IndexError
as
e
:
except
IndexError
as
e
:
_logger
.
error
(
"Pruning {}, but get [{}]"
.
format
(
param
.
name
(
_logger
.
error
(
"Pruning {}, but get [{}]"
.
format
(
),
e
))
param
.
name
(
),
e
))
param_t
.
set
(
pruned_param
,
place
)
param_t
.
set
(
pruned_param
,
place
)
graph
.
update_groups_of_conv
()
return
graph
.
program
,
param_backup
,
param_shape_backup
return
graph
.
program
,
param_backup
,
param_shape_backup
def
_cal_pruned_idx
(
self
,
param
,
ratio
,
axis
):
def
_cal_pruned_idx
(
self
,
param
,
ratio
,
axis
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录