Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
477debf7
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看板
提交
477debf7
编写于
12月 08, 2019
作者:
C
ceci3
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
d3a1891b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
49 addition
and
43 deletion
+49
-43
paddleslim/nas/search_space/inception_block.py
paddleslim/nas/search_space/inception_block.py
+5
-9
paddleslim/nas/search_space/mobilenet_block.py
paddleslim/nas/search_space/mobilenet_block.py
+6
-10
paddleslim/nas/search_space/mobilenetv1.py
paddleslim/nas/search_space/mobilenetv1.py
+2
-10
paddleslim/nas/search_space/mobilenetv2.py
paddleslim/nas/search_space/mobilenetv2.py
+2
-1
paddleslim/nas/search_space/resnet.py
paddleslim/nas/search_space/resnet.py
+18
-7
paddleslim/nas/search_space/resnet_block.py
paddleslim/nas/search_space/resnet_block.py
+3
-5
paddleslim/nas/search_space/utils.py
paddleslim/nas/search_space/utils.py
+13
-1
未找到文件。
paddleslim/nas/search_space/inception_block.py
浏览文件 @
477debf7
...
@@ -22,7 +22,7 @@ from paddle.fluid.param_attr import ParamAttr
...
@@ -22,7 +22,7 @@ from paddle.fluid.param_attr import ParamAttr
from
.search_space_base
import
SearchSpaceBase
from
.search_space_base
import
SearchSpaceBase
from
.base_layer
import
conv_bn_layer
from
.base_layer
import
conv_bn_layer
from
.search_space_registry
import
SEARCHSPACE
from
.search_space_registry
import
SEARCHSPACE
from
.utils
import
compute_downsample_num
from
.utils
import
compute_downsample_num
,
check_points
__all__
=
[
"InceptionABlockSpace"
,
"InceptionCBlockSpace"
]
__all__
=
[
"InceptionABlockSpace"
,
"InceptionCBlockSpace"
]
### TODO add asymmetric kernel of conv when paddle-lite support
### TODO add asymmetric kernel of conv when paddle-lite support
...
@@ -162,9 +162,7 @@ class InceptionABlockSpace(SearchSpaceBase):
...
@@ -162,9 +162,7 @@ class InceptionABlockSpace(SearchSpaceBase):
self
.
k_size
[
tokens
[
i
*
9
+
7
]],
1
,
self
.
k_size
[
tokens
[
i
*
9
+
7
]],
1
,
self
.
pool_type
[
tokens
[
i
*
9
+
8
]]))
self
.
pool_type
[
tokens
[
i
*
9
+
8
]]))
def
net_arch
(
input
,
return_mid_layer
=
False
,
return_block
=
[]):
def
net_arch
(
input
,
return_mid_layer
=
False
,
return_block
=
None
):
assert
isinstance
(
return_block
,
list
),
'return_block must be a list.'
layer_count
=
0
layer_count
=
0
mid_layer
=
dict
()
mid_layer
=
dict
()
for
i
,
layer_setting
in
enumerate
(
self
.
bottleneck_params_list
):
for
i
,
layer_setting
in
enumerate
(
self
.
bottleneck_params_list
):
...
@@ -174,7 +172,7 @@ class InceptionABlockSpace(SearchSpaceBase):
...
@@ -174,7 +172,7 @@ class InceptionABlockSpace(SearchSpaceBase):
pool_type
=
'avg'
if
layer_setting
[
9
]
==
0
else
'max'
pool_type
=
'avg'
if
layer_setting
[
9
]
==
0
else
'max'
if
stride
==
2
:
if
stride
==
2
:
layer_count
+=
1
layer_count
+=
1
if
(
layer_count
-
1
)
in
return_block
:
if
check_points
((
layer_count
-
1
),
return_block
)
:
mid_layer
[
layer_count
-
1
]
=
input
mid_layer
[
layer_count
-
1
]
=
input
input
=
self
.
_inceptionA
(
input
=
self
.
_inceptionA
(
...
@@ -406,9 +404,7 @@ class InceptionCBlockSpace(SearchSpaceBase):
...
@@ -406,9 +404,7 @@ class InceptionCBlockSpace(SearchSpaceBase):
self
.
k_size
[
tokens
[
i
*
11
+
9
]],
1
,
self
.
k_size
[
tokens
[
i
*
11
+
9
]],
1
,
self
.
pool_type
[
tokens
[
i
*
11
+
10
]]))
self
.
pool_type
[
tokens
[
i
*
11
+
10
]]))
def
net_arch
(
input
,
return_mid_layer
=
False
,
return_block
=
[]):
def
net_arch
(
input
,
return_mid_layer
=
False
,
return_block
=
None
):
assert
isinstance
(
return_block
,
list
),
'return_block must be a list.'
layer_count
=
0
layer_count
=
0
mid_layer
=
dict
()
mid_layer
=
dict
()
for
i
,
layer_setting
in
enumerate
(
self
.
bottleneck_params_list
):
for
i
,
layer_setting
in
enumerate
(
self
.
bottleneck_params_list
):
...
@@ -418,7 +414,7 @@ class InceptionCBlockSpace(SearchSpaceBase):
...
@@ -418,7 +414,7 @@ class InceptionCBlockSpace(SearchSpaceBase):
pool_type
=
'avg'
if
layer_setting
[
11
]
==
0
else
'max'
pool_type
=
'avg'
if
layer_setting
[
11
]
==
0
else
'max'
if
stride
==
2
:
if
stride
==
2
:
layer_count
+=
1
layer_count
+=
1
if
(
layer_count
-
1
)
in
return_block
:
if
check_points
((
layer_count
-
1
)
in
return_block
)
:
mid_layer
[
layer_count
-
1
]
=
input
mid_layer
[
layer_count
-
1
]
=
input
input
=
self
.
_inceptionC
(
input
=
self
.
_inceptionC
(
...
...
paddleslim/nas/search_space/mobilenet_block.py
浏览文件 @
477debf7
...
@@ -22,7 +22,7 @@ from paddle.fluid.param_attr import ParamAttr
...
@@ -22,7 +22,7 @@ from paddle.fluid.param_attr import ParamAttr
from
.search_space_base
import
SearchSpaceBase
from
.search_space_base
import
SearchSpaceBase
from
.base_layer
import
conv_bn_layer
from
.base_layer
import
conv_bn_layer
from
.search_space_registry
import
SEARCHSPACE
from
.search_space_registry
import
SEARCHSPACE
from
.utils
import
compute_downsample_num
from
.utils
import
compute_downsample_num
,
check_points
__all__
=
[
"MobileNetV1BlockSpace"
,
"MobileNetV2BlockSpace"
]
__all__
=
[
"MobileNetV1BlockSpace"
,
"MobileNetV2BlockSpace"
]
...
@@ -133,9 +133,7 @@ class MobileNetV2BlockSpace(SearchSpaceBase):
...
@@ -133,9 +133,7 @@ class MobileNetV2BlockSpace(SearchSpaceBase):
self
.
repeat
[
tokens
[
i
*
4
+
2
]],
1
,
self
.
repeat
[
tokens
[
i
*
4
+
2
]],
1
,
self
.
k_size
[
tokens
[
i
*
4
+
3
]]))
self
.
k_size
[
tokens
[
i
*
4
+
3
]]))
def
net_arch
(
input
,
return_mid_layer
=
False
,
return_block
=
[]):
def
net_arch
(
input
,
return_mid_layer
=
False
,
return_block
=
None
):
assert
isinstance
(
return_block
,
list
),
'return_block must be a list.'
# all padding is 'SAME' in the conv2d, can compute the actual padding automatic.
# all padding is 'SAME' in the conv2d, can compute the actual padding automatic.
# bottleneck sequences
# bottleneck sequences
in_c
=
int
(
32
*
self
.
scale
)
in_c
=
int
(
32
*
self
.
scale
)
...
@@ -148,7 +146,7 @@ class MobileNetV2BlockSpace(SearchSpaceBase):
...
@@ -148,7 +146,7 @@ class MobileNetV2BlockSpace(SearchSpaceBase):
if
s
==
2
:
if
s
==
2
:
layer_count
+=
1
layer_count
+=
1
if
(
layer_count
-
1
)
in
return_block
:
if
check_points
((
layer_count
-
1
),
return_block
)
:
mid_layer
[
layer_count
-
1
]
=
depthwise_conv
mid_layer
[
layer_count
-
1
]
=
depthwise_conv
input
,
depthwise_conv
=
self
.
_invresi_blocks
(
input
,
depthwise_conv
=
self
.
_invresi_blocks
(
...
@@ -162,7 +160,7 @@ class MobileNetV2BlockSpace(SearchSpaceBase):
...
@@ -162,7 +160,7 @@ class MobileNetV2BlockSpace(SearchSpaceBase):
name
=
'mobilenetv2_'
+
str
(
i
+
1
))
name
=
'mobilenetv2_'
+
str
(
i
+
1
))
in_c
=
int
(
c
*
self
.
scale
)
in_c
=
int
(
c
*
self
.
scale
)
if
layer_count
in
return_block
:
if
check_points
(
layer_count
,
return_block
)
:
mid_layer
[
layer_count
]
=
depthwise_conv
mid_layer
[
layer_count
]
=
depthwise_conv
if
return_mid_layer
:
if
return_mid_layer
:
...
@@ -374,9 +372,7 @@ class MobileNetV1BlockSpace(SearchSpaceBase):
...
@@ -374,9 +372,7 @@ class MobileNetV1BlockSpace(SearchSpaceBase):
self
.
filter_num
[
tokens
[
i
*
3
+
1
]],
1
,
self
.
filter_num
[
tokens
[
i
*
3
+
1
]],
1
,
self
.
k_size
[
tokens
[
i
*
3
+
2
]]))
self
.
k_size
[
tokens
[
i
*
3
+
2
]]))
def
net_arch
(
input
,
return_mid_layer
=
False
,
return_block
=
[]):
def
net_arch
(
input
,
return_mid_layer
=
False
,
return_block
=
None
):
assert
isinstance
(
return_block
,
list
),
'return_block must be a list.'
mid_layer
=
dict
()
mid_layer
=
dict
()
layer_count
=
0
layer_count
=
0
...
@@ -384,7 +380,7 @@ class MobileNetV1BlockSpace(SearchSpaceBase):
...
@@ -384,7 +380,7 @@ class MobileNetV1BlockSpace(SearchSpaceBase):
filter_num1
,
filter_num2
,
stride
,
kernel_size
=
layer_setting
filter_num1
,
filter_num2
,
stride
,
kernel_size
=
layer_setting
if
stride
==
2
:
if
stride
==
2
:
layer_count
+=
1
layer_count
+=
1
if
(
layer_count
-
1
)
in
return_block
:
if
check_points
((
layer_count
-
1
),
return_block
)
:
mid_layer
[
layer_count
-
1
]
=
input
mid_layer
[
layer_count
-
1
]
=
input
input
=
self
.
_depthwise_separable
(
input
=
self
.
_depthwise_separable
(
...
...
paddleslim/nas/search_space/mobilenetv1.py
浏览文件 @
477debf7
...
@@ -22,6 +22,7 @@ from paddle.fluid.param_attr import ParamAttr
...
@@ -22,6 +22,7 @@ from paddle.fluid.param_attr import ParamAttr
from
.search_space_base
import
SearchSpaceBase
from
.search_space_base
import
SearchSpaceBase
from
.base_layer
import
conv_bn_layer
from
.base_layer
import
conv_bn_layer
from
.search_space_registry
import
SEARCHSPACE
from
.search_space_registry
import
SEARCHSPACE
from
.utils
import
check_points
__all__
=
[
"MobileNetV1Space"
]
__all__
=
[
"MobileNetV1Space"
]
...
@@ -157,7 +158,7 @@ class MobileNetV1Space(SearchSpaceBase):
...
@@ -157,7 +158,7 @@ class MobileNetV1Space(SearchSpaceBase):
def
net_arch
(
input
,
def
net_arch
(
input
,
scale
=
1.0
,
scale
=
1.0
,
return_block
=
[]
,
return_block
=
None
,
end_points
=
None
,
end_points
=
None
,
output_stride
=
None
):
output_stride
=
None
):
self
.
scale
=
scale
self
.
scale
=
scale
...
@@ -165,15 +166,6 @@ class MobileNetV1Space(SearchSpaceBase):
...
@@ -165,15 +166,6 @@ class MobileNetV1Space(SearchSpaceBase):
decode_ends
=
dict
()
decode_ends
=
dict
()
def
check_points
(
count
,
points
):
if
points
is
None
:
return
False
else
:
if
isinstance
(
points
,
list
):
return
(
True
if
count
in
points
else
False
)
else
:
return
(
True
if
count
==
points
else
False
)
input
=
conv_bn_layer
(
input
=
conv_bn_layer
(
input
=
input
,
input
=
input
,
filter_size
=
3
,
filter_size
=
3
,
...
...
paddleslim/nas/search_space/mobilenetv2.py
浏览文件 @
477debf7
...
@@ -22,6 +22,7 @@ from paddle.fluid.param_attr import ParamAttr
...
@@ -22,6 +22,7 @@ from paddle.fluid.param_attr import ParamAttr
from
.search_space_base
import
SearchSpaceBase
from
.search_space_base
import
SearchSpaceBase
from
.base_layer
import
conv_bn_layer
from
.base_layer
import
conv_bn_layer
from
.search_space_registry
import
SEARCHSPACE
from
.search_space_registry
import
SEARCHSPACE
from
.utils
import
check_points
__all__
=
[
"MobileNetV2Space"
]
__all__
=
[
"MobileNetV2Space"
]
...
@@ -136,7 +137,7 @@ class MobileNetV2Space(SearchSpaceBase):
...
@@ -136,7 +137,7 @@ class MobileNetV2Space(SearchSpaceBase):
def
net_arch
(
input
,
def
net_arch
(
input
,
scale
=
1.0
,
scale
=
1.0
,
return_block
=
[]
,
return_block
=
None
,
end_points
=
None
,
end_points
=
None
,
output_stride
=
None
):
output_stride
=
None
):
self
.
scale
=
scale
self
.
scale
=
scale
...
...
paddleslim/nas/search_space/resnet.py
浏览文件 @
477debf7
...
@@ -22,17 +22,14 @@ from paddle.fluid.param_attr import ParamAttr
...
@@ -22,17 +22,14 @@ from paddle.fluid.param_attr import ParamAttr
from
.search_space_base
import
SearchSpaceBase
from
.search_space_base
import
SearchSpaceBase
from
.base_layer
import
conv_bn_layer
from
.base_layer
import
conv_bn_layer
from
.search_space_registry
import
SEARCHSPACE
from
.search_space_registry
import
SEARCHSPACE
from
.util
import
check_points
__all__
=
[
"ResNetSpace"
]
__all__
=
[
"ResNetSpace"
]
@
SEARCHSPACE
.
register
@
SEARCHSPACE
.
register
class
ResNetSpace
(
SearchSpaceBase
):
class
ResNetSpace
(
SearchSpaceBase
):
def
__init__
(
self
,
def
__init__
(
self
,
input_size
,
output_size
,
block_num
,
block_mask
=
None
):
input_size
,
output_size
,
block_num
,
block_mask
=
None
):
super
(
ResNetSpace
,
self
).
__init__
(
input_size
,
output_size
,
block_num
,
super
(
ResNetSpace
,
self
).
__init__
(
input_size
,
output_size
,
block_num
,
block_mask
)
block_mask
)
# self.filter_num1 ~ self.filter_num4 means convolution channel
# self.filter_num1 ~ self.filter_num4 means convolution channel
...
@@ -91,7 +88,9 @@ class ResNetSpace(SearchSpaceBase):
...
@@ -91,7 +88,9 @@ class ResNetSpace(SearchSpaceBase):
num_filters
.
append
(
filter4
)
num_filters
.
append
(
filter4
)
depth
.
append
(
repeat4
)
depth
.
append
(
repeat4
)
def
net_arch
(
input
):
def
net_arch
(
input
,
return_block
=
None
,
end_points
=
None
):
decode_ends
=
dict
()
conv
=
conv_bn_layer
(
conv
=
conv_bn_layer
(
input
=
input
,
input
=
input
,
filter_size
=
5
,
filter_size
=
5
,
...
@@ -99,14 +98,26 @@ class ResNetSpace(SearchSpaceBase):
...
@@ -99,14 +98,26 @@ class ResNetSpace(SearchSpaceBase):
stride
=
2
,
stride
=
2
,
act
=
'relu'
,
act
=
'relu'
,
name
=
'resnet_conv0'
)
name
=
'resnet_conv0'
)
layer_count
=
1
for
block
in
range
(
len
(
depth
)):
for
block
in
range
(
len
(
depth
)):
for
i
in
range
(
depth
[
block
]):
for
i
in
range
(
depth
[
block
]):
stride
=
2
if
i
==
0
and
block
!=
0
else
1
if
stride
==
2
:
layer_count
+=
1
if
check_points
((
layer_count
-
1
),
return_block
):
decode_ends
[
layer_count
-
1
]
=
conv
if
check_points
((
layer_count
-
1
),
end_points
):
return
conv
,
decode_ends
conv
=
self
.
_bottleneck_block
(
conv
=
self
.
_bottleneck_block
(
input
=
conv
,
input
=
conv
,
num_filters
=
num_filters
[
block
],
num_filters
=
num_filters
[
block
],
stride
=
2
if
i
==
0
and
block
!=
0
else
1
,
stride
=
stride
,
name
=
'resnet_depth{}_block{}'
.
format
(
i
,
block
))
name
=
'resnet_depth{}_block{}'
.
format
(
i
,
block
))
if
check_points
(
layer_count
,
end_points
):
return
conv
,
decode_ends
return
conv
return
conv
...
...
paddleslim/nas/search_space/resnet_block.py
浏览文件 @
477debf7
...
@@ -22,7 +22,7 @@ from paddle.fluid.param_attr import ParamAttr
...
@@ -22,7 +22,7 @@ from paddle.fluid.param_attr import ParamAttr
from
.search_space_base
import
SearchSpaceBase
from
.search_space_base
import
SearchSpaceBase
from
.base_layer
import
conv_bn_layer
from
.base_layer
import
conv_bn_layer
from
.search_space_registry
import
SEARCHSPACE
from
.search_space_registry
import
SEARCHSPACE
from
.utils
import
compute_downsample_num
from
.utils
import
compute_downsample_num
,
check_points
__all__
=
[
"ResNetBlockSpace"
]
__all__
=
[
"ResNetBlockSpace"
]
...
@@ -121,16 +121,14 @@ class ResNetBlockSpace(SearchSpaceBase):
...
@@ -121,16 +121,14 @@ class ResNetBlockSpace(SearchSpaceBase):
self
.
repeat
[
tokens
[
i
*
6
+
4
]],
self
.
repeat
[
tokens
[
i
*
6
+
4
]],
self
.
repeat
[
tokens
[
i
*
6
+
5
]],
1
))
self
.
repeat
[
tokens
[
i
*
6
+
5
]],
1
))
def
net_arch
(
input
,
return_mid_layer
=
False
,
return_block
=
[]):
def
net_arch
(
input
,
return_mid_layer
=
False
,
return_block
=
None
):
assert
isinstance
(
return_block
,
list
),
'return_block must be a list.'
layer_count
=
0
layer_count
=
0
mid_layer
=
dict
()
mid_layer
=
dict
()
for
i
,
layer_setting
in
enumerate
(
self
.
bottleneck_params_list
):
for
i
,
layer_setting
in
enumerate
(
self
.
bottleneck_params_list
):
filter_num1
,
filter_num2
,
filter_num3
,
k_size
,
repeat1
,
repeat2
,
stride
=
layer_setting
filter_num1
,
filter_num2
,
filter_num3
,
k_size
,
repeat1
,
repeat2
,
stride
=
layer_setting
if
stride
==
2
:
if
stride
==
2
:
layer_count
+=
1
layer_count
+=
1
if
(
layer_count
-
1
)
in
return_block
:
if
check_points
((
layer_count
-
1
),
return_block
)
:
mid_layer
[
layer_count
-
1
]
=
input
mid_layer
[
layer_count
-
1
]
=
input
input
=
self
.
_bottleneck_block
(
input
=
self
.
_bottleneck_block
(
...
...
paddleslim/nas/search_space/utils.py
浏览文件 @
477debf7
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
import
math
import
math
def
compute_downsample_num
(
input_size
,
output_size
):
def
compute_downsample_num
(
input_size
,
output_size
):
downsample_num
=
0
downsample_num
=
0
while
input_size
>
output_size
:
while
input_size
>
output_size
:
...
@@ -21,6 +22,17 @@ def compute_downsample_num(input_size, output_size):
...
@@ -21,6 +22,17 @@ def compute_downsample_num(input_size, output_size):
downsample_num
+=
1
downsample_num
+=
1
if
input_size
!=
output_size
:
if
input_size
!=
output_size
:
raise
NotImplementedError
(
'output_size must can downsample by input_size!!!'
)
raise
NotImplementedError
(
'output_size must can downsample by input_size!!!'
)
return
downsample_num
return
downsample_num
def
check_points
(
count
,
points
):
if
points
is
None
:
return
False
else
:
if
isinstance
(
points
,
list
):
return
(
True
if
count
in
points
else
False
)
else
:
return
(
True
if
count
==
points
else
False
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录