@@ -4262,30 +4262,39 @@ def group_norm(input,
4262
4262
4263
4263
Refer to `Group Normalization <https://arxiv.org/abs/1803.08494>`_ .
4264
4264
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` .
4279
4285
4280
4286
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'.
4282
4291
4283
4292
Examples:
4293
+ .. code-block:: python
4284
4294
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)
4289
4298
"""
4290
4299
helper = LayerHelper('group_norm', **locals())
4291
4300
dtype = helper.input_dtype()
@@ -10206,59 +10215,57 @@ def crop_tensor(x, shape=None, offsets=None, name=None):
10206
10215
10207
10216
.. code-block:: text
10208
10217
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:
10218
10228
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],
10234
10244
[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].
10246
10254
If Variable contained, it is suitable for the case that the shape may
10247
10255
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
10249
10257
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` .
10259
10266
10260
10267
Returns:
10261
- Variable: The cropped tensor variable .
10268
+ Variable: The cropped Tensor has same data type with `x` .
10262
10269
10263
10270
Raises:
10264
10271
ValueError: If shape is not a list, tuple or Variable.
@@ -10269,31 +10276,31 @@ def crop_tensor(x, shape=None, offsets=None, name=None):
10269
10276
.. code-block:: python
10270
10277
10271
10278
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")
10273
10280
# x.shape = [-1, 3, 5], where -1 indicates batch size, and it will get the exact value in runtime.
10274
10281
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")
10277
10284
crop0 = fluid.layers.crop_tensor(x, shape=crop_shape)
10278
10285
# crop0.shape = [-1, -1, -1], it means crop0.shape[0] = x.shape[0] in runtime.
10279
10286
10280
10287
# or shape is a list in which each element is a constant
10281
10288
crop1 = fluid.layers.crop_tensor(x, shape=[-1, 2, 3])
10282
10289
# crop1.shape = [-1, 2, 3]
10283
10290
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]
10289
10296
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")
10292
10299
crop3 = fluid.layers.crop_tensor(x, shape=[-1, 2, 3], offsets=crop_offsets)
10293
10300
# crop3.shape = [-1, 2, 3]
10294
10301
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")
10297
10304
crop4 = fluid.layers.crop_tensor(x, shape=[-1, 2, 3], offsets=[0, 1, offsets_var])
10298
10305
# crop4.shape = [-1, 2, 3]
10299
10306
0 commit comments