Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
e8be42fc
P
Paddle
项目概览
机器未来
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e8be42fc
编写于
2月 22, 2017
作者:
T
Tao Luo
提交者:
GitHub
2月 22, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1416 from luotao1/v2
add cost function in v2.layer
上级
5a1d9263
e19134e0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
45 addition
and
8 deletion
+45
-8
python/paddle/v2/layer.py
python/paddle/v2/layer.py
+45
-8
未找到文件。
python/paddle/v2/layer.py
浏览文件 @
e8be42fc
...
...
@@ -77,7 +77,9 @@ import data_type
__all__
=
[
'parse_network'
,
'data'
,
'fc'
,
'max_id'
,
'classification_cost'
,
'cross_entropy_cost'
'cross_entropy_cost'
,
'cross_entropy_with_selfnorm_cost'
,
'regression_cost'
,
'multi_binary_label_cross_entropy_cost'
,
'rank_cost'
,
'lambda_cost'
,
'sum_cost'
,
'huber_cost'
]
...
...
@@ -137,7 +139,8 @@ def __convert_to_v2__(method_name, name_prefix, parent_names):
parent_layers
=
dict
()
other_kwargs
=
dict
()
for
pname
in
parent_names
:
parent_layers
[
pname
]
=
kwargs
[
pname
]
if
kwargs
.
has_key
(
pname
):
parent_layers
[
pname
]
=
kwargs
[
pname
]
for
key
in
kwargs
.
keys
():
if
key
not
in
parent_names
:
...
...
@@ -189,27 +192,61 @@ class DataLayerV2(Layer):
data
=
DataLayerV2
fc
=
__convert_to_v2__
(
'fc_layer'
,
name_prefix
=
'fc'
,
parent_names
=
[
'input'
])
max_id
=
__convert_to_v2__
(
'maxid_layer'
,
name_prefix
=
'maxid
_layer
'
,
parent_names
=
[
'input'
])
'maxid_layer'
,
name_prefix
=
'maxid'
,
parent_names
=
[
'input'
])
classification_cost
=
__convert_to_v2__
(
'classification_cost'
,
name_prefix
=
'classification_cost'
,
parent_names
=
[
'input'
,
'label'
])
parent_names
=
[
'input'
,
'label'
,
'weight'
])
regression_cost
=
__convert_to_v2__
(
'regression_cost'
,
name_prefix
=
'regression_cost'
,
parent_names
=
[
'input'
,
'label'
,
'weight'
])
cross_entropy_cost
=
__convert_to_v2__
(
'cross_entropy'
,
name_prefix
=
'cross_entropy'
,
parent_names
=
[
'input'
,
'label'
])
cross_entropy_with_selfnorm_cost
=
__convert_to_v2__
(
'cross_entropy_with_selfnorm'
,
name_prefix
=
'cross_entropy_with_selfnorm'
,
parent_names
=
[
'input'
,
'label'
])
multi_binary_label_cross_entropy_cost
=
__convert_to_v2__
(
'multi_binary_label_cross_entropy'
,
name_prefix
=
'multi_binary_label_cross_entropy'
,
parent_names
=
[
'input'
,
'label'
])
rank_cost
=
__convert_to_v2__
(
'rank_cost'
,
name_prefix
=
'rank_cost'
,
parent_names
=
[
'left'
,
'right'
,
'label'
,
'weight'
])
lambda_cost
=
__convert_to_v2__
(
'lambda_cost'
,
name_prefix
=
'lambda_cost'
,
parent_names
=
[
'input'
,
'score'
])
sum_cost
=
__convert_to_v2__
(
'sum_cost'
,
name_prefix
=
'sum_cost'
,
parent_names
=
[
'input'
])
huber_cost
=
__convert_to_v2__
(
'huber_cost'
,
name_prefix
=
'huber_cost'
,
parent_names
=
[
'input'
,
'label'
])
if
__name__
==
'__main__'
:
pixel
=
data
(
name
=
'pixel'
,
type
=
data_type
.
dense_vector
(
784
))
label
=
data
(
name
=
'label'
,
type
=
data_type
.
integer_value
(
10
))
weight
=
data
(
name
=
'weight'
,
type
=
data_type
.
dense_vector
(
10
))
score
=
data
(
name
=
'score'
,
type
=
data_type
.
dense_vector
(
1
))
hidden
=
fc
(
input
=
pixel
,
size
=
100
,
act
=
conf_helps
.
SigmoidActivation
())
inference
=
fc
(
input
=
hidden
,
size
=
10
,
act
=
conf_helps
.
SoftmaxActivation
())
maxid
=
max_id
(
input
=
inference
)
cost1
=
classification_cost
(
input
=
inference
,
label
=
label
)
cost2
=
cross_entropy_cost
(
input
=
inference
,
label
=
label
)
cost2
=
classification_cost
(
input
=
inference
,
label
=
label
,
weight
=
weight
)
cost3
=
cross_entropy_cost
(
input
=
inference
,
label
=
label
)
cost4
=
cross_entropy_with_selfnorm_cost
(
input
=
inference
,
label
=
label
)
cost5
=
regression_cost
(
input
=
inference
,
label
=
label
)
cost6
=
regression_cost
(
input
=
inference
,
label
=
label
,
weight
=
weight
)
cost7
=
multi_binary_label_cross_entropy_cost
(
input
=
inference
,
label
=
label
)
cost8
=
rank_cost
(
left
=
score
,
right
=
score
,
label
=
score
)
cost9
=
lambda_cost
(
input
=
inference
,
score
=
score
)
cost10
=
sum_cost
(
input
=
inference
)
cost11
=
huber_cost
(
input
=
score
,
label
=
label
)
print
parse_network
(
cost1
)
print
parse_network
(
cost2
)
print
parse_network
(
cost1
,
cost2
)
print
parse_network
(
cost2
)
print
parse_network
(
cost3
,
cost4
)
print
parse_network
(
cost5
,
cost6
)
print
parse_network
(
cost7
,
cost8
,
cost9
,
cost10
,
cost11
)
print
parse_network
(
inference
,
maxid
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录