提交 2087f771 编写于 作者: Z Zhang Ting 提交者: hong

modified doc of crop_tensor, test=develop, test=document_fix (#20203)

上级 6bc4d488
...@@ -223,7 +223,7 @@ paddle.fluid.layers.relu (ArgSpec(args=['x', 'name'], varargs=None, keywords=Non ...@@ -223,7 +223,7 @@ paddle.fluid.layers.relu (ArgSpec(args=['x', 'name'], varargs=None, keywords=Non
paddle.fluid.layers.selu (ArgSpec(args=['x', 'scale', 'alpha', 'name'], varargs=None, keywords=None, defaults=(None, None, None)), ('document', 'f93c61f5b0bf933cd425a64dca2c4fdd')) paddle.fluid.layers.selu (ArgSpec(args=['x', 'scale', 'alpha', 'name'], varargs=None, keywords=None, defaults=(None, None, None)), ('document', 'f93c61f5b0bf933cd425a64dca2c4fdd'))
paddle.fluid.layers.log (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '02f668664e3bfc4df6c00d7363467140')) paddle.fluid.layers.log (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '02f668664e3bfc4df6c00d7363467140'))
paddle.fluid.layers.crop (ArgSpec(args=['x', 'shape', 'offsets', 'name'], varargs=None, keywords=None, defaults=(None, None, None)), ('document', 'ba3621917d5beffd3d022b88fbf6dc46')) paddle.fluid.layers.crop (ArgSpec(args=['x', 'shape', 'offsets', 'name'], varargs=None, keywords=None, defaults=(None, None, None)), ('document', 'ba3621917d5beffd3d022b88fbf6dc46'))
paddle.fluid.layers.crop_tensor (ArgSpec(args=['x', 'shape', 'offsets', 'name'], varargs=None, keywords=None, defaults=(None, None, None)), ('document', 'cb855453e3506bf54c5c013616ffddfb')) paddle.fluid.layers.crop_tensor (ArgSpec(args=['x', 'shape', 'offsets', 'name'], varargs=None, keywords=None, defaults=(None, None, None)), ('document', 'd460aaf35afbbeb9beea4789aa6e4343'))
paddle.fluid.layers.rank_loss (ArgSpec(args=['label', 'left', 'right', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '8eb36596bb43d7a907d3397c7aedbdb3')) paddle.fluid.layers.rank_loss (ArgSpec(args=['label', 'left', 'right', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '8eb36596bb43d7a907d3397c7aedbdb3'))
paddle.fluid.layers.margin_rank_loss (ArgSpec(args=['label', 'left', 'right', 'margin', 'name'], varargs=None, keywords=None, defaults=(0.1, None)), ('document', '6fc86ed23b420c8a0f6c043563cf3937')) paddle.fluid.layers.margin_rank_loss (ArgSpec(args=['label', 'left', 'right', 'margin', 'name'], varargs=None, keywords=None, defaults=(0.1, None)), ('document', '6fc86ed23b420c8a0f6c043563cf3937'))
paddle.fluid.layers.elu (ArgSpec(args=['x', 'alpha', 'name'], varargs=None, keywords=None, defaults=(1.0, None)), ('document', '9af1926c06711eacef9e82d7a9e4d308')) paddle.fluid.layers.elu (ArgSpec(args=['x', 'alpha', 'name'], varargs=None, keywords=None, defaults=(1.0, None)), ('document', '9af1926c06711eacef9e82d7a9e4d308'))
......
...@@ -10267,59 +10267,57 @@ def crop_tensor(x, shape=None, offsets=None, name=None): ...@@ -10267,59 +10267,57 @@ def crop_tensor(x, shape=None, offsets=None, name=None):
.. code-block:: text .. code-block:: text
* Case 1: * Case 1 (input is a 2-D Tensor):
Given Input:
X = [[0, 1, 2, 0, 0] X.shape = [3. 5]
[0, 3, 4, 0, 0] X.data = [[0, 1, 2, 0, 0],
[0, 0, 0, 0, 0]], [0, 3, 4, 0, 0],
and [0, 0, 0, 0, 0]]
shape = [2, 2], Parameters:
offsets = [0, 1], shape = [2, 2]
output is: offsets = [0, 1]
Output:
Out = [[1, 2], Out = [[1, 2],
[3, 4]]. [3, 4]]
* Case 2: * Case 2 (input is a 3-D Tensor):
Given Input:
X = [[[0, 1, 2, 3] X.shape = [2, 3, 4]
[0, 5, 6, 7] X.data = [[[0, 1, 2, 3],
[0, 0, 0, 0]], [0, 5, 6, 7],
[0, 0, 0, 0]],
[[0, 3, 4, 5] [[0, 3, 4, 5],
[0, 6, 7, 8] [0, 6, 7, 8],
[0, 0, 0, 0]]]. [0, 0, 0, 0]]]
and Parameters:
shape = [2, 2, 3], shape = [2, 2, 3]
offsets = [0, 0, 1], offsets = [0, 0, 1]
output is: Output:
Out = [[[1, 2, 3] Out = [[[1, 2, 3],
[5, 6, 7]], [5, 6, 7]],
[[3, 4, 5],
[[3, 4, 5] [6, 7, 8]]]
[6, 7, 8]]].
Parameters:
Args: x (Variable): 1-D to 6-D Tensor, the data type is float32 or float64.
x (Variable): The input tensor variable. shape (list|tuple|Variable): The output shape is specified
shape (Variable|list|tuple of integer): The output shape is specified by `shape`. Its data type is int32. If a list/tuple, it's length must be
by `shape`. It can be a 1-D tensor Variable or a list/tuple. If a the same as the dimension size of `x`. If a Variable, it shoule be a 1-D Tensor.
1-D tensor Variable, it's rank must be the same as `x`. If a When it is a list, each element can be an integer or a Tensor of shape: [1].
list/tuple, it's length must be the same as the rank of `x`. Each
element of list can be an integer or a tensor Variable of shape: [1].
If Variable contained, it is suitable for the case that the shape may If Variable contained, it is suitable for the case that the shape may
be changed each iteration. Only the first element of list/tuple can be be changed each iteration. Only the first element of list/tuple can be
set to -1, it means that the first dimension of the output is the same set to -1, it means that the first dimension's size of the output is the same
as the input. as the input.
offsets (Variable|list|tuple of integer|None): Specifies the cropping offsets (list|tuple|Variable, optional): Specifies the cropping
offsets at each dimension. It can be a 1-D tensor Variable or a list/tuple. offsets at each dimension. Its data type is int32. If a list/tuple, it's length
If a 1-D tensor Variable, it's rank must be the same as `x`. If a list/tuple, must be the same as the dimension size of `x`. If a Variable, it shoule be a 1-D
it's length must be the same as the rank of `x`. Each element of list can be Tensor. When it is a list, each element can be an integer or a Tensor of shape: [1].
an integer or a tensor Variable of shape: [1]. If Variable contained, it is If Variable contained, it is suitable for the case that the offsets may be changed
suitable for the case that the offsets may be changed each iteration. If None, each iteration. Default: None, the offsets are 0 at each dimension.
the offsets are 0 at each dimension. name(str, optional): The default value is None. Normally there is no need for user to set
name(str|None): A name for this layer(optional). If set None, the layer this property. For more information, please refer to :ref:`api_guide_Name` .
will be named automatically.
Returns: Returns:
Variable: The cropped tensor variable. Variable: The cropped Tensor has same data type with `x`.
Raises: Raises:
ValueError: If shape is not a list, tuple or Variable. ValueError: If shape is not a list, tuple or Variable.
...@@ -10330,11 +10328,11 @@ def crop_tensor(x, shape=None, offsets=None, name=None): ...@@ -10330,11 +10328,11 @@ def crop_tensor(x, shape=None, offsets=None, name=None):
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle.fluid as fluid
x = fluid.layers.data(name="x", shape=[3, 5], dtype="float32") x = fluid.data(name="x", shape=[None, 3, 5], dtype="float32")
# x.shape = [-1, 3, 5], where -1 indicates batch size, and it will get the exact value in runtime. # x.shape = [-1, 3, 5], where -1 indicates batch size, and it will get the exact value in runtime.
# shape is a 1-D tensor variable # shape is a 1-D Tensor
crop_shape = fluid.layers.data(name="crop_shape", shape=[3], dtype="int32", append_batch_size=False) crop_shape = fluid.data(name="crop_shape", shape=[3], dtype="int32")
crop0 = fluid.layers.crop_tensor(x, shape=crop_shape) crop0 = fluid.layers.crop_tensor(x, shape=crop_shape)
# crop0.shape = [-1, -1, -1], it means crop0.shape[0] = x.shape[0] in runtime. # crop0.shape = [-1, -1, -1], it means crop0.shape[0] = x.shape[0] in runtime.
...@@ -10342,19 +10340,19 @@ def crop_tensor(x, shape=None, offsets=None, name=None): ...@@ -10342,19 +10340,19 @@ def crop_tensor(x, shape=None, offsets=None, name=None):
crop1 = fluid.layers.crop_tensor(x, shape=[-1, 2, 3]) crop1 = fluid.layers.crop_tensor(x, shape=[-1, 2, 3])
# crop1.shape = [-1, 2, 3] # crop1.shape = [-1, 2, 3]
# or shape is a list in which each element is a constant or variable # or shape is a list in which each element is a constant or Variable
y = fluid.layers.data(name="y", shape=[3, 8, 8], dtype="float32") y = fluid.data(name="y", shape=[3, 8, 8], dtype="float32")
dim1 = fluid.layers.data(name="dim1", shape=[1], dtype="int32", append_batch_size=False) dim1 = fluid.data(name="dim1", shape=[1], dtype="int32")
crop2 = fluid.layers.crop_tensor(y, shape=[-1, 3, dim1, 4]) crop2 = fluid.layers.crop_tensor(y, shape=[3, dim1, 4])
# crop2.shape = [-1, 3, -1, 4] # crop2.shape = [3, -1, 4]
# offsets is a 1-D tensor variable # offsets is a 1-D Tensor
crop_offsets = fluid.layers.data(name="crop_offsets", shape=[3], dtype="int32", append_batch_size=False) crop_offsets = fluid.data(name="crop_offsets", shape=[3], dtype="int32")
crop3 = fluid.layers.crop_tensor(x, shape=[-1, 2, 3], offsets=crop_offsets) crop3 = fluid.layers.crop_tensor(x, shape=[-1, 2, 3], offsets=crop_offsets)
# crop3.shape = [-1, 2, 3] # crop3.shape = [-1, 2, 3]
# offsets is a list in which each element is a constant or variable # offsets is a list in which each element is a constant or Variable
offsets_var = fluid.layers.data(name="dim1", shape=[1], dtype="int32", append_batch_size=False) offsets_var = fluid.data(name="dim1", shape=[1], dtype="int32")
crop4 = fluid.layers.crop_tensor(x, shape=[-1, 2, 3], offsets=[0, 1, offsets_var]) crop4 = fluid.layers.crop_tensor(x, shape=[-1, 2, 3], offsets=[0, 1, offsets_var])
# crop4.shape = [-1, 2, 3] # crop4.shape = [-1, 2, 3]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册