Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
bda259bb
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
bda259bb
编写于
10月 26, 2016
作者:
W
wangyang59
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added more test on convTrans layer and comments
上级
70e44732
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
144 addition
and
11 deletion
+144
-11
paddle/gserver/layers/ConvTransBaseLayer.cpp
paddle/gserver/layers/ConvTransBaseLayer.cpp
+11
-0
paddle/gserver/layers/ConvTransBaseLayer.h
paddle/gserver/layers/ConvTransBaseLayer.h
+5
-0
paddle/gserver/layers/ExpandConvTransLayer.cpp
paddle/gserver/layers/ExpandConvTransLayer.cpp
+5
-0
paddle/gserver/layers/ExpandConvTransLayer.h
paddle/gserver/layers/ExpandConvTransLayer.h
+1
-1
paddle/gserver/tests/test_ConvTrans.cpp
paddle/gserver/tests/test_ConvTrans.cpp
+114
-2
python/paddle/trainer/config_parser.py
python/paddle/trainer/config_parser.py
+7
-7
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+1
-1
未找到文件。
paddle/gserver/layers/ConvTransBaseLayer.cpp
浏览文件 @
bda259bb
...
...
@@ -23,6 +23,17 @@ bool ConvTransBaseLayer::init(const LayerMap& layerMap,
Layer
::
init
(
layerMap
,
parameterMap
);
/* Initialize the convolutional layer parameter */
/* Everything is the same as ConvBaseLayer.cpp except that the meaning of
* num_filters and channel is switched.
*
* In the config, num_filters refer to the number of feature maps in the
* output of convTransLayer, and channel refer to the number of feature maps
* in the input of convTransLayer.
*
* However, within the convTrans class, the channel is related to the output
* and num_filters is related to the input, so that it is consistent with the
* settings in convLayer.
* */
channel_
=
config_
.
num_filters
();
sharedBiases_
=
config_
.
shared_biases
();
for
(
auto
&
inputConfig
:
config_
.
inputs
())
{
...
...
paddle/gserver/layers/ConvTransBaseLayer.h
浏览文件 @
bda259bb
...
...
@@ -96,6 +96,11 @@ public:
* - outputSize = 5;
*/
/*
* In order to be consistent with the convLayer, here the outputSize is
* actually the size of the input image of convTransLayer, and the image size
* is actually the size of the output image of convTransLayer
*/
int
imageSize
(
int
outputSize
,
int
filterSize
,
int
padding
,
int
stride
)
{
int
imageSize
;
if
(
!
caffeMode_
)
{
...
...
paddle/gserver/layers/ExpandConvTransLayer.cpp
浏览文件 @
bda259bb
...
...
@@ -17,6 +17,11 @@ limitations under the License. */
#include "paddle/utils/Stat.h"
#include "ExpandConvTransLayer.h"
/* The implementation of the convTransLayer is basically a swap of forward and
* backward of the original convLayer.
* The variable naming follows the convention of the convLayer.
* */
namespace
paddle
{
REGISTER_LAYER
(
exconvt
,
ExpandConvTransLayer
);
...
...
paddle/gserver/layers/ExpandConvTransLayer.h
浏览文件 @
bda259bb
...
...
@@ -26,7 +26,7 @@ namespace paddle {
* This layer expands input and use matrix multiplication to
* calculate convolution operation.
*
* The config file api is img_conv_layer.
* The config file api is img_conv
Trans
_layer.
*/
class
ExpandConvTransLayer
:
public
ConvTransBaseLayer
{
protected:
...
...
paddle/gserver/tests/test_ConvTrans.cpp
浏览文件 @
bda259bb
...
...
@@ -33,7 +33,9 @@ P_DECLARE_double(checkgrad_eps);
P_DECLARE_bool
(
thread_local_rand_use_global_seed
);
P_DECLARE_bool
(
prev_batch_state
);
// Test that the convTrans forward is the same as conv backward
TEST
(
Layer
,
convTransLayerFwd
)
{
// Setting up conv-trans layer
TestConfig
configt
;
configt
.
biasSize
=
3
;
configt
.
layerConfig
.
set_type
(
"exconvt"
);
...
...
@@ -68,7 +70,7 @@ TEST(Layer, convTransLayerFwd) {
LayerMap
layerMap
;
vector
<
Argument
>
datas
;
initDataLayer
(
configt
,
&
dataLayers
,
&
datas
,
&
layerMap
,
"convTrans"
,
100
,
false
,
useGpu
);
100
,
false
,
false
);
// test layer initialize
std
::
vector
<
ParameterPtr
>
parameters
;
LayerPtr
convtLayer
;
...
...
@@ -76,6 +78,7 @@ TEST(Layer, convTransLayerFwd) {
convtLayer
->
getBiasParameter
()
->
zeroMem
();
convtLayer
->
forward
(
PASS_GC
);
// Setting up conv-layer config
TestConfig
config
;
config
.
biasSize
=
16
;
config
.
layerConfig
.
set_type
(
"exconv"
);
...
...
@@ -109,16 +112,18 @@ TEST(Layer, convTransLayerFwd) {
LayerMap
layerMap2
;
vector
<
Argument
>
datas2
;
initDataLayer
(
config
,
&
dataLayers2
,
&
datas2
,
&
layerMap2
,
"conv"
,
100
,
false
,
useGpu
);
100
,
false
,
false
);
// test layer initialize
std
::
vector
<
ParameterPtr
>
parameters2
;
LayerPtr
convLayer
;
initTestLayer
(
config
,
&
layerMap2
,
&
parameters2
,
&
convLayer
);
// Sync convLayer and convtLayer parameter
convLayer
->
getBiasParameter
()
->
zeroMem
();
convLayer
->
getParameters
()[
0
]
->
getBuf
(
PARAMETER_VALUE
)
->
copyFrom
(
*
(
convtLayer
->
getParameters
()[
0
]
->
getBuf
(
PARAMETER_VALUE
)));
// Set convLayer outputGrad as convTransLayer input value
convLayer
->
forward
(
PASS_GC
);
convLayer
->
getOutput
().
grad
->
copyFrom
(
*
(
dataLayers
[
0
]
->
getOutputValue
()));
...
...
@@ -126,10 +131,117 @@ TEST(Layer, convTransLayerFwd) {
auto
callback
=
[
&
](
Parameter
*
para
)
{
++
callbackFlags
[
para
->
getID
()];
};
convLayer
->
backward
(
callback
);
// Check that the convLayer backward is the same as convTransLayer forward
checkMatrixEqual
(
convtLayer
->
getOutputValue
(),
dataLayers2
[
0
]
->
getOutputGrad
());
}
// Do one forward pass of convTrans layer and check to see if its output
// matches the given result
void
doOneConvtTest
(
size_t
imgSize
,
size_t
output_x
,
size_t
stride
,
size_t
padding
,
size_t
filter_size
,
MatrixPtr
&
result
)
{
TestConfig
configt
;
configt
.
biasSize
=
1
;
configt
.
layerConfig
.
set_type
(
"exconvt"
);
configt
.
layerConfig
.
set_num_filters
(
1
);
configt
.
layerConfig
.
set_partial_sum
(
1
);
configt
.
layerConfig
.
set_shared_biases
(
true
);
configt
.
inputDefs
.
push_back
({
INPUT_DATA
,
"layer_0"
,
output_x
*
output_x
,
filter_size
*
filter_size
});
LayerInputConfig
*
input
=
configt
.
layerConfig
.
add_inputs
();
ConvConfig
*
conv
=
input
->
mutable_conv_conf
();
conv
->
set_filter_size
(
filter_size
);
conv
->
set_filter_size_y
(
filter_size
);
conv
->
set_channels
(
1
);
conv
->
set_padding
(
padding
);
conv
->
set_padding_y
(
padding
);
conv
->
set_stride
(
stride
);
conv
->
set_stride_y
(
stride
);
conv
->
set_groups
(
1
);
conv
->
set_filter_channels
(
1
);
conv
->
set_img_size
(
imgSize
);
conv
->
set_output_x
(
output_x
);
configt
.
layerConfig
.
set_size
(
conv
->
img_size
()
*
conv
->
img_size
()
*
configt
.
layerConfig
.
num_filters
());
configt
.
layerConfig
.
set_name
(
"convTrans"
);
std
::
vector
<
DataLayerPtr
>
dataLayers
;
LayerMap
layerMap
;
vector
<
Argument
>
datas
;
initDataLayer
(
configt
,
&
dataLayers
,
&
datas
,
&
layerMap
,
"convTrans"
,
1
,
false
,
false
);
dataLayers
[
0
]
->
getOutputValue
()
->
zeroMem
();
dataLayers
[
0
]
->
getOutputValue
()
->
add
(
1.0
);
// test layer initialize
std
::
vector
<
ParameterPtr
>
parameters
;
LayerPtr
convtLayer
;
initTestLayer
(
configt
,
&
layerMap
,
&
parameters
,
&
convtLayer
);
convtLayer
->
getBiasParameter
()
->
zeroMem
();
convtLayer
->
getParameters
()[
0
]
->
zeroMem
();
convtLayer
->
getParameters
()[
0
]
->
getBuf
(
PARAMETER_VALUE
)
->
add
(
1.0
);
convtLayer
->
forward
(
PASS_GC
);
checkMatrixEqual
(
convtLayer
->
getOutputValue
(),
result
);
}
TEST
(
Layer
,
convTransLayerFwd2
)
{
size_t
imgSize
,
output_x
,
stride
,
padding
,
filter_size
;
MatrixPtr
result
;
imgSize
=
5
;
output_x
=
1
;
stride
=
1
;
padding
=
0
;
filter_size
=
5
;
result
=
Matrix
::
create
(
1
,
imgSize
*
imgSize
,
false
,
false
);
result
->
zeroMem
();
result
->
add
(
1.0
);
doOneConvtTest
(
imgSize
,
output_x
,
stride
,
padding
,
filter_size
,
result
);
imgSize
=
5
;
output_x
=
2
;
stride
=
1
;
padding
=
0
;
filter_size
=
4
;
float
resultData
[]
=
{
1
,
2
,
2
,
2
,
1
,
2
,
4
,
4
,
4
,
2
,
2
,
4
,
4
,
4
,
2
,
2
,
4
,
4
,
4
,
2
,
1
,
2
,
2
,
2
,
1
};
result
=
Matrix
::
create
(
resultData
,
1
,
imgSize
*
imgSize
,
false
,
false
);
doOneConvtTest
(
imgSize
,
output_x
,
stride
,
padding
,
filter_size
,
result
);
imgSize
=
5
;
output_x
=
2
;
stride
=
2
;
padding
=
1
;
filter_size
=
5
;
float
resultData2
[]
=
{
1
,
2
,
2
,
2
,
1
,
2
,
4
,
4
,
4
,
2
,
2
,
4
,
4
,
4
,
2
,
2
,
4
,
4
,
4
,
2
,
1
,
2
,
2
,
2
,
1
};
result
=
Matrix
::
create
(
resultData2
,
1
,
imgSize
*
imgSize
,
false
,
false
);
doOneConvtTest
(
imgSize
,
output_x
,
stride
,
padding
,
filter_size
,
result
);
imgSize
=
5
;
output_x
=
2
;
stride
=
2
;
padding
=
0
;
filter_size
=
3
;
float
resultData3
[]
=
{
1
,
1
,
2
,
1
,
1
,
1
,
1
,
2
,
1
,
1
,
2
,
2
,
4
,
2
,
2
,
1
,
1
,
2
,
1
,
1
,
1
,
1
,
2
,
1
,
1
};
result
=
Matrix
::
create
(
resultData3
,
1
,
imgSize
*
imgSize
,
false
,
false
);
doOneConvtTest
(
imgSize
,
output_x
,
stride
,
padding
,
filter_size
,
result
);
}
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
initMain
(
argc
,
argv
);
...
...
python/paddle/trainer/config_parser.py
浏览文件 @
bda259bb
...
...
@@ -1107,7 +1107,7 @@ def parse_conv(conv, input_layer_name, conv_conf):
conv_conf
.
caffe_mode
)
def
parse_convt
(
conv
,
input_layer_name
,
conv_conf
):
def
parse_convt
(
conv
,
input_layer_name
,
conv_conf
,
num_filters
):
conv_conf
.
filter_size
=
conv
.
filter_size
conv_conf
.
filter_size_y
=
conv
.
filter_size_y
conv_conf
.
channels
=
conv
.
channels
...
...
@@ -1116,7 +1116,7 @@ def parse_convt(conv, input_layer_name, conv_conf):
conv_conf
.
stride
=
conv
.
stride
conv_conf
.
stride_y
=
conv
.
stride_y
conv_conf
.
groups
=
conv
.
groups
conv_conf
.
filter_channels
=
conv
.
channel
s
/
conv
.
groups
conv_conf
.
filter_channels
=
num_filter
s
/
conv
.
groups
conv_conf
.
caffe_mode
=
conv
.
caffe_mode
outputSize
=
g_layer_map
[
input_layer_name
].
size
/
conv
.
channels
...
...
@@ -1126,14 +1126,14 @@ def parse_convt(conv, input_layer_name, conv_conf):
config_assert
((
conv_conf
.
output_x
**
2
)
==
outputSize
,
(
"Input layer %s: Incorrect input image size %d for input "
+
"image pixels %d"
)
%
(
input_layer_name
,
conv_conf
.
img_size
,
img_pixels
))
%
(
input_layer_name
,
conv_conf
.
output_x
,
outputSize
))
if
conv
.
caffe_mode
:
conv_conf
.
img_size
=
\
(
conv_conf
.
output_x
-
1
)
*
conv
.
stride
\
+
conv
.
filter_size
-
2
*
conv
.
padding
else
:
conv_conf
.
img_size
=
\
(
conv_conf
.
output_x
-
1
)
*
conv
.
stride
\
(
conv_conf
.
output_x
-
2
)
*
conv
.
stride
\
+
conv
.
filter_size
-
2
*
conv
.
padding
+
1
...
...
@@ -1655,7 +1655,7 @@ class ConvTransLayerBase(LayerBase):
num_filters
=
None
,
shared_biases
=
False
,
**
xargs
):
super
(
ConvLayerBase
,
self
).
__init__
(
super
(
Conv
Trans
LayerBase
,
self
).
__init__
(
name
,
self
.
layer_type
,
0
,
inputs
=
inputs
,
**
xargs
)
if
num_filters
is
not
None
:
...
...
@@ -1686,7 +1686,7 @@ class ConvTransLayerBase(LayerBase):
parse_convt
(
self
.
inputs
[
input_index
].
conv
,
input_layer
.
name
,
self
.
config
.
inputs
[
input_index
].
conv_conf
)
self
.
config
.
inputs
[
input_index
].
conv_conf
,
num_filters
)
conv_conf
=
self
.
config
.
inputs
[
input_index
].
conv_conf
psize
=
self
.
calc_parameter_size
(
conv_conf
)
print
(
"output size for %s is %d "
%
(
name
,
conv_conf
.
output_x
))
...
...
@@ -1700,7 +1700,7 @@ class ConvTransLayerBase(LayerBase):
self
.
create_bias_parameter
(
bias
,
psize
,
[
psize
,
1
])
def
calc_parameter_size
(
self
,
conv_conf
):
return
conv_conf
.
channels
()
*
conv_conf
.
filter_channels
\
return
conv_conf
.
channels
*
conv_conf
.
filter_channels
\
*
(
conv_conf
.
filter_size
*
conv_conf
.
filter_size_y
)
@
config_layer
(
'exconvt'
)
...
...
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
bda259bb
...
...
@@ -36,7 +36,7 @@ __all__ = ["full_matrix_projection", "AggregateLevel", "ExpandLevel",
"pooling_layer"
,
"lstmemory"
,
"last_seq"
,
"first_seq"
,
"cos_sim"
,
"hsigmoid"
,
"conv_projection"
,
"regression_cost"
,
'classification_cost'
,
"LayerOutput"
,
'img_conv_layer'
,
'img_pool_layer'
,
'batch_norm_layer'
,
'img_conv_layer'
,
'img_
convTrans_layer'
,
'img_
pool_layer'
,
'batch_norm_layer'
,
'img_cmrnorm_layer'
,
'addto_layer'
,
'concat_layer'
,
'lstm_step_layer'
,
'recurrent_group'
,
'memory'
,
'StaticInput'
,
'expand_layer'
,
'scaling_layer'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录