Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
8c302d48
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8c302d48
编写于
2月 12, 2018
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove kwargs in layer apis
上级
e9d30991
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
27 addition
and
27 deletion
+27
-27
python/paddle/v2/fluid/layers/nn.py
python/paddle/v2/fluid/layers/nn.py
+27
-27
未找到文件。
python/paddle/v2/fluid/layers/nn.py
浏览文件 @
8c302d48
...
...
@@ -829,12 +829,12 @@ def crf_decoding(input, param_attr, label=None):
return
viterbi_path
def
cos_sim
(
X
,
Y
,
**
kwargs
):
def
cos_sim
(
X
,
Y
):
"""
This function performs the cosine similarity between two tensors
X and Y and returns that as the output.
"""
helper
=
LayerHelper
(
'cos_sim'
,
**
kwargs
)
helper
=
LayerHelper
(
'cos_sim'
,
**
locals
()
)
out
=
helper
.
create_tmp_variable
(
dtype
=
X
.
dtype
)
xnorm
=
helper
.
create_tmp_variable
(
dtype
=
X
.
dtype
)
ynorm
=
helper
.
create_tmp_variable
(
dtype
=
X
.
dtype
)
...
...
@@ -848,7 +848,7 @@ def cos_sim(X, Y, **kwargs):
return
out
def
dropout
(
x
,
dropout_prob
,
is_test
=
False
,
seed
=
None
,
**
kwargs
):
def
dropout
(
x
,
dropout_prob
,
is_test
=
False
,
seed
=
None
):
"""
Computes dropout.
...
...
@@ -877,7 +877,7 @@ def dropout(x, dropout_prob, is_test=False, seed=None, **kwargs):
droped = fluid.layers.dropout(input=x, dropout_rate=0.5)
"""
helper
=
LayerHelper
(
'dropout'
,
**
kwargs
)
helper
=
LayerHelper
(
'dropout'
,
**
locals
()
)
out
=
helper
.
create_tmp_variable
(
dtype
=
x
.
dtype
)
mask
=
helper
.
create_tmp_variable
(
dtype
=
x
.
dtype
,
stop_gradient
=
True
)
helper
.
append_op
(
...
...
@@ -894,7 +894,7 @@ def dropout(x, dropout_prob, is_test=False, seed=None, **kwargs):
return
out
def
cross_entropy
(
input
,
label
,
**
kwargs
):
def
cross_entropy
(
input
,
label
,
soft_label
=
False
):
"""
**Cross Entropy Layer**
...
...
@@ -936,7 +936,7 @@ def cross_entropy(input, label, **kwargs):
tensor<int64> with shape [N x 1]. When
`soft_label` is set to `True`, `label` is a
tensor<float/double> with shape [N x D].
soft_label (bool
, via `**kwargs`
): a flag indicating whether to
soft_label (bool): a flag indicating whether to
interpretate the given labels as soft
labels, default `False`.
...
...
@@ -956,18 +956,18 @@ def cross_entropy(input, label, **kwargs):
predict = fluid.layers.fc(input=net, size=classdim, act='softmax')
cost = fluid.layers.cross_entropy(input=predict, label=label)
"""
helper
=
LayerHelper
(
'cross_entropy'
,
**
kwargs
)
helper
=
LayerHelper
(
'cross_entropy'
,
**
locals
()
)
out
=
helper
.
create_tmp_variable
(
dtype
=
input
.
dtype
)
helper
.
append_op
(
type
=
'cross_entropy'
,
inputs
=
{
'X'
:
[
input
],
'Label'
:
[
label
]},
outputs
=
{
'Y'
:
[
out
]},
attrs
=
kwargs
)
attrs
=
{
"soft_label"
:
soft_label
}
)
return
out
def
square_error_cost
(
input
,
label
,
**
kwargs
):
def
square_error_cost
(
input
,
label
):
"""
**Square error cost layer**
...
...
@@ -1002,7 +1002,7 @@ def square_error_cost(input, label, **kwargs):
cost = layers.square_error_cost(input=y_predict, label=y)
"""
helper
=
LayerHelper
(
'square_error_cost'
,
**
kwargs
)
helper
=
LayerHelper
(
'square_error_cost'
,
**
locals
()
)
minus_out
=
helper
.
create_tmp_variable
(
dtype
=
input
.
dtype
)
helper
.
append_op
(
type
=
'elementwise_sub'
,
...
...
@@ -1017,12 +1017,12 @@ def square_error_cost(input, label, **kwargs):
return
square_out
def
accuracy
(
input
,
label
,
k
=
1
,
correct
=
None
,
total
=
None
,
**
kwargs
):
def
accuracy
(
input
,
label
,
k
=
1
,
correct
=
None
,
total
=
None
):
"""
This function computes the accuracy using the input and label.
The output is the top_k inputs and their indices.
"""
helper
=
LayerHelper
(
"accuracy"
,
**
kwargs
)
helper
=
LayerHelper
(
"accuracy"
,
**
locals
()
)
topk_out
=
helper
.
create_tmp_variable
(
dtype
=
input
.
dtype
)
topk_indices
=
helper
.
create_tmp_variable
(
dtype
=
"int64"
)
helper
.
append_op
(
...
...
@@ -1055,13 +1055,12 @@ def chunk_eval(input,
label
,
chunk_scheme
,
num_chunk_types
,
excluded_chunk_types
=
None
,
**
kwargs
):
excluded_chunk_types
=
None
):
"""
This function computes and outputs the precision, recall and
F1-score of chunk detection.
"""
helper
=
LayerHelper
(
"chunk_eval"
,
**
kwargs
)
helper
=
LayerHelper
(
"chunk_eval"
,
**
locals
()
)
# prepare output
precision
=
helper
.
create_tmp_variable
(
dtype
=
"float32"
)
...
...
@@ -1293,7 +1292,7 @@ def conv2d(input,
return
helper
.
append_activation
(
pre_act
)
def
sequence_pool
(
input
,
pool_type
,
**
kwargs
):
def
sequence_pool
(
input
,
pool_type
):
"""
This function add the operator for sequence pooling.
It pools features of all time-steps of each instance, and is applied
...
...
@@ -1343,7 +1342,7 @@ def sequence_pool(input, pool_type, **kwargs):
sqrt_x = fluid.layers.sequence_pool(input=x, pool_type='sqrt')
max_x = fluid.layers.sequence_pool(input=x, pool_type='max')
"""
helper
=
LayerHelper
(
'sequence_pool'
,
input
=
input
,
**
kwargs
)
helper
=
LayerHelper
(
'sequence_pool'
,
**
locals
()
)
dtype
=
helper
.
input_dtype
()
pool_out
=
helper
.
create_tmp_variable
(
dtype
)
max_index
=
helper
.
create_tmp_variable
(
dtype
)
...
...
@@ -1363,7 +1362,7 @@ def sequence_pool(input, pool_type, **kwargs):
return
pool_out
def
sequence_first_step
(
input
,
**
kwargs
):
def
sequence_first_step
(
input
):
"""
This funciton get the first step of sequence.
...
...
@@ -1396,7 +1395,7 @@ def sequence_first_step(input, **kwargs):
return
sequence_pool
(
input
=
input
,
pool_type
=
"first"
)
def
sequence_last_step
(
input
,
**
kwargs
):
def
sequence_last_step
(
input
):
"""
This funciton get the last step of sequence.
...
...
@@ -2336,7 +2335,8 @@ def l2_normalize(x, axis, epsilon=1e-12, name=None):
normed = fluid.layers.l2_normalize(x=data, axis=1)
"""
if
len
(
x
.
shape
)
==
1
:
axis
=
0
if
len
(
x
.
shape
)
==
1
:
axis
=
0
helper
=
LayerHelper
(
"l2_normalize"
,
**
locals
())
...
...
@@ -2654,7 +2654,7 @@ def ctc_greedy_decoder(input, blank, name=None):
return
ctc_out
def
warpctc
(
input
,
label
,
blank
=
0
,
norm_by_times
=
False
,
**
kwargs
):
def
warpctc
(
input
,
label
,
blank
=
0
,
norm_by_times
=
False
):
"""
An operator integrating the open source Warp-CTC library
(https://github.com/baidu-research/warp-ctc)
...
...
@@ -2695,7 +2695,7 @@ def warpctc(input, label, blank=0, norm_by_times=False, **kwargs):
cost = layers.warpctc(input=y_predict, label=y)
"""
helper
=
LayerHelper
(
'warpctc'
,
**
kwargs
)
helper
=
LayerHelper
(
'warpctc'
,
**
locals
()
)
loss_out
=
helper
.
create_tmp_variable
(
dtype
=
input
.
dtype
)
grad_out
=
helper
.
create_tmp_variable
(
dtype
=
input
.
dtype
)
helper
.
append_op
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录