Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
a13fe40b
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看板
未验证
提交
a13fe40b
编写于
4月 22, 2020
作者:
L
lijianshe02
提交者:
GitHub
4月 22, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix some prune API related bugs test=develop (#232)
上级
7160d704
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
13 addition
and
8 deletion
+13
-8
paddleslim/prune/criterion.py
paddleslim/prune/criterion.py
+6
-3
paddleslim/prune/idx_selector.py
paddleslim/prune/idx_selector.py
+1
-1
tests/test_optimal_threshold.py
tests/test_optimal_threshold.py
+2
-1
tests/test_prune.py
tests/test_prune.py
+3
-2
tests/test_slim_prune.py
tests/test_slim_prune.py
+1
-1
未找到文件。
paddleslim/prune/criterion.py
浏览文件 @
a13fe40b
...
...
@@ -17,7 +17,7 @@
import
logging
import
numpy
as
np
from
..common
import
get_logger
from
..core
import
Registry
from
..core
import
Registry
,
GraphWrapper
__all__
=
[
"l1_norm"
,
"CRITERION"
]
...
...
@@ -61,13 +61,16 @@ def geometry_median(group, graph):
channel_num
=
value
.
shape
[
0
]
w
.
shape
=
value
.
shape
[
0
],
np
.
product
(
value
.
shape
[
1
:])
x
=
w
.
repeat
(
channel_num
,
axis
=
0
)
y
=
np
.
tile
(
channel_num
,
(
channel_num
,
1
))
y
=
np
.
zeros_like
(
x
)
for
i
in
range
(
channel_num
):
y
[
i
*
channel_num
:(
i
+
1
)
*
channel_num
]
=
np
.
tile
(
channel_num
,
(
channel_num
,
1
))
tmp
=
np
.
sqrt
(
np
.
sum
((
x
-
y
)
**
2
,
-
1
))
tmp
=
tmp
.
reshape
((
channel_num
,
channel_num
))
tmp
=
np
.
sum
(
tmp
,
-
1
)
for
name
,
value
,
axis
in
group
:
scores
.
append
(
name
,
axis
,
tmp
)
scores
.
append
(
(
name
,
axis
,
tmp
)
)
return
scores
...
...
paddleslim/prune/idx_selector.py
浏览文件 @
a13fe40b
...
...
@@ -96,7 +96,7 @@ def optimal_threshold(group, ratio):
name
,
axis
,
score
=
group
[
0
]
# sort channels by the first convolution's score
score
[
sco
ew
<
1e-18
]
=
1e-18
score
[
sco
re
<
1e-18
]
=
1e-18
score_sorted
=
np
.
sort
(
score
)
score_square
=
score_sorted
**
2
total_sum
=
score_square
.
sum
()
...
...
tests/test_optimal_threshold.py
浏览文件 @
a13fe40b
...
...
@@ -49,7 +49,8 @@ class TestPrune(unittest.TestCase):
exe
=
fluid
.
Executor
(
place
)
scope
=
fluid
.
Scope
()
exe
.
run
(
startup_program
,
scope
=
scope
)
criterion
=
'optimal_threshold'
criterion
=
'bn_scale'
idx_selector
=
'optimal_threshold'
pruner
=
Pruner
(
criterion
)
main_program
,
_
,
_
=
pruner
.
prune
(
main_program
,
...
...
tests/test_prune.py
浏览文件 @
a13fe40b
...
...
@@ -15,7 +15,7 @@ import sys
sys
.
path
.
append
(
"../"
)
import
unittest
import
paddle.fluid
as
fluid
from
paddleslim.prune
.walk_pruner
import
Pruner
from
paddleslim.prune
import
Pruner
from
layers
import
conv_bn_layer
...
...
@@ -72,7 +72,8 @@ class TestPrune(unittest.TestCase):
for
param
in
main_program
.
global_block
().
all_parameters
():
if
"weights"
in
param
.
name
:
print
(
"param: {}; param shape: {}"
.
format
(
param
.
name
,
param
.
shape
))
print
(
"param: {}; param shape: {}"
.
format
(
param
.
name
,
param
.
shape
))
self
.
assertTrue
(
param
.
shape
==
shapes
[
param
.
name
])
...
...
tests/test_slim_prune.py
浏览文件 @
a13fe40b
...
...
@@ -49,7 +49,7 @@ class TestPrune(unittest.TestCase):
exe
=
fluid
.
Executor
(
place
)
scope
=
fluid
.
Scope
()
exe
.
run
(
startup_program
,
scope
=
scope
)
criterion
=
'b
atch_norm
_scale'
criterion
=
'b
n
_scale'
pruner
=
Pruner
(
criterion
)
main_program
,
_
,
_
=
pruner
.
prune
(
main_program
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录