Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ff55d4c5
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
提交
ff55d4c5
编写于
6月 12, 2018
作者:
Y
yuyang18
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish documents
* less_than * cumsum * multiplex * open_recordio_file
上级
2955ff58
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
93 addition
and
95 deletion
+93
-95
paddle/fluid/operators/compare_op.cc
paddle/fluid/operators/compare_op.cc
+10
-13
paddle/fluid/operators/cumsum_op.cc
paddle/fluid/operators/cumsum_op.cc
+5
-5
paddle/fluid/operators/multiplex_op.cc
paddle/fluid/operators/multiplex_op.cc
+30
-12
paddle/fluid/operators/reader/create_recordio_file_reader_op.cc
.../fluid/operators/reader/create_recordio_file_reader_op.cc
+7
-3
paddle/fluid/operators/reader/reader_op_registry.cc
paddle/fluid/operators/reader/reader_op_registry.cc
+1
-1
python/paddle/fluid/layers/control_flow.py
python/paddle/fluid/layers/control_flow.py
+16
-13
python/paddle/fluid/layers/io.py
python/paddle/fluid/layers/io.py
+13
-18
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+11
-30
未找到文件。
paddle/fluid/operators/compare_op.cc
浏览文件 @
ff55d4c5
...
@@ -23,25 +23,22 @@ class CompareOpProtoMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -23,25 +23,22 @@ class CompareOpProtoMaker : public framework::OpProtoAndCheckerMaker {
public:
public:
void
Make
()
override
{
void
Make
()
override
{
OpComment
comment
;
OpComment
comment
;
AddInput
(
"X"
,
AddInput
(
"X"
,
string
::
Sprintf
(
"the left hand operand of %s operator"
,
string
::
Sprintf
(
"(LoDTensor) the left hand operand of %s operator"
,
comment
.
type
));
comment
.
type
));
AddInput
(
"Y"
,
string
::
Sprintf
(
AddInput
(
"Y"
,
string
::
Sprintf
(
"the right hand operand of %s operator"
,
"(LoDTensor) the right hand operand of %s operator"
,
comment
.
type
));
comment
.
type
));
AddAttr
<
bool
>
(
"force_cpu"
,
AddAttr
<
bool
>
(
"force_cpu"
,
"
(bool, default false)
Force fill output variable to cpu "
"Force fill output variable to cpu "
"memory. Otherwise, fill output variable to the running "
"memory. Otherwise, fill output variable to the running "
"device"
)
"device [default true]."
)
.
SetDefault
(
false
);
.
SetDefault
(
true
);
AddOutput
(
"Out"
,
string
::
Sprintf
(
AddOutput
(
"Out"
,
string
::
Sprintf
(
"n-dim bool tensor. Each element is %s"
,
"(LoDTensor) n-dim bool tensor. Each element is %s"
,
comment
.
equation
));
comment
.
equation
));
AddComment
(
string
::
Sprintf
(
R"DOC(%s Operator
AddComment
(
string
::
Sprintf
(
R"DOC(%s Operator
It operates element-wise on X and Y, and returns the Out. Each of them is a
It operates element-wise on X and Y, and returns the Out. Each of them is a
N-dim tensor. X and Y could be any type. The each element of the Out tensor is
N-dim tensor. X and Y could be any type. The each element of the Out tensor is
calculated by
%s
calculated by
$%s$
)DOC"
,
)DOC"
,
comment
.
type
,
comment
.
equation
));
comment
.
type
,
comment
.
equation
));
AddAttr
<
int
>
(
"axis"
,
AddAttr
<
int
>
(
"axis"
,
...
...
paddle/fluid/operators/cumsum_op.cc
浏览文件 @
ff55d4c5
...
@@ -33,16 +33,16 @@ class CumsumOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -33,16 +33,16 @@ class CumsumOpMaker : public framework::OpProtoAndCheckerMaker {
AddInput
(
"X"
,
"Input of Cumsum operator"
);
AddInput
(
"X"
,
"Input of Cumsum operator"
);
AddOutput
(
"Out"
,
"Output of Cumsum operator"
);
AddOutput
(
"Out"
,
"Output of Cumsum operator"
);
AddAttr
<
int
>
(
"axis"
,
AddAttr
<
int
>
(
"axis"
,
"
(int, default -1). The dimenstion to accumulate along.
"
"
The dimenstion to accumulate along. -1 means the last
"
"
-1 means the last dimenstion
"
)
"
dimenstion [default -1].
"
)
.
SetDefault
(
-
1
)
.
SetDefault
(
-
1
)
.
EqualGreaterThan
(
-
1
);
.
EqualGreaterThan
(
-
1
);
AddAttr
<
bool
>
(
"exclusive"
,
AddAttr
<
bool
>
(
"exclusive"
,
"
bool, default false). Whether to perform exclusive cumsum
"
)
"
Whether to perform exclusive cumsum. [default false].
"
)
.
SetDefault
(
false
);
.
SetDefault
(
false
);
AddAttr
<
bool
>
(
"reverse"
,
AddAttr
<
bool
>
(
"reverse"
,
"
bool, default false). If true, the cumsum is performed in
"
"
If true, the cumsum is performed in the reversed direction.
"
"
the reversed direction
"
)
"
[default false].
"
)
.
SetDefault
(
false
);
.
SetDefault
(
false
);
AddComment
(
R"DOC(
AddComment
(
R"DOC(
The cumulative sum of the elements along a given axis.
The cumulative sum of the elements along a given axis.
...
...
paddle/fluid/operators/multiplex_op.cc
浏览文件 @
ff55d4c5
...
@@ -62,26 +62,44 @@ class MultiplexOp : public framework::OperatorWithKernel {
...
@@ -62,26 +62,44 @@ class MultiplexOp : public framework::OperatorWithKernel {
class
MultiplexOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
class
MultiplexOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
public:
void
Make
()
override
{
void
Make
()
override
{
AddInput
(
"Ids"
,
"The index tensor of multiplex operator."
);
AddInput
(
"Ids"
,
AddInput
(
"X"
,
"The candidate tensors of multiplex operator."
)
"Tensor<int32>, index variable which is a 2-D tensor with shape "
"[M, 1] where M is the batch size."
);
AddInput
(
"X"
,
"A list of variables to gather from. All variables have the same "
"shape and the rank is at least 2."
)
.
AsDuplicable
();
.
AsDuplicable
();
AddOutput
(
"Out"
,
"The output tensor of multiplex operator."
);
AddOutput
(
"Out"
,
"The output tensor of multiplex operator."
);
AddComment
(
R"DOC(
AddComment
(
R"DOC(
Multiplex Operator.
Referring to the given index variable, this layer selects rows from the
input variables to construct a multiplex variable. Assuming that there are
Multiplex multiple tensors according to the index provided by the index tensor.
:math:`m` input variables and :math:`I_i` represents the i-th input
variable and :math:`i` is in [0, :math:`m`). All input variables are
Ids: the index tensor.
tensors with same shape [:math:`d_0`, :math:`d_1`, ..., :math:`d_R`].
X[0 : N - 1]: the candidate tensors for output (N >= 2).
Please note that rank of the input tensor should be at least 2. Each input
For each index i from 0 to batchSize - 1, the output is the i-th row of the
variable will be treated as a 2-D matrix with shape [:math:`M`, :math:`N`]
where :math:`M` for :math:`d_0` and :math:`N` for :math:`d_1` * :math:`d_2`
* ... * :math:`d_R`. Let :math:`I_i[j]` be the j-th row of the i-th input
variable. The given index variable should be a 2-D tensor with shape
[:math:`M`, 1]. Let `ID[i]` be the i-th index value of the index variable.
Then the output variable will be a tensor with shape [:math:`d_0`,
:math:`d_1`, ..., :math:`d_R`]. If we treat the output tensor as a 2-D
matrix with shape [:math:`M`, :math:`N`] and let :math:`O[i]` be the i-th
row of the matrix, then `O[i]` is equal to :math:`I_{ID[i]}[i]`.
* Ids: the index tensor.
* X[0 : N - 1]: the candidate tensors for output (N >= 2).
* For each index i from 0 to batchSize - 1, the output is the i-th row of the
the (Ids[i])-th tensor.
the (Ids[i])-th tensor.
For i-th row of the output tensor:
For i-th row of the output tensor:
$
$y[i] = x_{k}[i]$
$
$
y[i] = x_{k}[i]
$
where
`y` is the output tensor, `x_{k}`
is the k-th input tensor,
where
$y$ is the output tensor, $x_{k}$
is the k-th input tensor,
and
`k = Ids[i]`
.
and
$k = Ids[i]$
.
)DOC"
);
)DOC"
);
}
}
...
...
paddle/fluid/operators/reader/create_recordio_file_reader_op.cc
浏览文件 @
ff55d4c5
...
@@ -78,11 +78,15 @@ class CreateRecordIOReaderOp : public framework::OperatorBase {
...
@@ -78,11 +78,15 @@ class CreateRecordIOReaderOp : public framework::OperatorBase {
class
CreateRecordIOReaderOpMaker
:
public
FileReaderMakerBase
{
class
CreateRecordIOReaderOpMaker
:
public
FileReaderMakerBase
{
protected:
protected:
void
Apply
()
override
{
void
Apply
()
override
{
AddAttr
<
std
::
string
>
(
"filename"
,
"The filename of record io reader"
);
AddAttr
<
std
::
string
>
(
"filename"
,
"The filename of record file. This file will given to reader."
);
AddComment
(
R"DOC(
AddComment
(
R"DOC(
CreateRecordIOReader Operator
Open a recordio file and return the reader object. The returned reader object
is thread-safe.
Create a reader from a record io file
NOTE: This is a very low-level API. It is used for debugging data file or
training. Please use `open_files` instead of this API for production usage.
)DOC"
);
)DOC"
);
}
}
};
};
...
...
paddle/fluid/operators/reader/reader_op_registry.cc
浏览文件 @
ff55d4c5
...
@@ -54,7 +54,7 @@ std::unique_ptr<framework::ReaderBase> CreateReaderByFileName(
...
@@ -54,7 +54,7 @@ std::unique_ptr<framework::ReaderBase> CreateReaderByFileName(
}
}
void
FileReaderMakerBase
::
Make
()
{
void
FileReaderMakerBase
::
Make
()
{
AddOutput
(
"Out"
,
"(ReaderHolder) The created random reader."
).
AsDuplicable
();
AddOutput
(
"Out"
,
"(ReaderHolder)
:
The created random reader."
).
AsDuplicable
();
AddAttr
<
std
::
vector
<
int
>>
(
"shape_concat"
,
"The concat of all data's shapes."
);
AddAttr
<
std
::
vector
<
int
>>
(
"shape_concat"
,
"The concat of all data's shapes."
);
AddAttr
<
std
::
vector
<
int
>>
(
AddAttr
<
std
::
vector
<
int
>>
(
"ranks"
,
"ranks"
,
...
...
python/paddle/fluid/layers/control_flow.py
浏览文件 @
ff55d4c5
...
@@ -909,37 +909,40 @@ def create_array(dtype):
...
@@ -909,37 +909,40 @@ def create_array(dtype):
dtype
=
dtype
)
dtype
=
dtype
)
def
less_than
(
x
,
y
,
force_cpu
=
True
,
cond
=
None
,
**
ignored
):
@
templatedoc
()
def
less_than
(
x
,
y
,
force_cpu
=
None
,
cond
=
None
,
**
ignored
):
"""
"""
**Less than**
${comment}
This layer returns the truth value of :math:`x < y` elementwise.
>>> import paddle.fluid as fluid
>>> less = fluid.layers.less_than(x=label, y=limit)
Args:
Args:
x(
Variable): First operand of *less_than*
x(
${x_type}): ${x_comment}.
y(
Variable): Second operand of *less_than*
y(
${y_type}): ${y_comment}.
force_cpu(
Bool|True): The output data will be on CPU if set true
.
force_cpu(
${force_cpu_type}): ${force_cpu_comment}
.
cond(Variable|None): Optional output variable to store the result of *less_than*
cond(Variable|None): Optional output variable to store the result of *less_than*
Returns:
Returns:
Variable: The tensor variable storing the output of *less_than*.
${out_comment}.
Examples:
.. code-block:: python
less = fluid.layers.less_than(x=label, y=limit)
"""
"""
helper
=
LayerHelper
(
"less_than"
,
**
locals
())
helper
=
LayerHelper
(
"less_than"
,
**
locals
())
if
cond
is
None
:
if
cond
is
None
:
cond
=
helper
.
create_tmp_variable
(
dtype
=
'bool'
)
cond
=
helper
.
create_tmp_variable
(
dtype
=
'bool'
)
cond
.
stop_gradient
=
True
cond
.
stop_gradient
=
True
attrs
=
dict
()
if
force_cpu
is
not
None
:
attrs
[
'force_cpu'
]
=
force_cpu
elif
force_init_on_cpu
():
attrs
[
'force_cpu'
]
=
force_init_on_cpu
()
helper
.
append_op
(
helper
.
append_op
(
type
=
'less_than'
,
type
=
'less_than'
,
inputs
=
{
'X'
:
[
x
],
inputs
=
{
'X'
:
[
x
],
'Y'
:
[
y
]},
'Y'
:
[
y
]},
outputs
=
{
'Out'
:
[
cond
]},
outputs
=
{
'Out'
:
[
cond
]},
attrs
=
{
'force_cpu'
:
force_cpu
or
force_init_on_cpu
()}
)
attrs
=
attrs
)
return
cond
return
cond
...
...
python/paddle/fluid/layers/io.py
浏览文件 @
ff55d4c5
...
@@ -292,6 +292,7 @@ def _copy_reader_create_op_(block, op):
...
@@ -292,6 +292,7 @@ def _copy_reader_create_op_(block, op):
return
new_op
return
new_op
@
templatedoc
(
op_type
=
'create_recordio_file_reader'
)
def
open_recordio_file
(
filename
,
def
open_recordio_file
(
filename
,
shapes
,
shapes
,
lod_levels
,
lod_levels
,
...
@@ -299,34 +300,28 @@ def open_recordio_file(filename,
...
@@ -299,34 +300,28 @@ def open_recordio_file(filename,
pass_num
=
1
,
pass_num
=
1
,
for_parallel
=
True
):
for_parallel
=
True
):
"""
"""
Open a RecordIO file
${comment}
This layer takes a RecordIO file to read from and returns a Reader Variable.
>>> import paddle.fluid as fluid
Via the Reader Variable, we can get data from the given RecordIO file.
>>> reader = fluid.layers.io.open_recordio_file(
>>> filename='./data.recordio',
>>> shapes=[(3,224,224), (1)],
>>> lod_levels=[0, 0],
>>> dtypes=['float32', 'int64'])
>>> # Via the reader, we can use 'read_file' layer to get data:
>>> image, label = fluid.layers.io.read_file(reader)
Args:
Args:
filename(
str): The RecordIO file's name
.
filename(
${filename_type}): ${filename_comment}
.
shapes(list): List of tuples which declaring data shapes.
shapes(list): List of tuples which declaring data shapes.
lod_levels(
list): List of ints which declaring data lod_level
.
lod_levels(
${lod_levels_type}): ${lod_levels_comment}
.
dtypes(list): List of strs which declaring data type.
dtypes(list): List of strs which declaring data type.
pass_num(int): Number of passes to run.
pass_num(int): Number of passes to run.
for_parallel(Bool): Set it as True if you are going to run
for_parallel(Bool): Set it as True if you are going to run
subsequent operators in parallel.
subsequent operators in parallel.
Returns:
Returns:
Variable: A Reader Variable via which we can get RecordIO file data.
${out_comment}.
Examples:
.. code-block:: python
reader = fluid.layers.io.open_recordio_file(
filename='./data.recordio',
shapes=[(3,224,224), (1)],
lod_levels=[0, 0],
dtypes=['float32', 'int64'])
# Via the reader, we can use 'read_file' layer to get data:
image, label = fluid.layers.io.read_file(reader)
"""
"""
dtypes
=
[
convert_np_dtype_to_dtype_
(
dt
)
for
dt
in
dtypes
]
dtypes
=
[
convert_np_dtype_to_dtype_
(
dt
)
for
dt
in
dtypes
]
shape_concat
=
[]
shape_concat
=
[]
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
ff55d4c5
...
@@ -3210,42 +3210,23 @@ def row_conv(input, future_context_size, param_attr=None, act=None):
...
@@ -3210,42 +3210,23 @@ def row_conv(input, future_context_size, param_attr=None, act=None):
return
helper
.
append_activation
(
out
)
return
helper
.
append_activation
(
out
)
@
templatedoc
()
def
multiplex
(
inputs
,
index
):
def
multiplex
(
inputs
,
index
):
"""
"""
**Multiplex Layer**
${comment}
Referring to the given index variable, this layer selects rows from the
>>> import paddle.fluid as fluid
input variables to construct a multiplex variable. Assuming that there are
>>> x1 = fluid.layers.data(name='x1', shape=[4], dtype='float32')
:math:`m` input variables and :math:`I_i` represents the i-th input
>>> x2 = fluid.layers.data(name='x2', shape=[4], dtype='float32')
variable and :math:`i` is in [0, :math:`m`). All input variables are
>>> index = fluid.layers.data(name='index', shape=[1], dtype='int32')
tensors with same shape [:math:`d_0`, :math:`d_1`, ..., :math:`d_R`].
>>> out = fluid.layers.multiplex(inputs=[x1, x2], index=index)
Please note that rank of the input tensor should be at least 2. Each input
variable will be treated as a 2-D matrix with shape [:math:`M`, :math:`N`]
where :math:`M` for :math:`d_0` and :math:`N` for :math:`d_1` * :math:`d_2`
* ... * :math:`d_R`. Let :math:`I_i[j]` be the j-th row of the i-th input
variable. The given index variable should be a 2-D tensor with shape
[:math:`M`, 1]. Let `ID[i]` be the i-th index value of the index variable.
Then the output variable will be a tensor with shape [:math:`d_0`,
:math:`d_1`, ..., :math:`d_R`]. If we treat the output tensor as a 2-D
matrix with shape [:math:`M`, :math:`N`] and let :math:`O[i]` be the i-th
row of the matrix, then `O[i]` is equal to :math:`I_{ID[i]}[i]`.
Args:
Args:
inputs (list): A list of variables to gather from. All variables have the
inputs (list): ${x_comment}.
same shape and the rank is at least 2.
index (${ids_type}): ${ids_comment}.
index (Variable): Tensor<int32>, index variable which is a 2-D tensor
with shape [M, 1] where M is the batch size.
Returns:
Returns:
Variable: Multiplex variable gathered from input variables.
${out_comment}.
Examples:
.. code-block:: python
x1 = fluid.layers.data(name='x1', shape=[4], dtype='float32')
x2 = fluid.layers.data(name='x2', shape=[4], dtype='float32')
index = fluid.layers.data(name='index', shape=[1], dtype='int32')
out = fluid.layers.multiplex(inputs=[x1, x2], index=index)
"""
"""
helper
=
LayerHelper
(
'multiplex'
,
**
locals
())
helper
=
LayerHelper
(
'multiplex'
,
**
locals
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录