Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
5f90a31f
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
5f90a31f
编写于
12月 18, 2017
作者:
Y
Yang yaming
提交者:
GitHub
12月 18, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6670 from pkuyym/fix-6590
Add python wrapper for SeqExpandOp
上级
f8413ff7
984e4ca5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
82 addition
and
2 deletion
+82
-2
doc/api/v2/fluid/layers.rst
doc/api/v2/fluid/layers.rst
+4
-0
python/paddle/v2/fluid/layers/nn.py
python/paddle/v2/fluid/layers/nn.py
+69
-2
python/paddle/v2/fluid/tests/test_layers.py
python/paddle/v2/fluid/tests/test_layers.py
+9
-0
未找到文件。
doc/api/v2/fluid/layers.rst
浏览文件 @
5f90a31f
...
@@ -300,3 +300,7 @@ conv2d_transpose
...
@@ -300,3 +300,7 @@ conv2d_transpose
.. autofunction:: paddle.v2.fluid.layers.conv2d_transpose
.. autofunction:: paddle.v2.fluid.layers.conv2d_transpose
:noindex:
:noindex:
sequence_expand
---------
.. autofunction:: paddle.v2.fluid.layers.sequence_expand
:noindex:
python/paddle/v2/fluid/layers/nn.py
浏览文件 @
5f90a31f
...
@@ -10,7 +10,7 @@ __all__ = [
...
@@ -10,7 +10,7 @@ __all__ = [
'fc'
,
'embedding'
,
'dynamic_lstm'
,
'gru_unit'
,
'linear_chain_crf'
,
'fc'
,
'embedding'
,
'dynamic_lstm'
,
'gru_unit'
,
'linear_chain_crf'
,
'crf_decoding'
,
'cos_sim'
,
'cross_entropy'
,
'square_error_cost'
,
'accuracy'
,
'crf_decoding'
,
'cos_sim'
,
'cross_entropy'
,
'square_error_cost'
,
'accuracy'
,
'chunk_eval'
,
'sequence_conv'
,
'conv2d'
,
'sequence_pool'
,
'pool2d'
,
'chunk_eval'
,
'sequence_conv'
,
'conv2d'
,
'sequence_pool'
,
'pool2d'
,
'batch_norm'
,
'beam_search_decode'
,
'conv2d_transpose'
'batch_norm'
,
'beam_search_decode'
,
'conv2d_transpose'
,
'sequence_expand'
]
]
...
@@ -392,7 +392,7 @@ def chunk_eval(input,
...
@@ -392,7 +392,7 @@ def chunk_eval(input,
excluded_chunk_types
=
None
,
excluded_chunk_types
=
None
,
**
kwargs
):
**
kwargs
):
"""
"""
This function computes and outputs the precision, recall and
This function computes and outputs the precision, recall and
F1-score of chunk detection.
F1-score of chunk detection.
"""
"""
helper
=
LayerHelper
(
"chunk_eval"
,
**
kwargs
)
helper
=
LayerHelper
(
"chunk_eval"
,
**
kwargs
)
...
@@ -789,3 +789,70 @@ def conv2d_transpose(input,
...
@@ -789,3 +789,70 @@ def conv2d_transpose(input,
attrs
=
op_attr
)
attrs
=
op_attr
)
return
out
return
out
def
sequence_expand
(
x
,
y
,
main_program
=
None
,
startup_program
=
None
):
"""Sequence Expand Layer. This layer will expand the input variable **x**
according to LoD information of **y**. And the following examples will
explain how sequence_expand works:
.. code-block:: text
* Case 1
x is a LoDTensor:
x.lod = [[0, 2, 3],
[0, 1, 3, 4]]
x.data = [a, b, c, d]
x.dims = [4, 1]
y is a LoDTensor:
y.lod = [[0, 2, 4],
[0, 3, 6, 7, 8]]
with condition len(y.lod[-1]) - 1 == x.dims[0]
then output is a 2-level LoDTensor:
out.lod = [[0, 2, 4],
[0, 3, 6, 7, 8]]
out.data = [a, a, a, b, b, b, c, d]
out.dims = [8, 1]
* Case 2
x is a Tensor:
x.data = [a, b, c]
x.dims = [3, 1]
y is a LoDTensor:
y.lod = [[0, 2, 3, 6]]
with condition len(y.lod[-1]) - 1 == x.dims[0]
then output is a 1-level LoDTensor:
out.lod = [[0, 2, 3, 6]]
out.data = [a, a, b, c, c, c]
out.dims = [6, 1]
Args:
x (Variable): The input variable which is a Tensor or LoDTensor.
y (Variable): The input variable which is a LoDTensor.
main_program (Program): The main program.
startup_program (Program): The startup program.
Returns:
Variable: The expanded variable which is a LoDTensor.
Examples:
.. code-block:: python
x = fluid.layers.data(name='x', shape=[10], dtype='float32')
y = fluid.layers.data(name='y', shape=[10, 20],
dtype='float32', lod_level=1)
out = layers.sequence_expand(x=x, y=y)
"""
helper
=
LayerHelper
(
'sequence_expand'
,
input
=
x
,
**
locals
())
dtype
=
helper
.
input_dtype
()
tmp
=
helper
.
create_tmp_variable
(
dtype
)
helper
.
append_op
(
type
=
'sequence_expand'
,
inputs
=
{
'X'
:
x
,
'Y'
:
y
},
outputs
=
{
'Out'
:
tmp
})
return
tmp
python/paddle/v2/fluid/tests/test_layers.py
浏览文件 @
5f90a31f
...
@@ -161,6 +161,15 @@ class TestBook(unittest.TestCase):
...
@@ -161,6 +161,15 @@ class TestBook(unittest.TestCase):
x
=
dat
,
label
=
lbl
))
x
=
dat
,
label
=
lbl
))
print
(
str
(
program
))
print
(
str
(
program
))
def
test_seq_expand
(
self
):
program
=
Program
()
with
program_guard
(
program
):
x
=
layers
.
data
(
name
=
'x'
,
shape
=
[
10
],
dtype
=
'float32'
)
y
=
layers
.
data
(
name
=
'y'
,
shape
=
[
10
,
20
],
dtype
=
'float32'
,
lod_level
=
1
)
self
.
assertIsNotNone
(
layers
.
sequence_expand
(
x
=
x
,
y
=
y
))
print
(
str
(
program
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录