Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
6b61a096
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6b61a096
编写于
1月 07, 2017
作者:
D
dangqingqing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optional padding mode, namely ceil or floor, ceil by default.
上级
c8817a19
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
1614 addition
and
1600 deletion
+1614
-1600
paddle/function/PadOp.cpp
paddle/function/PadOp.cpp
+8
-8
paddle/function/PadOpTest.cpp
paddle/function/PadOpTest.cpp
+25
-23
paddle/gserver/tests/test_LayerGrad.cpp
paddle/gserver/tests/test_LayerGrad.cpp
+1545
-1548
python/paddle/trainer/config_parser.py
python/paddle/trainer/config_parser.py
+16
-20
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+20
-1
未找到文件。
paddle/function/PadOp.cpp
浏览文件 @
6b61a096
...
@@ -73,10 +73,6 @@ void PadGrad<DEVICE_TYPE_CPU>(real* inGrad,
...
@@ -73,10 +73,6 @@ void PadGrad<DEVICE_TYPE_CPU>(real* inGrad,
}
}
}
}
/**
* \param inputs[0] input value.
* \param outputs[0] output value.
*/
template
<
DeviceType
Device
>
template
<
DeviceType
Device
>
class
PadFunc
:
public
FunctionBase
{
class
PadFunc
:
public
FunctionBase
{
public:
public:
...
@@ -89,6 +85,10 @@ public:
...
@@ -89,6 +85,10 @@ public:
padw1_
=
config
.
get
<
int
>
(
"padw1"
);
padw1_
=
config
.
get
<
int
>
(
"padw1"
);
}
}
/**
* \param inputs[0] input value.
* \param outputs[0] output value.
*/
void
calc
(
const
Arguments
&
inputs
,
void
calc
(
const
Arguments
&
inputs
,
const
Arguments
&
outputs
,
const
Arguments
&
outputs
,
const
Arguments
&
inouts
)
override
{
const
Arguments
&
inouts
)
override
{
...
@@ -124,10 +124,6 @@ private:
...
@@ -124,10 +124,6 @@ private:
int
padw1_
;
int
padw1_
;
};
};
/**
* \param inputs[0] input grad.
* \param outputs[0] output grad.
*/
template
<
DeviceType
Device
>
template
<
DeviceType
Device
>
class
PadGradFunc
:
public
FunctionBase
{
class
PadGradFunc
:
public
FunctionBase
{
public:
public:
...
@@ -140,6 +136,10 @@ public:
...
@@ -140,6 +136,10 @@ public:
padw1_
=
config
.
get
<
int
>
(
"padw1"
);
padw1_
=
config
.
get
<
int
>
(
"padw1"
);
}
}
/**
* \param inputs[0] output grad.
* \param inouts[0] input grad.
*/
void
calc
(
const
Arguments
&
inputs
,
void
calc
(
const
Arguments
&
inputs
,
const
Arguments
&
outputs
,
const
Arguments
&
outputs
,
const
Arguments
&
inouts
)
override
{
const
Arguments
&
inouts
)
override
{
...
...
paddle/function/PadOpTest.cpp
浏览文件 @
6b61a096
...
@@ -43,28 +43,30 @@ TEST(Pad, real) {
...
@@ -43,28 +43,30 @@ TEST(Pad, real) {
}
}
}
}
// TEST(PadGrad, real) {
TEST
(
PadGrad
,
real
)
{
// for (size_t numSamples : {5, 32}) {
for
(
size_t
numSamples
:
{
5
,
32
})
{
// for (size_t channels : {1, 5, 32}) {
for
(
size_t
channels
:
{
1
,
5
,
32
})
{
// for (size_t imgSizeH : {5, 33, 100}) {
for
(
size_t
imgSizeH
:
{
5
,
33
,
100
})
{
// for (size_t imgSizeW : {5, 32, 96}) {
for
(
size_t
imgSizeW
:
{
5
,
32
,
96
})
{
// VLOG(3) << " numSamples=" << numSamples << " channels=" << channels
VLOG
(
3
)
<<
" numSamples="
<<
numSamples
<<
" channels="
<<
channels
// << " imgSizeH=" << imgSizeH << " imgSizeW=" << imgSizeW;
<<
" imgSizeH="
<<
imgSizeH
<<
" imgSizeW="
<<
imgSizeW
;
//
// FunctionCompare compare("PadGrad",
FunctionCompare
compare
(
"PadGrad"
,
// FuncConfig()
FuncConfig
()
// .set("padc0", 2).set("padc1", 3)
.
set
(
"padc0"
,
2
)
// .set("padh0", 1).set("padh1", 2)
.
set
(
"padc1"
,
3
)
// .set("padw0", 3).set("padw1", 2));
.
set
(
"padh0"
,
1
)
// Dims inDims{numSamples, channels, imgSizeH, imgSizeW};
.
set
(
"padh1"
,
2
)
// Dims outDims{numSamples, channels + 5, imgSizeH + 3, imgSizeW + 5};
.
set
(
"padw0"
,
3
)
// compare.cmpWithArg({Tensor(nullptr, inDims)},
.
set
(
"padw1"
,
2
));
// {Tensor(nullptr, outDims)},
Dims
inDims
{
numSamples
,
channels
,
imgSizeH
,
imgSizeW
};
// {});
Dims
outDims
{
numSamples
,
channels
+
5
,
imgSizeH
+
3
,
imgSizeW
+
5
};
// }
compare
.
cmpWithArg
(
// }
{
Tensor
(
nullptr
,
inDims
)},
{},
{
Tensor
(
nullptr
,
outDims
)});
// }
}
// }
}
//}
}
}
}
}
// namespace paddle
}
// namespace paddle
paddle/gserver/tests/test_LayerGrad.cpp
浏览文件 @
6b61a096
此差异已折叠。
点击以展开。
python/paddle/trainer/config_parser.py
浏览文件 @
6b61a096
...
@@ -1109,7 +1109,7 @@ def parse_bilinear(bilinear, input_layer_name, bilinear_conf):
...
@@ -1109,7 +1109,7 @@ def parse_bilinear(bilinear, input_layer_name, bilinear_conf):
bilinear_conf
.
out_size_y
=
bilinear
.
out_size_y
bilinear_conf
.
out_size_y
=
bilinear
.
out_size_y
def
parse_pool
(
pool
,
input_layer_name
,
pool_conf
):
def
parse_pool
(
pool
,
input_layer_name
,
pool_conf
,
ceil_mode
):
pool_conf
.
pool_type
=
pool
.
pool_type
pool_conf
.
pool_type
=
pool
.
pool_type
config_assert
(
pool
.
pool_type
in
[
config_assert
(
pool
.
pool_type
in
[
'max-projection'
,
'avg-projection'
,
'cudnn-max-pool'
,
'cudnn-avg-pool'
'max-projection'
,
'avg-projection'
,
'cudnn-max-pool'
,
'cudnn-avg-pool'
...
@@ -1134,10 +1134,10 @@ def parse_pool(pool, input_layer_name, pool_conf):
...
@@ -1134,10 +1134,10 @@ def parse_pool(pool, input_layer_name, pool_conf):
pool_conf
.
padding_y
=
default
(
pool
.
padding_y
,
pool_conf
.
padding
)
pool_conf
.
padding_y
=
default
(
pool
.
padding_y
,
pool_conf
.
padding
)
pool_conf
.
output_x
=
cnn_output_size
(
pool_conf
.
img_size
,
pool_conf
.
size_x
,
pool_conf
.
output_x
=
cnn_output_size
(
pool_conf
.
img_size
,
pool_conf
.
size_x
,
pool_conf
.
padding
,
pool_conf
.
stride
,
pool_conf
.
padding
,
pool_conf
.
stride
,
Fals
e
)
not
ceil_mod
e
)
pool_conf
.
output_y
=
cnn_output_size
(
pool_conf
.
img_size_y
,
pool_conf
.
size_y
,
pool_conf
.
output_y
=
cnn_output_size
(
pool_conf
.
img_size_y
,
pool_conf
.
size_y
,
pool_conf
.
padding_y
,
pool_conf
.
padding_y
,
pool_conf
.
stride_y
,
Fals
e
)
pool_conf
.
stride_y
,
not
ceil_mod
e
)
def
parse_spp
(
spp
,
input_layer_name
,
spp_conf
):
def
parse_spp
(
spp
,
input_layer_name
,
spp_conf
):
...
@@ -1810,9 +1810,8 @@ class ConvTransLayer(ConvTransLayerBase):
...
@@ -1810,9 +1810,8 @@ class ConvTransLayer(ConvTransLayerBase):
@
config_layer
(
'norm'
)
@
config_layer
(
'norm'
)
class
NormLayer
(
LayerBase
):
class
NormLayer
(
LayerBase
):
def
__init__
(
self
,
name
,
inputs
,
device
=
None
):
def
__init__
(
self
,
name
,
inputs
,
**
xargs
):
super
(
NormLayer
,
self
).
__init__
(
super
(
NormLayer
,
self
).
__init__
(
name
,
'norm'
,
0
,
inputs
=
inputs
,
**
xargs
)
name
,
'norm'
,
0
,
inputs
=
inputs
,
device
=
device
)
for
input_index
in
xrange
(
len
(
self
.
inputs
)):
for
input_index
in
xrange
(
len
(
self
.
inputs
)):
input_layer
=
self
.
get_input_layer
(
input_index
)
input_layer
=
self
.
get_input_layer
(
input_index
)
norm_conf
=
self
.
config
.
inputs
[
input_index
].
norm_conf
norm_conf
=
self
.
config
.
inputs
[
input_index
].
norm_conf
...
@@ -1824,23 +1823,22 @@ class NormLayer(LayerBase):
...
@@ -1824,23 +1823,22 @@ class NormLayer(LayerBase):
@
config_layer
(
'pool'
)
@
config_layer
(
'pool'
)
class
PoolLayer
(
LayerBase
):
class
PoolLayer
(
LayerBase
):
def
__init__
(
self
,
name
,
inputs
,
device
=
None
):
def
__init__
(
self
,
name
,
inputs
,
ceil_mode
=
True
,
**
xargs
):
super
(
PoolLayer
,
self
).
__init__
(
super
(
PoolLayer
,
self
).
__init__
(
name
,
'pool'
,
0
,
inputs
=
inputs
,
**
xargs
)
name
,
'pool'
,
0
,
inputs
=
inputs
,
device
=
device
)
for
input_index
in
xrange
(
len
(
self
.
inputs
)):
for
input_index
in
xrange
(
len
(
self
.
inputs
)):
input_layer
=
self
.
get_input_layer
(
input_index
)
input_layer
=
self
.
get_input_layer
(
input_index
)
pool_conf
=
self
.
config
.
inputs
[
input_index
].
pool_conf
pool_conf
=
self
.
config
.
inputs
[
input_index
].
pool_conf
parse_pool
(
self
.
inputs
[
input_index
].
pool
,
input_layer
.
name
,
parse_pool
(
self
.
inputs
[
input_index
].
pool
,
input_layer
.
name
,
pool_conf
)
pool_conf
,
ceil_mode
)
self
.
set_cnn_layer
(
name
,
pool_conf
.
output_y
,
pool_conf
.
output_x
,
self
.
set_cnn_layer
(
name
,
pool_conf
.
output_y
,
pool_conf
.
output_x
,
pool_conf
.
channels
)
pool_conf
.
channels
)
@
config_layer
(
'spp'
)
@
config_layer
(
'spp'
)
class
SpatialPyramidPoolLayer
(
LayerBase
):
class
SpatialPyramidPoolLayer
(
LayerBase
):
def
__init__
(
self
,
name
,
inputs
,
device
=
None
):
def
__init__
(
self
,
name
,
inputs
,
**
xargs
):
super
(
SpatialPyramidPoolLayer
,
self
).
__init__
(
super
(
SpatialPyramidPoolLayer
,
self
).
__init__
(
name
,
'spp'
,
0
,
inputs
=
inputs
,
device
=
device
)
name
,
'spp'
,
0
,
inputs
=
inputs
,
**
xargs
)
for
input_index
in
xrange
(
len
(
self
.
inputs
)):
for
input_index
in
xrange
(
len
(
self
.
inputs
)):
input_layer
=
self
.
get_input_layer
(
input_index
)
input_layer
=
self
.
get_input_layer
(
input_index
)
spp_conf
=
self
.
config
.
inputs
[
input_index
].
spp_conf
spp_conf
=
self
.
config
.
inputs
[
input_index
].
spp_conf
...
@@ -1877,7 +1875,6 @@ class BatchNormLayer(LayerBase):
...
@@ -1877,7 +1875,6 @@ class BatchNormLayer(LayerBase):
inputs
,
inputs
,
active_type
=
"linear"
,
active_type
=
"linear"
,
bias
=
True
,
bias
=
True
,
device
=
None
,
use_global_stats
=
True
,
use_global_stats
=
True
,
moving_average_fraction
=
0.9
,
moving_average_fraction
=
0.9
,
batch_norm_type
=
None
,
batch_norm_type
=
None
,
...
@@ -1919,7 +1916,6 @@ class BatchNormLayer(LayerBase):
...
@@ -1919,7 +1916,6 @@ class BatchNormLayer(LayerBase):
0
,
0
,
active_type
=
active_type
,
active_type
=
active_type
,
inputs
=
inputs
,
inputs
=
inputs
,
device
=
device
,
**
xargs
)
**
xargs
)
if
use_global_stats
is
not
None
:
if
use_global_stats
is
not
None
:
...
@@ -1953,9 +1949,9 @@ class BatchNormLayer(LayerBase):
...
@@ -1953,9 +1949,9 @@ class BatchNormLayer(LayerBase):
@
config_layer
(
'trans'
)
@
config_layer
(
'trans'
)
class
TransLayer
(
LayerBase
):
class
TransLayer
(
LayerBase
):
def
__init__
(
self
,
name
,
inputs
,
device
=
None
):
def
__init__
(
self
,
name
,
inputs
,
**
xargs
):
super
(
TransLayer
,
self
).
__init__
(
super
(
TransLayer
,
self
).
__init__
(
name
,
'trans'
,
0
,
inputs
=
inputs
,
device
=
device
)
name
,
'trans'
,
0
,
inputs
=
inputs
,
**
xargs
)
config_assert
(
config_assert
(
len
(
self
.
inputs
)
==
1
,
len
(
self
.
inputs
)
==
1
,
'TransLayer must have one and only one input'
)
'TransLayer must have one and only one input'
)
...
@@ -1964,9 +1960,9 @@ class TransLayer(LayerBase):
...
@@ -1964,9 +1960,9 @@ class TransLayer(LayerBase):
@
config_layer
(
'resize'
)
@
config_layer
(
'resize'
)
class
ResizeLayer
(
LayerBase
):
class
ResizeLayer
(
LayerBase
):
def
__init__
(
self
,
name
,
size
,
inputs
,
device
=
None
):
def
__init__
(
self
,
name
,
size
,
inputs
,
**
xargs
):
super
(
ResizeLayer
,
self
).
__init__
(
super
(
ResizeLayer
,
self
).
__init__
(
name
,
'resize'
,
size
=
size
,
inputs
=
inputs
,
device
=
device
)
name
,
'resize'
,
size
=
size
,
inputs
=
inputs
,
**
xargs
)
config_assert
(
config_assert
(
len
(
self
.
inputs
)
==
1
,
len
(
self
.
inputs
)
==
1
,
'ResizeLayer must have one and only one input'
)
'ResizeLayer must have one and only one input'
)
...
@@ -1974,9 +1970,9 @@ class ResizeLayer(LayerBase):
...
@@ -1974,9 +1970,9 @@ class ResizeLayer(LayerBase):
@
config_layer
(
'blockexpand'
)
@
config_layer
(
'blockexpand'
)
class
BlockExpandLayer
(
LayerBase
):
class
BlockExpandLayer
(
LayerBase
):
def
__init__
(
self
,
name
,
inputs
,
device
=
None
):
def
__init__
(
self
,
name
,
inputs
,
**
xargs
):
super
(
BlockExpandLayer
,
self
).
__init__
(
super
(
BlockExpandLayer
,
self
).
__init__
(
name
,
'blockexpand'
,
0
,
inputs
=
inputs
,
device
=
device
)
name
,
'blockexpand'
,
0
,
inputs
=
inputs
,
**
xargs
)
for
input_index
in
xrange
(
len
(
self
.
inputs
)):
for
input_index
in
xrange
(
len
(
self
.
inputs
)):
input_layer
=
self
.
get_input_layer
(
input_index
)
input_layer
=
self
.
get_input_layer
(
input_index
)
parse_block_expand
(
parse_block_expand
(
...
...
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
6b61a096
...
@@ -1980,7 +1980,8 @@ def img_pool_layer(input,
...
@@ -1980,7 +1980,8 @@ def img_pool_layer(input,
layer_attr
=
None
,
layer_attr
=
None
,
pool_size_y
=
None
,
pool_size_y
=
None
,
stride_y
=
None
,
stride_y
=
None
,
padding_y
=
None
):
padding_y
=
None
,
ceil_mode
=
True
):
"""
"""
Image pooling Layer.
Image pooling Layer.
...
@@ -2011,6 +2012,23 @@ def img_pool_layer(input,
...
@@ -2011,6 +2012,23 @@ def img_pool_layer(input,
:type stride_y: int|None
:type stride_y: int|None
:param layer_attr: Extra Layer attribute.
:param layer_attr: Extra Layer attribute.
:type layer_attr: ExtraLayerAttribute
:type layer_attr: ExtraLayerAttribute
:param ceil_mode: Wether to use ceil mode to calculate output height and with.
Defalut is True. If set false, Otherwise use floor.
- ceil_mode=True:
.. math::
w = 1 + int(ceil(input_width + 2 * padding - pool_size) / float(stride))
h = 1 + int(ceil(input_height + 2 * padding_y - pool_size_y) / float(stride_y))
- ceil_mode=False:
.. math::
w = 1 + int(floor(input_width + 2 * padding - pool_size) / float(stride))
h = 1 + int(floor(input_height + 2 * padding_y - pool_size_y) / float(stride_y))
:type ceil_mode: bool
:return: LayerOutput object.
:return: LayerOutput object.
:rtype: LayerOutput
:rtype: LayerOutput
"""
"""
...
@@ -2048,6 +2066,7 @@ def img_pool_layer(input,
...
@@ -2048,6 +2066,7 @@ def img_pool_layer(input,
stride_y
=
stride_y
,
stride_y
=
stride_y
,
padding_y
=
padding_y
))
padding_y
=
padding_y
))
],
],
ceil_mode
=
ceil_mode
,
**
ExtraLayerAttribute
.
to_kwargs
(
layer_attr
))
**
ExtraLayerAttribute
.
to_kwargs
(
layer_attr
))
return
LayerOutput
(
return
LayerOutput
(
name
,
name
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录