Skip to content

Commit f25834a

Browse files
zhangting2020Aurelius84
authored andcommitted
[cherry-pick] modified docs of group_norm and crop_tensor (#20339)
* [cherry-pick] modified doc of group_norm, test=release/1.6, test=document_fix (#20234) * [cherry-pick] modified doc of crop_tensor, test=release/1.6, test=document_fix (#20203)
1 parent f72d82c commit f25834a

File tree

2 files changed

+86
-79
lines changed

2 files changed

+86
-79
lines changed

paddle/fluid/API.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ paddle.fluid.layers.beam_search (ArgSpec(args=['pre_ids', 'pre_scores', 'ids', '
188188
paddle.fluid.layers.row_conv (ArgSpec(args=['input', 'future_context_size', 'param_attr', 'act'], varargs=None, keywords=None, defaults=(None, None)), ('document', '1d8a1c8b686b55631ba1b77805e4eacf'))
189189
paddle.fluid.layers.multiplex (ArgSpec(args=['inputs', 'index'], varargs=None, keywords=None, defaults=None), ('document', '2c4d1ae83da6ed35e3b36ba1b3b51d23'))
190190
paddle.fluid.layers.layer_norm (ArgSpec(args=['input', 'scale', 'shift', 'begin_norm_axis', 'epsilon', 'param_attr', 'bias_attr', 'act', 'name'], varargs=None, keywords=None, defaults=(True, True, 1, 1e-05, None, None, None, None)), ('document', '79797f827d89ae72c77960e9696883a9'))
191-
paddle.fluid.layers.group_norm (ArgSpec(args=['input', 'groups', 'epsilon', 'param_attr', 'bias_attr', 'act', 'data_layout', 'name'], varargs=None, keywords=None, defaults=(1e-05, None, None, None, 'NCHW', None)), ('document', '65231cc8281815124934b1439fbb750c'))
191+
paddle.fluid.layers.group_norm (ArgSpec(args=['input', 'groups', 'epsilon', 'param_attr', 'bias_attr', 'act', 'data_layout', 'name'], varargs=None, keywords=None, defaults=(1e-05, None, None, None, 'NCHW', None)), ('document', '87dd4b818f102bc1a780e1804c28bd38'))
192192
paddle.fluid.layers.spectral_norm (ArgSpec(args=['weight', 'dim', 'power_iters', 'eps', 'name'], varargs=None, keywords=None, defaults=(0, 1, 1e-12, None)), ('document', '9461e67095a6fc5d568fb2ce8fef66ff'))
193193
paddle.fluid.layers.softmax_with_cross_entropy (ArgSpec(args=['logits', 'label', 'soft_label', 'ignore_index', 'numeric_stable_mode', 'return_softmax', 'axis'], varargs=None, keywords=None, defaults=(False, -100, True, False, -1)), ('document', '54e1675aa0364f4a78fa72804ec0f413'))
194194
paddle.fluid.layers.smooth_l1 (ArgSpec(args=['x', 'y', 'inside_weight', 'outside_weight', 'sigma'], varargs=None, keywords=None, defaults=(None, None, None)), ('document', 'cbe8940643ac80ef75e1abdfbdb09e88'))
@@ -223,7 +223,7 @@ paddle.fluid.layers.relu (ArgSpec(args=['x', 'name'], varargs=None, keywords=Non
223223
paddle.fluid.layers.selu (ArgSpec(args=['x', 'scale', 'alpha', 'name'], varargs=None, keywords=None, defaults=(None, None, None)), ('document', 'f93c61f5b0bf933cd425a64dca2c4fdd'))
224224
paddle.fluid.layers.log (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '02f668664e3bfc4df6c00d7363467140'))
225225
paddle.fluid.layers.crop (ArgSpec(args=['x', 'shape', 'offsets', 'name'], varargs=None, keywords=None, defaults=(None, None, None)), ('document', 'ba3621917d5beffd3d022b88fbf6dc46'))
226-
paddle.fluid.layers.crop_tensor (ArgSpec(args=['x', 'shape', 'offsets', 'name'], varargs=None, keywords=None, defaults=(None, None, None)), ('document', 'cb855453e3506bf54c5c013616ffddfb'))
226+
paddle.fluid.layers.crop_tensor (ArgSpec(args=['x', 'shape', 'offsets', 'name'], varargs=None, keywords=None, defaults=(None, None, None)), ('document', 'd460aaf35afbbeb9beea4789aa6e4343'))
227227
paddle.fluid.layers.rank_loss (ArgSpec(args=['label', 'left', 'right', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '8eb36596bb43d7a907d3397c7aedbdb3'))
228228
paddle.fluid.layers.margin_rank_loss (ArgSpec(args=['label', 'left', 'right', 'margin', 'name'], varargs=None, keywords=None, defaults=(0.1, None)), ('document', '6fc86ed23b420c8a0f6c043563cf3937'))
229229
paddle.fluid.layers.elu (ArgSpec(args=['x', 'alpha', 'name'], varargs=None, keywords=None, defaults=(1.0, None)), ('document', '9af1926c06711eacef9e82d7a9e4d308'))

python/paddle/fluid/layers/nn.py

Lines changed: 84 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4262,30 +4262,39 @@ def group_norm(input,
42624262

42634263
Refer to `Group Normalization <https://arxiv.org/abs/1803.08494>`_ .
42644264

4265-
Args:
4266-
input(Variable): The input tensor variable.
4267-
groups(int): The number of groups that divided from channels.
4268-
epsilon(float): The small value added to the variance to prevent
4269-
division by zero.
4270-
param_attr(ParamAttr|None): The parameter attribute for the learnable
4271-
scale :math:`g`. If it is set to False, no scale will be added to the output units.
4272-
If it is set to None, the bias is initialized one. Default: None.
4273-
bias_attr(ParamAttr|None): The parameter attribute for the learnable
4274-
bias :math:`b`. If it is set to False, no bias will be added to the output units.
4275-
If it is set to None, the bias is initialized zero. Default: None.
4276-
act(str): Activation to be applied to the output of group normalizaiton.
4277-
data_layout(string, default NCHW): NCHW(num_batch, channels, h, w) or NHWC(num_batch, h, w, channels).
4278-
name (str): The name of this layer. It is optional.
4265+
Parameters:
4266+
input(Variable): 4-D Tensor, the data type is float32 or float64.
4267+
groups(int): The number of groups that divided from channels, the data type
4268+
is int32.
4269+
epsilon(float, optional): The small value added to the variance to prevent
4270+
division by zero, the data type is float32. Default: 1e-05.
4271+
param_attr(ParamAttr|bool, optional): ParamAttr object that specifies weight parameter
4272+
attribute. If a bool type, only False is supported, which means there is no weight parameter.
4273+
Default: None, the default weight parameter attribute is used. For more information, please
4274+
refer to :ref:`api_guide_ParamAttr` .
4275+
bias_attr(ParamAttr|bool, optional): ParamAttr object that specifies bias parameter
4276+
attribute. If a bool type, only False is supported, which means there is no bias parameter.
4277+
Default: None, the default bias parameter attribute is used. For more information, please
4278+
refer to :ref:`api_guide_ParamAttr` .
4279+
act(str, optional): Activation to be applied to the output of group normalizaiton.
4280+
data_layout(str, optional): The data format of the input and output data. An optional string
4281+
from: `"NCHW"`, `"NHWC"`. When it is `"NCHW"`, the data is stored in the order of:
4282+
`[batch_size, channels, height, width]`. Default: "NCHW".
4283+
name (str, optional): The default value is None. Normally there is no need for user to set this
4284+
property. For more information, please refer to :ref:`api_guide_Name` .
42794285

42804286
Returns:
4281-
Variable: A tensor variable which is the result after applying group normalization on the input.
4287+
Variable: A 4-D Tensor has same data type and data format with `input`.
4288+
4289+
Raises:
4290+
ValueError: If `data_layout` is neither 'NCHW' nor 'NHWC'.
42824291

42834292
Examples:
4293+
.. code-block:: python
42844294

4285-
>>> import paddle.fluid as fluid
4286-
>>> data = fluid.layers.data(name='data', shape=[8, 32, 32],
4287-
>>> dtype='float32')
4288-
>>> x = fluid.layers.group_norm(input=data, groups=4)
4295+
import paddle.fluid as fluid
4296+
data = fluid.data(name='data', shape=[None, 8, 32, 32], dtype='float32')
4297+
x = fluid.layers.group_norm(input=data, groups=4)
42894298
"""
42904299
helper = LayerHelper('group_norm', **locals())
42914300
dtype = helper.input_dtype()
@@ -10206,59 +10215,57 @@ def crop_tensor(x, shape=None, offsets=None, name=None):
1020610215

1020710216
.. code-block:: text
1020810217

10209-
* Case 1:
10210-
Given
10211-
X = [[0, 1, 2, 0, 0]
10212-
[0, 3, 4, 0, 0]
10213-
[0, 0, 0, 0, 0]],
10214-
and
10215-
shape = [2, 2],
10216-
offsets = [0, 1],
10217-
output is:
10218+
* Case 1 (input is a 2-D Tensor):
10219+
Input:
10220+
X.shape = [3. 5]
10221+
X.data = [[0, 1, 2, 0, 0],
10222+
[0, 3, 4, 0, 0],
10223+
[0, 0, 0, 0, 0]]
10224+
Parameters:
10225+
shape = [2, 2]
10226+
offsets = [0, 1]
10227+
Output:
1021810228
Out = [[1, 2],
10219-
[3, 4]].
10220-
* Case 2:
10221-
Given
10222-
X = [[[0, 1, 2, 3]
10223-
[0, 5, 6, 7]
10224-
[0, 0, 0, 0]],
10225-
10226-
[[0, 3, 4, 5]
10227-
[0, 6, 7, 8]
10228-
[0, 0, 0, 0]]].
10229-
and
10230-
shape = [2, 2, 3],
10231-
offsets = [0, 0, 1],
10232-
output is:
10233-
Out = [[[1, 2, 3]
10229+
[3, 4]]
10230+
* Case 2 (input is a 3-D Tensor):
10231+
Input:
10232+
X.shape = [2, 3, 4]
10233+
X.data = [[[0, 1, 2, 3],
10234+
[0, 5, 6, 7],
10235+
[0, 0, 0, 0]],
10236+
[[0, 3, 4, 5],
10237+
[0, 6, 7, 8],
10238+
[0, 0, 0, 0]]]
10239+
Parameters:
10240+
shape = [2, 2, 3]
10241+
offsets = [0, 0, 1]
10242+
Output:
10243+
Out = [[[1, 2, 3],
1023410244
[5, 6, 7]],
10235-
10236-
[[3, 4, 5]
10237-
[6, 7, 8]]].
10238-
10239-
Args:
10240-
x (Variable): The input tensor variable.
10241-
shape (Variable|list|tuple of integer): The output shape is specified
10242-
by `shape`. It can be a 1-D tensor Variable or a list/tuple. If a
10243-
1-D tensor Variable, it's rank must be the same as `x`. If a
10244-
list/tuple, it's length must be the same as the rank of `x`. Each
10245-
element of list can be an integer or a tensor Variable of shape: [1].
10245+
[[3, 4, 5],
10246+
[6, 7, 8]]]
10247+
10248+
Parameters:
10249+
x (Variable): 1-D to 6-D Tensor, the data type is float32 or float64.
10250+
shape (list|tuple|Variable): The output shape is specified
10251+
by `shape`. Its data type is int32. If a list/tuple, it's length must be
10252+
the same as the dimension size of `x`. If a Variable, it shoule be a 1-D Tensor.
10253+
When it is a list, each element can be an integer or a Tensor of shape: [1].
1024610254
If Variable contained, it is suitable for the case that the shape may
1024710255
be changed each iteration. Only the first element of list/tuple can be
10248-
set to -1, it means that the first dimension of the output is the same
10256+
set to -1, it means that the first dimension's size of the output is the same
1024910257
as the input.
10250-
offsets (Variable|list|tuple of integer|None): Specifies the cropping
10251-
offsets at each dimension. It can be a 1-D tensor Variable or a list/tuple.
10252-
If a 1-D tensor Variable, it's rank must be the same as `x`. If a list/tuple,
10253-
it's length must be the same as the rank of `x`. Each element of list can be
10254-
an integer or a tensor Variable of shape: [1]. If Variable contained, it is
10255-
suitable for the case that the offsets may be changed each iteration. If None,
10256-
the offsets are 0 at each dimension.
10257-
name(str|None): A name for this layer(optional). If set None, the layer
10258-
will be named automatically.
10258+
offsets (list|tuple|Variable, optional): Specifies the cropping
10259+
offsets at each dimension. Its data type is int32. If a list/tuple, it's length
10260+
must be the same as the dimension size of `x`. If a Variable, it shoule be a 1-D
10261+
Tensor. When it is a list, each element can be an integer or a Tensor of shape: [1].
10262+
If Variable contained, it is suitable for the case that the offsets may be changed
10263+
each iteration. Default: None, the offsets are 0 at each dimension.
10264+
name(str, optional): The default value is None. Normally there is no need for user to set
10265+
this property. For more information, please refer to :ref:`api_guide_Name` .
1025910266

1026010267
Returns:
10261-
Variable: The cropped tensor variable.
10268+
Variable: The cropped Tensor has same data type with `x`.
1026210269

1026310270
Raises:
1026410271
ValueError: If shape is not a list, tuple or Variable.
@@ -10269,31 +10276,31 @@ def crop_tensor(x, shape=None, offsets=None, name=None):
1026910276
.. code-block:: python
1027010277

1027110278
import paddle.fluid as fluid
10272-
x = fluid.layers.data(name="x", shape=[3, 5], dtype="float32")
10279+
x = fluid.data(name="x", shape=[None, 3, 5], dtype="float32")
1027310280
# x.shape = [-1, 3, 5], where -1 indicates batch size, and it will get the exact value in runtime.
1027410281

10275-
# shape is a 1-D tensor variable
10276-
crop_shape = fluid.layers.data(name="crop_shape", shape=[3], dtype="int32", append_batch_size=False)
10282+
# shape is a 1-D Tensor
10283+
crop_shape = fluid.data(name="crop_shape", shape=[3], dtype="int32")
1027710284
crop0 = fluid.layers.crop_tensor(x, shape=crop_shape)
1027810285
# crop0.shape = [-1, -1, -1], it means crop0.shape[0] = x.shape[0] in runtime.
1027910286

1028010287
# or shape is a list in which each element is a constant
1028110288
crop1 = fluid.layers.crop_tensor(x, shape=[-1, 2, 3])
1028210289
# crop1.shape = [-1, 2, 3]
1028310290

10284-
# or shape is a list in which each element is a constant or variable
10285-
y = fluid.layers.data(name="y", shape=[3, 8, 8], dtype="float32")
10286-
dim1 = fluid.layers.data(name="dim1", shape=[1], dtype="int32", append_batch_size=False)
10287-
crop2 = fluid.layers.crop_tensor(y, shape=[-1, 3, dim1, 4])
10288-
# crop2.shape = [-1, 3, -1, 4]
10291+
# or shape is a list in which each element is a constant or Variable
10292+
y = fluid.data(name="y", shape=[3, 8, 8], dtype="float32")
10293+
dim1 = fluid.data(name="dim1", shape=[1], dtype="int32")
10294+
crop2 = fluid.layers.crop_tensor(y, shape=[3, dim1, 4])
10295+
# crop2.shape = [3, -1, 4]
1028910296

10290-
# offsets is a 1-D tensor variable
10291-
crop_offsets = fluid.layers.data(name="crop_offsets", shape=[3], dtype="int32", append_batch_size=False)
10297+
# offsets is a 1-D Tensor
10298+
crop_offsets = fluid.data(name="crop_offsets", shape=[3], dtype="int32")
1029210299
crop3 = fluid.layers.crop_tensor(x, shape=[-1, 2, 3], offsets=crop_offsets)
1029310300
# crop3.shape = [-1, 2, 3]
1029410301

10295-
# offsets is a list in which each element is a constant or variable
10296-
offsets_var = fluid.layers.data(name="dim1", shape=[1], dtype="int32", append_batch_size=False)
10302+
# offsets is a list in which each element is a constant or Variable
10303+
offsets_var = fluid.data(name="dim1", shape=[1], dtype="int32")
1029710304
crop4 = fluid.layers.crop_tensor(x, shape=[-1, 2, 3], offsets=[0, 1, offsets_var])
1029810305
# crop4.shape = [-1, 2, 3]
1029910306

0 commit comments

Comments
 (0)