Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
8dd809d9
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看板
未验证
提交
8dd809d9
编写于
9月 15, 2020
作者:
Y
yukavio
提交者:
GitHub
9月 15, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bug when prune depthwise convolution layer. (#399) (#454)
上级
a52f3be2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
6 addition
and
17 deletion
+6
-17
paddleslim/core/graph_wrapper.py
paddleslim/core/graph_wrapper.py
+3
-15
paddleslim/prune/group_param.py
paddleslim/prune/group_param.py
+1
-2
tests/test_group_param.py
tests/test_group_param.py
+2
-0
未找到文件。
paddleslim/core/graph_wrapper.py
浏览文件 @
8dd809d9
...
...
@@ -166,9 +166,7 @@ class OpWrapper(object):
"""
Get all the varibales by the output name.
"""
return
[
self
.
_graph
.
var
(
var_name
)
for
var_name
in
self
.
_op
.
output
(
name
)
]
return
[
self
.
_graph
.
var
(
var_name
)
for
var_name
in
self
.
_op
.
output
(
name
)]
def
set_attr
(
self
,
key
,
value
):
"""
...
...
@@ -354,16 +352,6 @@ class GraphWrapper(object):
ret
+=
np
.
product
(
param
.
shape
())
return
ret
def
update_param_shape
(
self
,
scope
):
"""
Update the shape of parameters in the graph according to tensors in scope.
It is used after loading pruned parameters from file.
"""
for
param
in
self
.
all_parameters
():
tensor_shape
=
np
.
array
(
scope
.
find_var
(
param
.
name
()).
get_tensor
()).
shape
param
.
set_shape
(
tensor_shape
)
def
infer_shape
(
self
):
"""
Update the groups of convolution layer according to current filters.
...
...
@@ -375,6 +363,6 @@ class GraphWrapper(object):
def
update_groups_of_conv
(
self
):
for
op
in
self
.
ops
():
if
op
.
type
()
==
'depthwise_conv2d'
or
op
.
type
(
)
==
'depthwise_conv2d_grad'
:
if
'conv2d'
in
op
.
type
()
and
op
.
attr
(
'groups'
)
>=
op
.
inputs
(
'Filter'
)[
0
].
shape
()[
0
]
:
op
.
set_attr
(
'groups'
,
op
.
inputs
(
'Filter'
)[
0
].
shape
()[
0
])
paddleslim/prune/group_param.py
浏览文件 @
8dd809d9
...
...
@@ -58,8 +58,7 @@ def collect_convs(params, graph, visited={}):
walker
=
conv2d_walker
(
conv_op
,
pruned_params
=
pruned_params
,
visited
=
visited
)
walker
.
prune
(
param
,
pruned_axis
=
0
,
pruned_idx
=
[
0
])
if
len
(
pruned_params
)
>
0
:
groups
.
append
(
pruned_params
)
groups
.
append
(
pruned_params
)
visited
=
set
()
uniq_groups
=
[]
for
group
in
groups
:
...
...
tests/test_group_param.py
浏览文件 @
8dd809d9
...
...
@@ -42,6 +42,8 @@ class TestPrune(unittest.TestCase):
conv6
=
conv_bn_layer
(
conv5
,
8
,
3
,
"conv6"
)
groups
=
collect_convs
(
[
"conv1_weights"
,
"conv2_weights"
,
"conv3_weights"
],
main_program
)
while
[]
in
groups
:
groups
.
remove
([])
self
.
assertTrue
(
len
(
groups
)
==
2
)
self
.
assertTrue
(
len
(
groups
[
0
])
==
18
)
self
.
assertTrue
(
len
(
groups
[
1
])
==
6
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录