Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
cee93468
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cee93468
编写于
12月 15, 2016
作者:
H
hedaoyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add some comments
上级
f13aeb52
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
50 addition
and
16 deletion
+50
-16
paddle/function/cross_map_normal_op.cpp
paddle/function/cross_map_normal_op.cpp
+4
-1
paddle/function/cross_map_normal_op.h
paddle/function/cross_map_normal_op.h
+34
-0
paddle/gserver/layers/Layer.h
paddle/gserver/layers/Layer.h
+6
-0
paddle/gserver/layers/NormProjectionLayer.cpp
paddle/gserver/layers/NormProjectionLayer.cpp
+6
-12
paddle/gserver/layers/NormProjectionLayer.h
paddle/gserver/layers/NormProjectionLayer.h
+0
-3
未找到文件。
paddle/function/cross_map_normal_op.cpp
浏览文件 @
cee93468
...
...
@@ -17,7 +17,6 @@ limitations under the License. */
namespace
paddle
{
// NCHW
template
<
>
void
CrossMapNormal
<
DEVICE_TYPE_CPU
>
(
real
*
outputs
,
real
*
denoms
,
...
...
@@ -36,6 +35,10 @@ void CrossMapNormal<DEVICE_TYPE_CPU>(real* outputs,
CpuVector
inputsV
(
numSamples
*
oneSample
,
inputs
);
CpuVector
denomsV
(
numSamples
*
oneSample
,
denoms
);
// f(x) = x * ( 1 + scale * SUM((x)^2) )^(-pow)
// x represents inputs
// f(x) represents outputs
// denoms save the intermediate result for backward
denomsV
=
denomsV
.
constant
(
1.0
);
const
int
start
=
-
((
int
)
size
-
1
)
/
2
;
const
int
end
=
(
int
)
size
+
start
;
...
...
paddle/function/cross_map_normal_op.h
浏览文件 @
cee93468
...
...
@@ -18,6 +18,22 @@ limitations under the License. */
namespace
paddle
{
/**
* \brief Cross map respose normalize forward.
* The data structure of image data is NCHW.
*
* \param[out] outputs output data.
* \param[in] denoms denoms buffer.
* \param[in] inputs input data.
* \param[in] numSamples batch size of input image.
* \param[in] channels number of channel.
* \param[in] height image height.
* \param[in] width image width.
* \param[in] size size.
* \param[in] scale scale.
* \param[in] pow scale.
*
*/
template
<
DeviceType
Device
>
void
CrossMapNormal
(
real
*
outputs
,
real
*
denoms
,
...
...
@@ -30,6 +46,24 @@ void CrossMapNormal(real* outputs,
real
scale
,
real
pow
);
/**
* \brief Cross map respose normalize backward.
* The data structure of image data is NCHW.
*
* \param[out] inputsGrad input grad.
* \param[in] inputsValue input value.
* \param[out] outputsValue output value.
* \param[out] outputsGrad output grad.
* \param[in] denoms denoms buffer.
* \param[in] numSamples batch size of input image.
* \param[in] channels number of channel.
* \param[in] height image height.
* \param[in] width image width.
* \param[in] size size.
* \param[in] scale scale.
* \param[in] pow scale.
*
*/
template
<
DeviceType
Device
>
void
CrossMapNormalGrad
(
real
*
inputsGrad
,
real
*
inputsValue
,
...
...
paddle/gserver/layers/Layer.h
浏览文件 @
cee93468
...
...
@@ -18,6 +18,7 @@ limitations under the License. */
#include <functional>
#include <memory>
#include "ModelConfig.pb.h"
#include "paddle/function/Function.h"
#include "paddle/math/CpuSparseMatrix.h"
#include "paddle/parameter/Parameter.h"
#include "paddle/utils/ClassRegistrar.h"
...
...
@@ -100,6 +101,11 @@ protected:
/// Mark input grad in(true) or out(false) of backward function.
std
::
vector
<
bool
>
markInBackward_
;
/// Layer forward function
FunctionBase
*
forward_
;
/// Layer backward function
FunctionBase
*
backward_
;
public:
/**
* Wait until all input value ready.
...
...
paddle/gserver/layers/NormProjectionLayer.cpp
浏览文件 @
cee93468
...
...
@@ -48,20 +48,17 @@ bool CMRProjectionNormLayer::init(const LayerMap& layerMap,
if
(
useGpu_
)
{
forward_
=
FunctionBase
::
funcRegistrar_
.
createByType
(
FUNC_NAME
(
CrossMapNormal
,
GPU
));
backward_
=
FunctionBase
::
funcRegistrar_
.
createByType
(
FUNC_NAME
(
CrossMapNormalGrad
,
GPU
));
}
else
{
forward_
=
FunctionBase
::
funcRegistrar_
.
createByType
(
FUNC_NAME
(
CrossMapNormal
,
CPU
));
backward_
=
FunctionBase
::
funcRegistrar_
.
createByType
(
FUNC_NAME
(
CrossMapNormalGrad
,
CPU
));
}
forward_
->
init
(
FuncConfig
().
set
(
"size"
,
size_
).
set
(
"scale"
,
scale_
).
set
(
"pow"
,
pow_
));
if
(
useGpu_
)
{
backward_
=
FunctionBase
::
funcRegistrar_
.
createByType
(
FUNC_NAME
(
CrossMapNormalGrad
,
GPU
));
}
else
{
backward_
=
FunctionBase
::
funcRegistrar_
.
createByType
(
FUNC_NAME
(
CrossMapNormalGrad
,
CPU
));
}
backward_
->
init
(
FuncConfig
().
set
(
"size"
,
size_
).
set
(
"scale"
,
scale_
).
set
(
"pow"
,
pow_
));
...
...
@@ -74,7 +71,7 @@ void CMRProjectionNormLayer::forward(PassType passType) {
/* malloc memory for the output_ if necessary */
/* note: one sample correspond to one row */
MatrixPtr
input
=
inputLayers_
[
0
]
->
getOutputValue
();
in
t
batchSize
=
input
->
getHeight
();
size_
t
batchSize
=
input
->
getHeight
();
int
size
=
getSize
();
resetOutput
(
batchSize
,
size
);
...
...
@@ -82,10 +79,7 @@ void CMRProjectionNormLayer::forward(PassType passType) {
Matrix
::
resizeOrCreate
(
denoms_
,
batchSize
,
size
,
/* trans */
false
,
useGpu_
);
dims_
=
{(
size_t
)
batchSize
,
(
size_t
)
channels_
,
(
size_t
)
imgSizeH_
,
(
size_t
)
imgSizeW_
};
dims_
=
{
batchSize
,
channels_
,
imgSizeH_
,
imgSizeW_
};
forward_
->
calc
(
{
Tensor
(
input
->
getData
(),
dims_
)},
{
Tensor
(
outV
->
getData
(),
dims_
),
Tensor
(
denoms_
->
getData
(),
dims_
)},
...
...
paddle/gserver/layers/NormProjectionLayer.h
浏览文件 @
cee93468
...
...
@@ -16,7 +16,6 @@ limitations under the License. */
#include <vector>
#include "NormLayer.h"
#include "paddle/function/Function.h"
#include "paddle/math/Matrix.h"
namespace
paddle
{
...
...
@@ -43,7 +42,5 @@ public:
protected:
Dims
dims_
;
FunctionBase
*
forward_
;
FunctionBase
*
backward_
;
};
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录