Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
199a6a4b
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
199a6a4b
编写于
10月 10, 2016
作者:
L
luotao1
提交者:
Yu Yang
10月 10, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add weight for cost layer interface (#177)
上级
86bb5ef1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
51 addition
and
10 deletion
+51
-10
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+35
-9
python/paddle/trainer_config_helpers/tests/configs/check.md5
python/paddle/trainer_config_helpers/tests/configs/check.md5
+1
-0
python/paddle/trainer_config_helpers/tests/configs/generate_protostr.sh
...trainer_config_helpers/tests/configs/generate_protostr.sh
+1
-1
python/paddle/trainer_config_helpers/tests/configs/test_cost_layers_with_weight.py
...fig_helpers/tests/configs/test_cost_layers_with_weight.py
+14
-0
未找到文件。
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
199a6a4b
...
...
@@ -2777,29 +2777,49 @@ def beam_search(step, input, bos_id, eos_id, beam_size,
return
tmp
def
__cost_input__
(
input
,
label
,
weight
=
None
):
"""
inputs and parents for cost layers.
"""
ipts
=
[
Input
(
input
.
name
),
Input
(
label
.
name
)]
parents
=
[
input
,
label
]
if
weight
is
not
None
:
assert
weight
.
layer_type
==
LayerType
.
DATA
ipts
.
append
(
Input
(
weight
.
name
))
parents
.
append
(
weight
)
return
ipts
,
parents
@
wrap_name_default
()
def
regression_cost
(
input
,
label
,
cost
=
'square_error'
,
name
=
None
):
def
regression_cost
(
input
,
label
,
weight
=
None
,
cost
=
'square_error'
,
name
=
None
):
"""
Regression Layer.
TODO(yuyang18): Complete this method.
:param name: layer name.
:type name: basestring
:param input: Network prediction.
:type input: LayerOutput
:param label: Data label.
:type label: LayerOutput
:param weight: The weight affects the cost, namely the scale of cost.
It is an optional argument.
:type weight: LayerOutput
:param cost: Cost method.
:type cost: basestring
:return: LayerOutput object.
:rtype: LayerOutput
"""
Layer
(
inputs
=
[
Input
(
input
.
name
),
Input
(
label
.
name
)],
type
=
cost
,
name
=
name
)
return
LayerOutput
(
name
,
LayerType
.
COST
,
parents
=
[
input
,
label
]
)
ipts
,
parents
=
__cost_input__
(
input
,
label
,
weight
)
Layer
(
inputs
=
ipts
,
type
=
cost
,
name
=
name
)
return
LayerOutput
(
name
,
LayerType
.
COST
,
parents
=
parents
)
@
wrap_name_default
(
"cost"
)
@
layer_support
()
def
classification_cost
(
input
,
label
,
name
=
None
,
def
classification_cost
(
input
,
label
,
weight
=
None
,
name
=
None
,
cost
=
"multi-class-cross-entropy"
,
evaluator
=
classification_error_evaluator
,
layer_attr
=
None
):
...
...
@@ -2812,6 +2832,9 @@ def classification_cost(input, label, name=None,
:type input: LayerOutput
:param label: label layer name. data_layer often.
:type label: LayerOutput
:param weight: The weight affects the cost, namely the scale of cost.
It is an optional argument.
:type weight: LayerOutput
:param cost: cost method.
:type cost: basestring
:param evaluator: Evaluator method.
...
...
@@ -2823,7 +2846,10 @@ def classification_cost(input, label, name=None,
assert
input
.
layer_type
!=
LayerType
.
DATA
assert
isinstance
(
input
.
activation
,
SoftmaxActivation
)
assert
label
.
layer_type
==
LayerType
.
DATA
Layer
(
name
=
name
,
type
=
cost
,
inputs
=
[
Input
(
input
.
name
),
Input
(
label
.
name
)],
ipts
,
parents
=
__cost_input__
(
input
,
label
,
weight
)
Layer
(
name
=
name
,
type
=
cost
,
inputs
=
ipts
,
**
ExtraLayerAttribute
.
to_kwargs
(
layer_attr
))
def
__add_evaluator__
(
e
):
...
...
@@ -2835,7 +2861,7 @@ def classification_cost(input, label, name=None,
assert
isinstance
(
e
.
for_classification
,
bool
)
assert
e
.
for_classification
e
(
name
=
e
.
__name__
,
input
=
input
,
label
=
label
)
e
(
name
=
e
.
__name__
,
input
=
input
,
label
=
label
,
weight
=
weight
)
if
not
isinstance
(
evaluator
,
collections
.
Sequence
):
evaluator
=
[
evaluator
]
...
...
@@ -2843,7 +2869,7 @@ def classification_cost(input, label, name=None,
for
each_evaluator
in
evaluator
:
__add_evaluator__
(
each_evaluator
)
return
LayerOutput
(
name
,
LayerType
.
COST
,
parents
=
[
input
,
label
]
)
return
LayerOutput
(
name
,
LayerType
.
COST
,
parents
=
parents
)
def
conv_operator
(
img
,
filter
,
filter_size
,
num_filters
,
...
...
python/paddle/trainer_config_helpers/tests/configs/check.md5
浏览文件 @
199a6a4b
...
...
@@ -4,6 +4,7 @@ a5d9259ff1fd7ca23d0ef090052cb1f2 last_first_seq.protostr
5913f87b39cee3b2701fa158270aca26 projections.protostr
6b39e34beea8dfb782bee9bd3dea9eb5 simple_rnn_layers.protostr
0fc1409600f1a3301da994ab9d28b0bf test_cost_layers.protostr
6cd5f28a3416344f20120698470e0a4c test_cost_layers_with_weight.protostr
144bc6d3a509de74115fa623741797ed test_expand_layer.protostr
2378518bdb71e8c6e888b1842923df58 test_fc.protostr
8bb44e1e5072d0c261572307e7672bda test_grumemory_layer.protostr
...
...
python/paddle/trainer_config_helpers/tests/configs/generate_protostr.sh
浏览文件 @
199a6a4b
...
...
@@ -8,7 +8,7 @@ configs=(test_fc layer_activations projections test_print_layer
test_sequence_pooling test_lstmemory_layer test_grumemory_layer
last_first_seq test_expand_layer test_ntm_layers test_hsigmoid
img_layers util_layers simple_rnn_layers unused_layers test_cost_layers
test_rnn_group
)
test_
cost_layers_with_weight test_
rnn_group
)
for
conf
in
${
configs
[*]
}
...
...
python/paddle/trainer_config_helpers/tests/configs/test_cost_layers_with_weight.py
0 → 100644
浏览文件 @
199a6a4b
from
paddle.trainer_config_helpers
import
*
settings
(
learning_rate
=
1e-4
,
batch_size
=
1000
)
data
=
data_layer
(
name
=
'input'
,
size
=
300
)
lbl
=
data_layer
(
name
=
'label'
,
size
=
1
)
wt
=
data_layer
(
name
=
'weight'
,
size
=
1
)
fc
=
fc_layer
(
input
=
data
,
size
=
10
,
act
=
SoftmaxActivation
())
outputs
(
classification_cost
(
input
=
fc
,
label
=
lbl
,
weight
=
wt
),
regression_cost
(
input
=
fc
,
label
=
lbl
,
weight
=
wt
))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录