Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
7aac38c7
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看板
提交
7aac38c7
编写于
6月 06, 2017
作者:
H
hedaoyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactoring the code implementation of exconv adn exconvt layer with GemmConvFunction.
上级
9885c578
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
98 addition
and
29 deletion
+98
-29
paddle/gserver/layers/ConvBaseLayer.cpp
paddle/gserver/layers/ConvBaseLayer.cpp
+1
-5
paddle/gserver/layers/CudnnConvBaseLayer.cpp
paddle/gserver/layers/CudnnConvBaseLayer.cpp
+2
-8
paddle/gserver/layers/ExpandConvLayer.cpp
paddle/gserver/layers/ExpandConvLayer.cpp
+89
-15
paddle/gserver/layers/ExpandConvLayer.h
paddle/gserver/layers/ExpandConvLayer.h
+5
-0
paddle/gserver/layers/ExpandConvTransLayer.cpp
paddle/gserver/layers/ExpandConvTransLayer.cpp
+1
-1
未找到文件。
paddle/gserver/layers/ConvBaseLayer.cpp
浏览文件 @
7aac38c7
...
...
@@ -118,11 +118,7 @@ size_t ConvBaseLayer::calOutputSize() {
layerSize
=
outH
[
0
]
*
outW
[
0
]
*
size_t
(
numFilters_
);
};
if
(
isDeconv_
)
{
setLayerSize
(
outputH_
,
outputW_
,
imgSizeH_
,
imgSizeW_
);
}
else
{
setLayerSize
(
imgSizeH_
,
imgSizeW_
,
outputH_
,
outputW_
);
}
return
layerSize
;
}
...
...
paddle/gserver/layers/CudnnConvBaseLayer.cpp
浏览文件 @
7aac38c7
...
...
@@ -70,14 +70,8 @@ void CudnnConvBaseLayer::forward(PassType passType) {
if
(
biases_
)
{
REGISTER_TIMER_INFO
(
"CudnnConvBiasTimer"
,
getName
().
c_str
());
int
batchSize
=
inputLayers_
[
0
]
->
getOutputValue
()
->
getHeight
();
int
outH
,
outW
;
if
(
isDeconv_
)
{
outH
=
imgSizeH_
[
0
];
outW
=
imgSizeW_
[
0
];
}
else
{
outH
=
outputH_
[
0
];
outW
=
outputW_
[
0
];
}
int
outH
=
outputH_
[
0
];
int
outW
=
outputW_
[
0
];
hl_tensor_reshape
(
outputDesc_
,
batchSize
,
...
...
paddle/gserver/layers/ExpandConvLayer.cpp
浏览文件 @
7aac38c7
...
...
@@ -18,32 +18,90 @@ limitations under the License. */
namespace
paddle
{
/*
* The calculation of the exconvt(convolution transpose (deconv) operation)
* is a swap of forward and backward of the calculation of exconv.
* */
REGISTER_LAYER
(
exconv
,
ExpandConvLayer
);
REGISTER_LAYER
(
exconvt
,
ExpandConvLayer
);
bool
ExpandConvLayer
::
init
(
const
LayerMap
&
layerMap
,
const
ParameterMap
&
parameterMap
)
{
/* Initialize the basic convolutional parent class */
ExpandConvBaseLayer
::
init
(
layerMap
,
parameterMap
);
size_t
numInputs
=
config_
.
inputs_size
();
inputShape_
.
resize
(
numInputs
);
filterShape_
.
resize
(
numInputs
);
outputShape_
.
resize
(
numInputs
);
for
(
int
i
=
0
;
i
<
config_
.
inputs_size
();
i
++
)
{
std
::
vector
<
size_t
>
paddings
=
{(
size_t
)
paddingY_
[
i
],
(
size_t
)
padding_
[
i
]};
std
::
vector
<
size_t
>
strides
=
{(
size_t
)
strideY_
[
i
],
(
size_t
)
stride_
[
i
]};
createFunction
(
forward_
,
!
isDeconv_
?
"GemmConv"
:
"GemmConvGradInput"
,
FuncConfig
()
.
set
(
"paddings"
,
paddings
)
.
set
(
"strides"
,
strides
)
.
set
(
"groups"
,
(
size_t
)
groups_
[
i
]));
createFunction
(
backward_
,
!
isDeconv_
?
"GemmConvGradInput"
:
"GemmConv"
,
FuncConfig
()
.
set
(
"paddings"
,
paddings
)
.
set
(
"strides"
,
strides
)
.
set
(
"groups"
,
(
size_t
)
groups_
[
i
]));
createFunction
(
backward_
,
"GemmConvGradFilter"
,
FuncConfig
()
.
set
(
"paddings"
,
paddings
)
.
set
(
"strides"
,
strides
)
.
set
(
"groups"
,
(
size_t
)
groups_
[
i
]));
}
return
true
;
}
// i is the index of input layers
#define BACKWARD_INPUT(i, inputs, outputs) \
backward_[2 * i]->calc(inputs, outputs)
#define BACKWARD_FILTER(i, inputs, outputs) \
backward_[2 * i + 1]->calc(inputs, outputs)
void
ExpandConvLayer
::
forward
(
PassType
passType
)
{
Layer
::
forward
(
passType
);
/* malloc memory for the output_ if necessary */
int
batchSize
=
inputLayers_
[
0
]
->
getOutputValue
()
->
getHeight
();
size_t
batchSize
=
inputLayers_
[
0
]
->
getOutputValue
()
->
getHeight
();
resetOutput
(
batchSize
,
getOutputSize
());
MatrixPtr
image
=
nullptr
;
MatrixPtr
outV
=
getOutputValue
();
// Calculate the shape of the input, output, and filter.
for
(
size_t
i
=
0
;
i
<
inputLayers_
.
size
();
++
i
)
{
LayerPtr
prevLayer
=
getPrev
(
i
);
image
=
prevLayer
->
getOutputValue
();
for
(
size_t
off
=
0
;
off
<
image
->
getHeight
();
off
++
)
{
REGISTER_TIMER_INFO
(
"expandFwdOnce"
,
getName
().
c_str
());
expandFwdOnce
(
image
,
outV
,
i
,
off
);
inputShape_
[
i
]
=
TensorShape
({(
size_t
)
batchSize
,
(
size_t
)
channels_
[
i
],
(
size_t
)
imgSizeH_
[
i
],
(
size_t
)
imgSizeW_
[
i
]});
filterShape_
[
i
]
=
TensorShape
({
!
isDeconv_
?
(
size_t
)
numFilters_
:
(
size_t
)
channels_
[
i
],
!
isDeconv_
?
(
size_t
)
channels_
[
i
]
:
(
size_t
)
numFilters_
,
(
size_t
)
filterSizeY_
[
i
],
(
size_t
)
filterSize_
[
i
]});
outputShape_
[
i
]
=
TensorShape
({(
size_t
)
batchSize
,
(
size_t
)
numFilters_
,
(
size_t
)
outputH_
[
i
],
(
size_t
)
outputW_
[
i
]});
}
// Calculate the output value.
for
(
size_t
i
=
0
;
i
<
inputLayers_
.
size
();
++
i
)
{
BufferArgs
inputs
;
BufferArgs
outputs
;
inputs
.
addArg
(
*
getInputValue
(
i
),
inputShape_
[
i
]);
inputs
.
addArg
(
*
weights_
[
i
]
->
getW
(),
filterShape_
[
i
]);
outputs
.
addArg
(
*
getOutputValue
(),
outputShape_
[
i
],
i
==
0
?
ASSIGN_TO
:
ADD_TO
);
forward_
[
i
]
->
calc
(
inputs
,
outputs
);
}
/* add the bias-vector */
if
(
biases_
.
get
())
{
if
(
sharedBiases_
)
{
...
...
@@ -67,14 +125,30 @@ void ExpandConvLayer::backward(const UpdateCallback &callback) {
biases_
->
getParameterPtr
()
->
incUpdate
(
callback
);
}
// Calculate the input grad and filter grad.
for
(
size_t
i
=
0
;
i
<
inputLayers_
.
size
();
++
i
)
{
/* First, calculate the input layers error */
if
(
getPrev
(
i
)
->
getOutputGrad
())
{
bpropActs
(
outGrad
,
getPrev
(
i
)
->
getOutputGrad
(),
i
);
if
(
getInputGrad
(
i
))
{
BufferArgs
inputs
;
BufferArgs
outputs
;
inputs
.
addArg
(
*
getOutputGrad
(),
outputShape_
[
i
]);
inputs
.
addArg
(
*
weights_
[
i
]
->
getW
(),
filterShape_
[
i
]);
outputs
.
addArg
(
*
getInputGrad
(
i
),
inputShape_
[
i
],
ADD_TO
);
BACKWARD_INPUT
(
i
,
inputs
,
outputs
);
}
if
(
weights_
[
i
]
->
getWGrad
())
{
/* Then, calculate the W-gradient for the current layer */
bpropWeights
(
getPrev
(
i
)
->
getOutputValue
(),
outGrad
,
i
);
BufferArgs
inputs
;
BufferArgs
outputs
;
if
(
!
isDeconv_
)
{
inputs
.
addArg
(
*
getOutputGrad
(),
outputShape_
[
i
]);
inputs
.
addArg
(
*
getInputValue
(
i
),
inputShape_
[
i
]);
}
else
{
inputs
.
addArg
(
*
getInputValue
(
i
),
inputShape_
[
i
]);
inputs
.
addArg
(
*
getOutputGrad
(),
outputShape_
[
i
]);
}
outputs
.
addArg
(
*
weights_
[
i
]
->
getWGrad
(),
filterShape_
[
i
],
ADD_TO
);
BACKWARD_FILTER
(
i
,
inputs
,
outputs
);
/* Increasing the number of gradient */
weights_
[
i
]
->
getParameterPtr
()
->
incUpdate
(
callback
);
}
...
...
paddle/gserver/layers/ExpandConvLayer.h
浏览文件 @
7aac38c7
...
...
@@ -40,6 +40,11 @@ public:
void
forward
(
PassType
passType
)
override
;
void
backward
(
const
UpdateCallback
&
callback
)
override
;
protected:
std
::
vector
<
TensorShape
>
inputShape_
;
std
::
vector
<
TensorShape
>
filterShape_
;
std
::
vector
<
TensorShape
>
outputShape_
;
};
}
// namespace paddle
paddle/gserver/layers/ExpandConvTransLayer.cpp
浏览文件 @
7aac38c7
...
...
@@ -23,7 +23,7 @@ limitations under the License. */
namespace
paddle
{
REGISTER_LAYER
(
exconvt
,
ExpandConvTransLayer
);
//
REGISTER_LAYER(exconvt, ExpandConvTransLayer);
bool
ExpandConvTransLayer
::
init
(
const
LayerMap
&
layerMap
,
const
ParameterMap
&
parameterMap
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录