Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
3dcf0da9
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看板
提交
3dcf0da9
编写于
11月 16, 2017
作者:
W
wanghaox
浏览文件
操作
浏览文件
下载
差异文件
change offset and length's rank to 2, dim[0] for batch size
上级
40a6c488
a76b6144
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
87 addition
and
83 deletion
+87
-83
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+85
-81
python/paddle/v2/fluid/tests/test_beam_search_op.py
python/paddle/v2/fluid/tests/test_beam_search_op.py
+2
-2
未找到文件。
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
3dcf0da9
...
@@ -2987,8 +2987,10 @@ def img_cmrnorm_layer(input,
...
@@ -2987,8 +2987,10 @@ def img_cmrnorm_layer(input,
layer_attr
=
None
):
layer_attr
=
None
):
"""
"""
Response normalization across feature maps.
Response normalization across feature maps.
The details please refer to
`Alex's paper <http://www.cs.toronto.edu/~fritz/absps/imagenet.pdf>`_.
Reference:
ImageNet Classification with Deep Convolutional Neural Networks
http://www.cs.toronto.edu/~fritz/absps/imagenet.pdf
The example usage is:
The example usage is:
...
@@ -2997,7 +2999,7 @@ def img_cmrnorm_layer(input,
...
@@ -2997,7 +2999,7 @@ def img_cmrnorm_layer(input,
norm = img_cmrnorm_layer(input=net, size=5)
norm = img_cmrnorm_layer(input=net, size=5)
:param name: The name of this layer. It is optional.
:param name: The name of this layer. It is optional.
:type name:
None |
basestring
:type name: basestring
:param input: The input of this layer.
:param input: The input of this layer.
:type input: LayerOutput
:type input: LayerOutput
:param size: Normalize in number of :math:`size` feature maps.
:param size: Normalize in number of :math:`size` feature maps.
...
@@ -3006,9 +3008,11 @@ def img_cmrnorm_layer(input,
...
@@ -3006,9 +3008,11 @@ def img_cmrnorm_layer(input,
:type scale: float
:type scale: float
:param power: The hyper-parameter.
:param power: The hyper-parameter.
:type power: float
:type power: float
:param num_channels: input layer's filers number or channels. If
:param num_channels: The number of input channels. If the parameter is not set or
num_channels is None, it will be set automatically.
set to None, its actual value will be automatically set to
:param layer_attr: Extra Layer Attribute.
the channels number of the input.
:param layer_attr: The extra layer attributes. See ExtraLayerAttribute for
details.
:type layer_attr: ExtraLayerAttribute
:type layer_attr: ExtraLayerAttribute
:return: LayerOutput object.
:return: LayerOutput object.
:rtype: LayerOutput
:rtype: LayerOutput
...
@@ -3036,7 +3040,7 @@ def batch_norm_layer(input,
...
@@ -3036,7 +3040,7 @@ def batch_norm_layer(input,
use_global_stats
=
None
,
use_global_stats
=
None
,
mean_var_names
=
None
):
mean_var_names
=
None
):
"""
"""
Batch Normalization Layer. The notation of this layer
as follow
.
Batch Normalization Layer. The notation of this layer
is as follows
.
:math:`x` is the input features over a mini-batch.
:math:`x` is the input features over a mini-batch.
...
@@ -3050,8 +3054,10 @@ def batch_norm_layer(input,
...
@@ -3050,8 +3054,10 @@ def batch_norm_layer(input,
\\
sigma_{
\\
beta}^{2} +
\\
epsilon}}
\\
qquad &//\ normalize
\\\\
\\
sigma_{
\\
beta}^{2} +
\\
epsilon}}
\\
qquad &//\ normalize
\\\\
y_i &
\\
gets
\\
gamma
\\
hat{x_i} +
\\
beta
\\
qquad &//\ scale\ and\ shift
y_i &
\\
gets
\\
gamma
\\
hat{x_i} +
\\
beta
\\
qquad &//\ scale\ and\ shift
The details of batch normalization please refer to this
Reference:
`paper <http://arxiv.org/abs/1502.03167>`_.
Batch Normalization: Accelerating Deep Network Training by Reducing
Internal Covariate Shift
http://arxiv.org/abs/1502.03167
The example usage is:
The example usage is:
...
@@ -3061,48 +3067,47 @@ def batch_norm_layer(input,
...
@@ -3061,48 +3067,47 @@ def batch_norm_layer(input,
:param name: The name of this layer. It is optional.
:param name: The name of this layer. It is optional.
:type name: basestring
:type name: basestring
:param input: batch normalization input. Better be linear activation.
:param input: This layer's input which is to be performed batch normalization on.
Because there is an activation inside batch_normalization.
:type input: LayerOutput
:type input: LayerOutput
:param batch_norm_type: We have batch_norm, mkldnn_batch_norm and cudnn_batch_norm.
:param batch_norm_type: We have batch_norm, mkldnn_batch_norm and cudnn_batch_norm.
batch_norm supports CPU, MKLDNN and GPU. cudnn_batch_norm
batch_norm supports CPU, MKLDNN and GPU. cudnn_batch_norm
requires cuDNN version greater or equal to v4 (>=v4).
requires cuDNN version greater or equal to v4 (>=v4).
But cudnn_batch_norm is faster and needs less
But cudnn_batch_norm is faster and needs less
memory than batch_norm. mkldnn_batch_norm requires
memory than batch_norm. mkldnn_batch_norm requires
enable use_mkldnn
. By default (None), we will
use_mkldnn is enabled
. By default (None), we will
automaticly select cudnn_batch_norm for GPU,
automatic
al
ly select cudnn_batch_norm for GPU,
mkldnn_batch_norm for MKLDNN and batch_norm for CPU.
mkldnn_batch_norm for MKLDNN and batch_norm for CPU.
Otherwise, select batch norm type based on th
e
Users can specify the batch norm type. If you us
e
specified type. If you use cudnn_batch_norm
,
cudnn_batch_norm, we suggested you use latest version
,
we suggested you use latest version,
such as v5.1.
such as v5.1.
:type batch_norm_type: None | string, None or "batch_norm" or "cudnn_batch_norm"
:type batch_norm_type: None | string, None or "batch_norm" or "cudnn_batch_norm"
or "mkldnn_batch_norm"
or "mkldnn_batch_norm"
:param act: Activation Type. Better be relu. Because batch
:param act: Activation type. ReluActivation is the default activation.
normalization will normalize input near zero.
:type act: BaseActivation
:type act: BaseActivation
:param num_channels:
num of image channels or previous layer's number of
:param num_channels:
The number of input channels. If the parameter is not set or
filters. None will automatically get from layer's
set to None, its actual value will be automatically set to
input.
the channels number of the
input.
:type num_channels: int
:type num_channels: int
:param bias_attr: :math:`
\\
beta`, better be zero when initialize. So the
:param bias_attr: :math:`
\\
beta`. The bias attribute. If the parameter is set to
initial_std=0, initial_mean=1 is best practice.
False or an object whose type is not ParameterAttribute, no
bias is defined. If the parameter is set to True, the bias is
initialized to zero.
:type bias_attr: ParameterAttribute | None | bool | Any
:type bias_attr: ParameterAttribute | None | bool | Any
:param param_attr: :math:`
\\
gamma`
, better be one when initialize. So th
e
:param param_attr: :math:`
\\
gamma`
. The parameter attribute. See ParameterAttribut
e
initial_std=0, initial_mean=1 is best practice
.
for details
.
:type param_attr: ParameterAttribute
:type param_attr: ParameterAttribute
:param layer_attr: Extra Layer Attribute.
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute for
details.
:type layer_attr: ExtraLayerAttribute
:type layer_attr: ExtraLayerAttribute
:param use_global_stats:
whether use moving mean/variance statistics
:param use_global_stats:
Whether use moving mean/variance statistics during
during testing peroid. If None or True,
testing peroid. If the parameter is set to None or
it will use moving mean/variance statistics during
True, it will use moving mean/variance statistics
testing. If False, it will use the mean
during testing. If the parameter is set to False, it
and variance of current batch of test data for
will use the mean and variance of the current batch
testing
.
of test data
.
:type use_global_stats: bool | None.
:type use_global_stats: bool | None.
:param moving_average_fraction: Factor used in the moving average
:param moving_average_fraction: Factor used in the moving average computation.
computation, referred to as facotr,
:math:`runningMean = newMean*(1-factor) + runningMean*factor`
:math:`runningMean = newMean*(1-factor)
+ runningMean*factor`
:type moving_average_fraction: float.
:type moving_average_fraction: float.
:param mean_var_names: [mean name, variance name]
:param mean_var_names: [mean name, variance name]
:type mean_var_names: string list
:type mean_var_names: string list
...
@@ -3164,8 +3169,9 @@ def sum_to_one_norm_layer(input, name=None, layer_attr=None):
...
@@ -3164,8 +3169,9 @@ def sum_to_one_norm_layer(input, name=None, layer_attr=None):
:type input: LayerOutput
:type input: LayerOutput
:param name: The name of this layer. It is optional.
:param name: The name of this layer. It is optional.
:type name: basestring
:type name: basestring
:param layer_attr: extra layer attributes.
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute
:type layer_attr: ExtraLayerAttribute.
for details.
:type layer_attr: ExtraLayerAttribute
:return: LayerOutput object.
:return: LayerOutput object.
:rtype: LayerOutput
:rtype: LayerOutput
"""
"""
...
@@ -3200,7 +3206,8 @@ def row_l2_norm_layer(input, name=None, layer_attr=None):
...
@@ -3200,7 +3206,8 @@ def row_l2_norm_layer(input, name=None, layer_attr=None):
:type input: LayerOutput
:type input: LayerOutput
:param name: The name of this layer. It is optional.
:param name: The name of this layer. It is optional.
:type name: basestring
:type name: basestring
:param layer_attr: extra layer attributes.
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute
for details.
:type layer_attr: ExtraLayerAttribute.
:type layer_attr: ExtraLayerAttribute.
:return: LayerOutput object.
:return: LayerOutput object.
:rtype: LayerOutput
:rtype: LayerOutput
...
@@ -3237,22 +3244,17 @@ def addto_layer(input, act=None, name=None, bias_attr=None, layer_attr=None):
...
@@ -3237,22 +3244,17 @@ def addto_layer(input, act=None, name=None, bias_attr=None, layer_attr=None):
act=ReluActivation(),
act=ReluActivation(),
bias_attr=False)
bias_attr=False)
This layer just simply add
all input layers together, then activate the sum
This layer just simply add
s all input layers together, then activates the
inputs. Each input of this layer should be the same size, which is also the
sum. All inputs should share the same dimension, which is also the dimension
o
utput size of this layer
.
o
f this layer's output
.
There is no weight matrix for each input, because it just a simple add
There is no weight matrix for each input, because it just a simple add
operation. If you want a complicated operation before add, please use
operation. If you want a complicated operation before add, please use
mixed_layer.
mixed_layer.
It is a very good way to set dropout outside the layers. Since not all
PaddlePaddle layer support dropout, you can add an add_to layer, set
dropout here.
Please refer to dropout_layer for details.
:param name: The name of this layer. It is optional.
:param name: The name of this layer. It is optional.
:type name: basestring
:type name: basestring
:param input:
I
nput layers. It could be a LayerOutput or list/tuple of
:param input:
The i
nput layers. It could be a LayerOutput or list/tuple of
LayerOutput.
LayerOutput.
:type input: LayerOutput | list | tuple
:type input: LayerOutput | list | tuple
:param act: Activation Type. LinearActivation is the default activation.
:param act: Activation Type. LinearActivation is the default activation.
...
@@ -3261,7 +3263,8 @@ def addto_layer(input, act=None, name=None, bias_attr=None, layer_attr=None):
...
@@ -3261,7 +3263,8 @@ def addto_layer(input, act=None, name=None, bias_attr=None, layer_attr=None):
whose type is not ParameterAttribute, no bias is defined. If the
whose type is not ParameterAttribute, no bias is defined. If the
parameter is set to True, the bias is initialized to zero.
parameter is set to True, the bias is initialized to zero.
:type bias_attr: ParameterAttribute | None | bool | Any
:type bias_attr: ParameterAttribute | None | bool | Any
:param layer_attr: Extra Layer attribute.
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute for
details.
:type layer_attr: ExtraLayerAttribute
:type layer_attr: ExtraLayerAttribute
:return: LayerOutput object.
:return: LayerOutput object.
:rtype: LayerOutput
:rtype: LayerOutput
...
@@ -3300,8 +3303,8 @@ def addto_layer(input, act=None, name=None, bias_attr=None, layer_attr=None):
...
@@ -3300,8 +3303,8 @@ def addto_layer(input, act=None, name=None, bias_attr=None, layer_attr=None):
@
layer_support
(
DROPOUT
,
ERROR_CLIPPING
)
@
layer_support
(
DROPOUT
,
ERROR_CLIPPING
)
def
concat_layer
(
input
,
act
=
None
,
name
=
None
,
layer_attr
=
None
,
bias_attr
=
None
):
def
concat_layer
(
input
,
act
=
None
,
name
=
None
,
layer_attr
=
None
,
bias_attr
=
None
):
"""
"""
Concat
all input vector into one hug
e vector.
Concat
enate all input vectors to on
e vector.
Inputs can be
list of LayerOutput or
list of projection.
Inputs can be
a list of LayerOutput or a
list of projection.
The example usage is:
The example usage is:
...
@@ -3311,11 +3314,12 @@ def concat_layer(input, act=None, name=None, layer_attr=None, bias_attr=None):
...
@@ -3311,11 +3314,12 @@ def concat_layer(input, act=None, name=None, layer_attr=None, bias_attr=None):
:param name: The name of this layer. It is optional.
:param name: The name of this layer. It is optional.
:type name: basestring
:type name: basestring
:param input: input layers or projections
:param input:
The
input layers or projections
:type input: list | tuple | collections.Sequence
:type input: list | tuple | collections.Sequence
:param act: Activation type. IdentityActivation is the default activation.
:param act: Activation type. IdentityActivation is the default activation.
:type act: BaseActivation
:type act: BaseActivation
:param layer_attr: Extra Layer Attribute.
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute for
details.
:type layer_attr: ExtraLayerAttribute
:type layer_attr: ExtraLayerAttribute
:return: LayerOutput object.
:return: LayerOutput object.
:rtype: LayerOutput
:rtype: LayerOutput
...
@@ -3385,7 +3389,7 @@ def concat_layer(input, act=None, name=None, layer_attr=None, bias_attr=None):
...
@@ -3385,7 +3389,7 @@ def concat_layer(input, act=None, name=None, layer_attr=None, bias_attr=None):
def
seq_concat_layer
(
a
,
b
,
act
=
None
,
name
=
None
,
layer_attr
=
None
,
def
seq_concat_layer
(
a
,
b
,
act
=
None
,
name
=
None
,
layer_attr
=
None
,
bias_attr
=
None
):
bias_attr
=
None
):
"""
"""
Concat
sequence a with
sequence b.
Concat
enate sequence a and
sequence b.
Inputs:
Inputs:
- a = [a1, a2, ..., am]
- a = [a1, a2, ..., am]
...
@@ -3404,13 +3408,14 @@ def seq_concat_layer(a, b, act=None, name=None, layer_attr=None,
...
@@ -3404,13 +3408,14 @@ def seq_concat_layer(a, b, act=None, name=None, layer_attr=None,
:param name: The name of this layer. It is optional.
:param name: The name of this layer. It is optional.
:type name: basestring
:type name: basestring
:param a: input sequence layer
:param a:
The first
input sequence layer
:type a: LayerOutput
:type a: LayerOutput
:param b: input sequence layer
:param b:
The second
input sequence layer
:type b: LayerOutput
:type b: LayerOutput
:param act: Activation type. IdentityActivation is the default activation.
:param act: Activation type. IdentityActivation is the default activation.
:type act: BaseActivation
:type act: BaseActivation
:param layer_attr: Extra Layer Attribute.
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute for
details.
:type layer_attr: ExtraLayerAttribute
:type layer_attr: ExtraLayerAttribute
:param bias_attr: The bias attribute. If the parameter is set to False or an object
:param bias_attr: The bias attribute. If the parameter is set to False or an object
whose type is not ParameterAttribute, no bias is defined. If the
whose type is not ParameterAttribute, no bias is defined. If the
...
@@ -3447,31 +3452,25 @@ def memory(name,
...
@@ -3447,31 +3452,25 @@ def memory(name,
boot_bias_active_type
=
None
,
boot_bias_active_type
=
None
,
boot_with_const_id
=
None
):
boot_with_const_id
=
None
):
"""
"""
The memory layers is a layer cross each time step. Reference this output
The memory takes a layer's output at previous time step as its own output.
as previous time step layer :code:`name` 's output.
The default memory is zero in first time step, previous time step's
If boot_bias, the activation of the bias is the initial value of the memory.
output in the rest time steps.
If boot_
bias, the first time step value is this bias and
If boot_
with_const_id is set, then the memory's output at the first time step
with activation
.
is a IndexSlot, the Arguments.ids()[0] is this :code:`cost_id`
.
If boot_
with_const_id, then the first time stop is a IndexSlot, the
If boot_
layer is specified, the memory's output at the first time step will
Arguments.ids()[0] is this :code:`cost_id`
.
be the boot_layer's output
.
If boot_layer is not null, the memory is just the boot_layer's output.
In other case, the default memory's output at the first time step is zero.
Set :code:`is_seq` is true boot layer is sequence.
The same name layer in recurrent group will set memory on each time
step.
.. code-block:: python
.. code-block:: python
mem = memory(size=256, name='state')
mem = memory(size=256, name='state')
state = fc_layer(input=mem, size=256, name='state')
state = fc_layer(input=mem, size=256, name='state')
If you do not want to specify the name, you can
equivalently
use set_input()
If you do not want to specify the name, you can
also
use set_input()
to specify the layer
needs
to be remembered as the following:
to specify the layer to be remembered as the following:
.. code-block:: python
.. code-block:: python
...
@@ -3479,26 +3478,31 @@ def memory(name,
...
@@ -3479,26 +3478,31 @@ def memory(name,
state = fc_layer(input=mem, size=256)
state = fc_layer(input=mem, size=256)
mem.set_input(mem)
mem.set_input(mem)
:param name:
t
he name of the layer which this memory remembers.
:param name:
T
he name of the layer which this memory remembers.
If name is None, user should call set_input() to specify the
If name is None, user should call set_input() to specify the
name of the layer which this memory remembers.
name of the layer which this memory remembers.
:type name: basestring
:type name: basestring
:param size:
size
of memory.
:param size:
The dimensionality
of memory.
:type size: int
:type size: int
:param memory_name: the name of the memory.
:param memory_name: The name of the memory. It is ignored when name is provided.
It is ignored when name is provided.
:type memory_name: basestring
:type memory_name: basestring
:param is_seq: DEPRECATED. is sequence for boot_layer
:param is_seq: DEPRECATED. is sequence for boot_layer
:type is_seq: bool
:type is_seq: bool
:param boot_layer: boot layer of memory.
:param boot_layer: This parameter specifies memory's output at the first time
step and the output is boot_layer's output.
:type boot_layer: LayerOutput | None
:type boot_layer: LayerOutput | None
:param boot_bias: boot layer's bias
:param boot_bias: The bias attribute of memory's output at the first time step.
If the parameter is set to False or an object whose type is not
ParameterAttribute, no bias is defined. If the parameter is set
to True, the bias is initialized to zero.
:type boot_bias: ParameterAttribute | None
:type boot_bias: ParameterAttribute | None
:param boot_bias_active_type: boot layer's active type.
:param boot_bias_active_type: Activation type for memory's bias at the first time
step. LinearActivation is the default activation.
:type boot_bias_active_type: BaseActivation
:type boot_bias_active_type: BaseActivation
:param boot_with_const_id: boot layer's id.
:param boot_with_const_id: This parameter specifies memory's output at the first
time step and the output is an index.
:type boot_with_const_id: int
:type boot_with_const_id: int
:return: LayerOutput object
which is a memory
.
:return: LayerOutput object.
:rtype: LayerOutput
:rtype: LayerOutput
"""
"""
if
boot_bias_active_type
is
None
:
if
boot_bias_active_type
is
None
:
...
...
python/paddle/v2/f
ramework
/tests/test_beam_search_op.py
→
python/paddle/v2/f
luid
/tests/test_beam_search_op.py
浏览文件 @
3dcf0da9
import
logging
import
logging
from
paddle.v2.f
ramework
.op
import
Operator
,
DynamicRecurrentOp
from
paddle.v2.f
luid
.op
import
Operator
,
DynamicRecurrentOp
import
paddle.v2.f
ramework
.core
as
core
import
paddle.v2.f
luid
.core
as
core
import
unittest
import
unittest
import
numpy
as
np
import
numpy
as
np
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录