Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
211f83fa
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
211f83fa
编写于
7月 04, 2017
作者:
Z
zlx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
set depthwise conv layer interface in python
上级
6fd41f7b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
147 addition
and
0 deletion
+147
-0
python/paddle/trainer/config_parser.py
python/paddle/trainer/config_parser.py
+57
-0
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+90
-0
未找到文件。
python/paddle/trainer/config_parser.py
浏览文件 @
211f83fa
...
...
@@ -1741,6 +1741,59 @@ class ParameterReluLayer(LayerBase):
self
.
create_input_parameter
(
0
,
input_layer
.
size
/
partial_sum
)
@
config_layer
(
'depthwise_conv'
)
class
DepthwiseConvLayer
(
LayerBase
):
layer_type
=
'depthwise_conv'
def
__init__
(
self
,
name
,
inputs
=
[],
bias
=
True
,
num_filters
=
None
,
shared_biases
=
False
,
**
xargs
):
super
(
DepthwiseConvLayer
,
self
).
__init__
(
name
,
self
.
layer_type
,
0
,
inputs
=
inputs
,
**
xargs
)
if
num_filters
is
not
None
:
self
.
config
.
num_filters
=
num_filters
use_gpu
=
int
(
g_command_config_args
.
get
(
"use_gpu"
,
0
))
parallel_nn
=
int
(
g_command_config_args
.
get
(
"parallel_nn"
,
0
))
# Automatically select cudnn_type for GPU and exconv for CPU
# if set type=conv, but still reserve the way user specify
# exconv or cudnn_conv manually.
self
.
layer_type
=
"depthwise_conv"
# need to specify layer in config
self
.
config
.
type
=
self
.
layer_type
if
shared_biases
is
not
None
:
self
.
config
.
shared_biases
=
shared_biases
for
input_index
in
xrange
(
len
(
self
.
inputs
)):
input_layer
=
self
.
get_input_layer
(
input_index
)
conv_conf
=
self
.
config
.
inputs
[
input_index
].
conv_conf
#set the groups
self
.
inputs
[
input_index
].
conv
.
groups
=
self
.
inputs
[
input_index
].
conv
.
channels
parse_conv
(
self
.
inputs
[
input_index
].
conv
,
input_layer
.
name
,
conv_conf
,
num_filters
)
psize
=
self
.
calc_parameter_size
(
conv_conf
)
self
.
create_input_parameter
(
input_index
,
psize
)
self
.
set_cnn_layer
(
name
,
conv_conf
.
output_y
,
conv_conf
.
output_x
,
self
.
config
.
num_filters
)
psize
=
self
.
config
.
size
if
shared_biases
:
psize
=
self
.
config
.
num_filters
self
.
create_bias_parameter
(
bias
,
psize
,
[
psize
,
1
])
def
calc_parameter_size
(
self
,
conv_conf
):
return
self
.
config
.
num_filters
*
conv_conf
.
filter_channels
\
*
(
conv_conf
.
filter_size
*
conv_conf
.
filter_size_y
)
@
config_layer
(
'conv'
)
class
ConvLayerBase
(
LayerBase
):
layer_type
=
'conv'
...
...
@@ -3145,6 +3198,10 @@ def ParameterHook(type, **kwargs):
if
sparsity_ratio
is
not
None
:
hook
.
sparsity_ratio
=
sparsity_ratio
return
hook
elif
type
==
'dpruning'
:
hook
=
ParameterUpdaterHookConfig
()
hook
.
type
=
type
return
hook
else
:
return
None
...
...
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
211f83fa
...
...
@@ -57,6 +57,7 @@ __all__ = [
'classification_cost'
,
'LayerOutput'
,
'img_conv_layer'
,
'img_depthwise_conv_layer'
,
'img_pool_layer'
,
'batch_norm_layer'
,
'img_cmrnorm_layer'
,
...
...
@@ -148,6 +149,7 @@ class LayerType(object):
HSIGMOID
=
'hsigmoid'
CONV_LAYER
=
'conv'
CONVTRANS_LAYER
=
'convt'
DEPTHWISE_CONV_LAYER
=
'depthwise_conv'
EXCONV_LAYER
=
'exconv'
EXCONVTRANS_LAYER
=
'exconvt'
CUDNNCONV_LAYER
=
'cudnn_conv'
...
...
@@ -2085,6 +2087,94 @@ def hsigmoid(input,
name
,
LayerType
.
HSIGMOID
,
parents
=
parents
,
size
=
l
.
config
.
size
)
@
wrap_name_default
(
"depthwise_conv"
)
@
wrap_param_attr_default
()
@
wrap_bias_attr_default
()
@
wrap_act_default
(
act
=
ReluActivation
())
@
layer_support
(
DROPOUT
)
def
img_depthwise_conv_layer
(
input
,
filter_size
,
num_filters
,
name
=
None
,
num_channels
=
None
,
act
=
None
,
groups
=
1
,
stride
=
1
,
padding
=
0
,
bias_attr
=
None
,
param_attr
=
None
,
shared_biases
=
True
,
layer_attr
=
None
,
filter_size_y
=
None
,
stride_y
=
None
,
padding_y
=
None
,
trans
=
False
,
layer_type
=
None
):
if
num_channels
is
None
:
assert
input
.
num_filters
is
not
None
num_channels
=
input
.
num_filters
if
filter_size_y
is
None
:
if
isinstance
(
filter_size
,
collections
.
Sequence
):
assert
len
(
filter_size
)
==
2
filter_size
,
filter_size_y
=
filter_size
else
:
filter_size_y
=
filter_size
if
stride_y
is
None
:
if
isinstance
(
stride
,
collections
.
Sequence
):
assert
len
(
stride
)
==
2
stride
,
stride_y
=
stride
else
:
stride_y
=
stride
if
padding_y
is
None
:
if
isinstance
(
padding
,
collections
.
Sequence
):
assert
len
(
padding
)
==
2
padding
,
padding_y
=
padding
else
:
padding_y
=
padding
if
param_attr
.
attr
.
get
(
'initial_smart'
):
# special initial for conv layers.
init_w
=
(
2.0
/
(
filter_size
**
2
*
num_channels
))
**
0.5
param_attr
.
attr
[
"initial_mean"
]
=
0.0
param_attr
.
attr
[
"initial_std"
]
=
init_w
param_attr
.
attr
[
"initial_strategy"
]
=
0
param_attr
.
attr
[
"initial_smart"
]
=
False
lt
=
LayerType
.
DEPTHWISE_CONV_LAYER
l
=
Layer
(
name
=
name
,
inputs
=
Input
(
input
.
name
,
conv
=
Conv
(
filter_size
=
filter_size
,
padding
=
padding
,
stride
=
stride
,
channels
=
num_channels
,
groups
=
groups
,
filter_size_y
=
filter_size_y
,
padding_y
=
padding_y
,
stride_y
=
stride_y
),
**
param_attr
.
attr
),
active_type
=
act
.
name
,
num_filters
=
num_filters
,
bias
=
ParamAttr
.
to_bias
(
bias_attr
),
shared_biases
=
shared_biases
,
type
=
lt
,
**
ExtraLayerAttribute
.
to_kwargs
(
layer_attr
))
return
LayerOutput
(
name
,
lt
,
parents
=
[
input
],
activation
=
act
,
num_filters
=
num_filters
,
size
=
l
.
config
.
size
)
@
wrap_name_default
(
"conv"
)
@
wrap_param_attr_default
()
@
wrap_bias_attr_default
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录