Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
17e16c25
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
17e16c25
编写于
8月 02, 2017
作者:
G
guosheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine RowL2NormLayer and add python unit test for it
上级
84660653
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
55 addition
and
18 deletion
+55
-18
doc/api/v2/config/layer.rst
doc/api/v2/config/layer.rst
+5
-0
paddle/gserver/layers/RowL2NormLayer.cpp
paddle/gserver/layers/RowL2NormLayer.cpp
+12
-13
python/paddle/trainer/config_parser.py
python/paddle/trainer/config_parser.py
+4
-4
python/paddle/trainer_config_helpers/tests/configs/file_list.sh
.../paddle/trainer_config_helpers/tests/configs/file_list.sh
+1
-1
python/paddle/trainer_config_helpers/tests/configs/protostr/test_row_l2_norm_layer.protostr
...rs/tests/configs/protostr/test_row_l2_norm_layer.protostr
+27
-0
python/paddle/trainer_config_helpers/tests/configs/test_row_l2_norm_layer.py
...er_config_helpers/tests/configs/test_row_l2_norm_layer.py
+6
-0
未找到文件。
doc/api/v2/config/layer.rst
浏览文件 @
17e16c25
...
...
@@ -104,6 +104,11 @@ cross_channel_norm
------------------
.. autoclass:: paddle.v2.layer.cross_channel_norm
:noindex:
row_l2_norm
-----------
.. autoclass:: paddle.v2.layer.row_l2_norm
:noindex:
Recurrent Layers
================
...
...
paddle/gserver/layers/RowL2NormLayer.cpp
浏览文件 @
17e16c25
...
...
@@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "Layer.h"
#include "paddle/math/Matrix.h"
namespace
paddle
{
...
...
@@ -29,7 +28,7 @@ namespace paddle {
class
RowL2NormLayer
:
public
Layer
{
protected:
MatrixPtr
inSquare_
;
MatrixPtr
reciSqrtRowSquareSum
_
;
MatrixPtr
l2NormReciprocal
_
;
MatrixPtr
dotSum_
;
public:
...
...
@@ -67,11 +66,11 @@ void RowL2NormLayer::forward(PassType passType) {
Matrix
::
resizeOrCreate
(
inSquare_
,
batchSize
,
dataDim
,
false
,
useGpu_
);
inV
->
square2
(
*
inSquare_
);
Matrix
::
resizeOrCreate
(
reciSqrtRowSquareSum
_
,
batchSize
,
1
,
false
,
useGpu_
);
inSquare_
->
rowSum
(
*
reciSqrtRowSquareSum
_
);
reciSqrtRowSquareSum_
->
sqrt2
(
*
reciSqrtRowSquareSum
_
);
reciSqrtRowSquareSum_
->
scalarDiv
(
*
reciSqrtRowSquareSum
_
,
1.0
);
outV
->
rowScale
(
0
,
*
inV
,
*
reciSqrtRowSquareSum
_
);
Matrix
::
resizeOrCreate
(
l2NormReciprocal
_
,
batchSize
,
1
,
false
,
useGpu_
);
inSquare_
->
rowSum
(
*
l2NormReciprocal
_
);
l2NormReciprocal_
->
sqrt2
(
*
l2NormReciprocal
_
);
l2NormReciprocal_
->
scalarDiv
(
*
l2NormReciprocal
_
,
1.0
);
outV
->
rowScale
(
0
,
*
inV
,
*
l2NormReciprocal
_
);
}
void
RowL2NormLayer
::
backward
(
const
UpdateCallback
&
callback
)
{
...
...
@@ -81,18 +80,18 @@ void RowL2NormLayer::backward(const UpdateCallback& callback) {
MatrixPtr
outG
=
getOutputGrad
();
size_t
batchSize
=
inV
->
getHeight
();
// inG[ij] += outG[ij] /
reciSqrtRowSquareSum
// inG[ij] += -inV[ij] *
reciSqrtRowSquareSum * reciSqrtRowSquareSum *
//
DotMul(outG[i],
inV[i])
// inG[ij] += outG[ij] /
l2NormReciprocal
// inG[ij] += -inV[ij] *
l2NormReciprocal * l2NormReciprocal * DotMul(outG[i],
// inV[i])
if
(
inG
)
{
Matrix
::
resizeOrCreate
(
dotSum_
,
batchSize
,
1
,
false
,
useGpu_
);
dotSum_
->
zeroMem
();
dotSum_
->
rowDotMul
(
0
,
*
outG
,
*
outV
);
dotSum_
->
dotMul
(
*
dotSum_
,
*
reciSqrtRowSquareSum
_
);
dotSum_
->
dotMul
(
*
dotSum_
,
*
reciSqrtRowSquareSum
_
);
dotSum_
->
dotMul
(
*
dotSum_
,
*
l2NormReciprocal
_
);
dotSum_
->
dotMul
(
*
dotSum_
,
*
l2NormReciprocal
_
);
inSquare_
->
rowScale
(
0
,
*
inV
,
*
dotSum_
);
inG
->
sub
(
*
inSquare_
);
inG
->
addRowScale
(
0
,
*
outG
,
*
reciSqrtRowSquareSum
_
);
inG
->
addRowScale
(
0
,
*
outG
,
*
l2NormReciprocal
_
);
}
}
...
...
python/paddle/trainer/config_parser.py
浏览文件 @
17e16c25
...
...
@@ -2727,12 +2727,12 @@ class SumToOneNormLayer(LayerBase):
@
config_layer
(
'row_l2_norm'
)
class
RowL2NormLayer
(
LayerBase
):
def
__init__
(
self
,
name
,
inputs
,
device
=
None
):
def
__init__
(
self
,
name
,
inputs
,
**
xargs
):
super
(
RowL2NormLayer
,
self
).
__init__
(
name
,
'row_l2_norm'
,
0
,
inputs
=
inputs
,
device
=
device
)
name
,
'row_l2_norm'
,
0
,
inputs
=
inputs
,
**
xargs
)
config_assert
(
len
(
self
.
inputs
)
==
1
,
'RowL2NormLayer must have 1 input'
)
input_layer
0
=
self
.
get_input_layer
(
0
)
self
.
set_layer_size
(
input_layer
0
.
size
)
input_layer
=
self
.
get_input_layer
(
0
)
self
.
set_layer_size
(
input_layer
.
size
)
@
config_layer
(
'cos_vm'
)
...
...
python/paddle/trainer_config_helpers/tests/configs/file_list.sh
浏览文件 @
17e16c25
...
...
@@ -7,6 +7,6 @@ test_rnn_group shared_fc shared_lstm shared_gru test_cost_layers_with_weight
test_spp_layer test_bilinear_interp test_maxout test_bi_grumemory math_ops
test_seq_concat_reshape test_pad test_smooth_l1 test_multiplex_layer
test_prelu_layer test_row_conv test_detection_output_layer test_multibox_loss_layer
test_recursive_topology test_gated_unit_layer
)
test_recursive_topology test_gated_unit_layer
test_row_l2_norm_layer
)
export
whole_configs
=(
test_split_datasource
)
python/paddle/trainer_config_helpers/tests/configs/protostr/test_row_l2_norm_layer.protostr
0 → 100644
浏览文件 @
17e16c25
type: "nn"
layers {
name: "input"
type: "data"
size: 300
active_type: ""
}
layers {
name: "__row_l2_norm_layer_0__"
type: "row_l2_norm"
size: 300
active_type: ""
inputs {
input_layer_name: "input"
}
}
input_layer_names: "input"
output_layer_names: "__row_l2_norm_layer_0__"
sub_models {
name: "root"
layer_names: "input"
layer_names: "__row_l2_norm_layer_0__"
input_layer_names: "input"
output_layer_names: "__row_l2_norm_layer_0__"
is_recurrent_layer_group: false
}
python/paddle/trainer_config_helpers/tests/configs/test_row_l2_norm_layer.py
0 → 100644
浏览文件 @
17e16c25
from
paddle.trainer_config_helpers
import
*
data
=
data_layer
(
name
=
'input'
,
size
=
300
)
row_l2_norm
=
row_l2_norm_layer
(
input
=
data
)
outputs
(
row_l2_norm
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录