Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
afdbc1ff
P
PaddleSlim
项目概览
PaddlePaddle
/
PaddleSlim
大约 2 年 前同步成功
通知
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看板
提交
afdbc1ff
编写于
11月 19, 2019
作者:
W
wanghaoshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update groups after pruning parameters of conv layer.
上级
72c800e9
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
12 addition
and
0 deletion
+12
-0
paddleslim/prune/pruner.py
paddleslim/prune/pruner.py
+12
-0
未找到文件。
paddleslim/prune/pruner.py
浏览文件 @
afdbc1ff
...
@@ -12,13 +12,17 @@
...
@@ -12,13 +12,17 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
import
logging
import
numpy
as
np
import
numpy
as
np
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
import
copy
import
copy
from
..core
import
VarWrapper
,
OpWrapper
,
GraphWrapper
from
..core
import
VarWrapper
,
OpWrapper
,
GraphWrapper
from
..common
import
get_logger
__all__
=
[
"Pruner"
]
__all__
=
[
"Pruner"
]
_logger
=
get_logger
(
__name__
,
level
=
logging
.
INFO
)
class
Pruner
():
class
Pruner
():
def
__init__
(
self
,
criterion
=
"l1_norm"
):
def
__init__
(
self
,
criterion
=
"l1_norm"
):
...
@@ -69,6 +73,10 @@ class Pruner():
...
@@ -69,6 +73,10 @@ class Pruner():
only_graph
=
only_graph
,
only_graph
=
only_graph
,
param_backup
=
param_backup
,
param_backup
=
param_backup
,
param_shape_backup
=
param_shape_backup
)
param_shape_backup
=
param_shape_backup
)
for
op
in
graph
.
ops
():
if
op
.
type
()
==
'depthwise_conv2d'
or
op
.
type
(
)
==
'depthwise_conv2d_grad'
:
op
.
set_attr
(
'groups'
,
op
.
inputs
(
'Filter'
)[
0
].
shape
()[
0
])
return
graph
.
program
return
graph
.
program
def
_prune_filters_by_ratio
(
self
,
def
_prune_filters_by_ratio
(
self
,
...
@@ -113,6 +121,8 @@ class Pruner():
...
@@ -113,6 +121,8 @@ class Pruner():
new_shape
=
list
(
param
.
shape
())
new_shape
=
list
(
param
.
shape
())
new_shape
[
0
]
=
pruned_param
.
shape
[
0
]
new_shape
[
0
]
=
pruned_param
.
shape
[
0
]
param
.
set_shape
(
new_shape
)
param
.
set_shape
(
new_shape
)
_logger
.
info
(
"prune [{}] from {} to {}"
.
format
(
param
.
name
(
),
ori_shape
,
new_shape
))
self
.
pruned_list
[
0
].
append
(
param
.
name
())
self
.
pruned_list
[
0
].
append
(
param
.
name
())
return
pruned_idx
return
pruned_idx
...
@@ -158,6 +168,8 @@ class Pruner():
...
@@ -158,6 +168,8 @@ class Pruner():
new_shape
=
list
(
param
.
shape
())
new_shape
=
list
(
param
.
shape
())
new_shape
[
pruned_axis
]
=
pruned_param
.
shape
[
pruned_axis
]
new_shape
[
pruned_axis
]
=
pruned_param
.
shape
[
pruned_axis
]
param
.
set_shape
(
new_shape
)
param
.
set_shape
(
new_shape
)
_logger
.
info
(
"prune [{}] from {} to {}"
.
format
(
param
.
name
(
),
ori_shape
,
new_shape
))
self
.
pruned_list
[
pruned_axis
].
append
(
param
.
name
())
self
.
pruned_list
[
pruned_axis
].
append
(
param
.
name
())
def
_forward_search_related_op
(
self
,
graph
,
param
):
def
_forward_search_related_op
(
self
,
graph
,
param
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录