From 941079714c61772d163e2a5cd8b44f66d7575484 Mon Sep 17 00:00:00 2001 From: Bai Yifan Date: Thu, 10 Oct 2019 16:20:00 +0800 Subject: [PATCH] [cherry-pick] 1.6 for english doc (#20388) * cherry pick for 131b1dc3240e53ea295cc49323bb2a7e7dcc717f, test=develop, test=document_fix * cherry pick for fb21a743aed5106abdc68eb9fe4696ad7518633e, test=develop, test=document_fix --- paddle/fluid/API.spec | 8 +-- python/paddle/fluid/layers/detection.py | 10 ++-- python/paddle/fluid/layers/nn.py | 79 ++++++++++++++----------- 3 files changed, 56 insertions(+), 41 deletions(-) diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index d99332bc47..d6e65f3e04 100755 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -236,7 +236,7 @@ paddle.fluid.layers.prelu (ArgSpec(args=['x', 'mode', 'param_attr', 'name'], var paddle.fluid.layers.brelu (ArgSpec(args=['x', 't_min', 't_max', 'name'], varargs=None, keywords=None, defaults=(0.0, 24.0, None)), ('document', '49580538249a52c857fce75c94ad8af7')) paddle.fluid.layers.leaky_relu (ArgSpec(args=['x', 'alpha', 'name'], varargs=None, keywords=None, defaults=(0.02, None)), ('document', '1eb3009c69060299ec87949ee0d4b9ae')) paddle.fluid.layers.soft_relu (ArgSpec(args=['x', 'threshold', 'name'], varargs=None, keywords=None, defaults=(40.0, None)), ('document', '6455afd2498b00198f53f83d63d6c6a4')) -paddle.fluid.layers.flatten (ArgSpec(args=['x', 'axis', 'name'], varargs=None, keywords=None, defaults=(1, None)), ('document', 'b52306659a21e6b118eed49fe2c155a1')) +paddle.fluid.layers.flatten (ArgSpec(args=['x', 'axis', 'name'], varargs=None, keywords=None, defaults=(1, None)), ('document', '424ff350578992f201f2c5c30959ef89')) paddle.fluid.layers.sequence_mask (ArgSpec(args=['x', 'maxlen', 'dtype', 'name'], varargs=None, keywords=None, defaults=(None, 'int64', None)), ('document', '6c3f916921b24edaad220f1fcbf039de')) paddle.fluid.layers.stack (ArgSpec(args=['x', 'axis'], varargs=None, keywords=None, defaults=(0,)), ('document', 'a76f347bf27ffe21b990340d5d9524d5')) paddle.fluid.layers.pad2d (ArgSpec(args=['input', 'paddings', 'mode', 'pad_value', 'data_format', 'name'], varargs=None, keywords=None, defaults=([0, 0, 0, 0], 'constant', 0.0, 'NCHW', None)), ('document', '3f3abdb795a5c2aad8c2312249551ce5')) @@ -299,11 +299,11 @@ paddle.fluid.layers.huber_loss (ArgSpec(args=['input', 'label', 'delta'], vararg paddle.fluid.layers.kldiv_loss (ArgSpec(args=['x', 'target', 'reduction', 'name'], varargs=None, keywords=None, defaults=('mean', None)), ('document', '18bc95c62d3300456c3c7da5278b47bb')) paddle.fluid.layers.npair_loss (ArgSpec(args=['anchor', 'positive', 'labels', 'l2_reg'], varargs=None, keywords=None, defaults=(0.002,)), ('document', '3828c4bd81c25af0ab955f52d453c587')) paddle.fluid.layers.pixel_shuffle (ArgSpec(args=['x', 'upscale_factor'], varargs=None, keywords=None, defaults=None), ('document', '7e5cac851fd9bad344230e1044b6a565')) -paddle.fluid.layers.fsp_matrix (ArgSpec(args=['x', 'y'], varargs=None, keywords=None, defaults=None), ('document', '20992b20d19c2e5983f366150827b4a6')) +paddle.fluid.layers.fsp_matrix (ArgSpec(args=['x', 'y'], varargs=None, keywords=None, defaults=None), ('document', '3a4eb7cce366f5fd8bc38b42b6af5ba1')) paddle.fluid.layers.continuous_value_model (ArgSpec(args=['input', 'cvm', 'use_cvm'], varargs=None, keywords=None, defaults=(True,)), ('document', 'c03490ffaa1b78258747157c313db4cd')) paddle.fluid.layers.where (ArgSpec(args=['condition'], varargs=None, keywords=None, defaults=None), ('document', 'b1e1487760295e1ff55307b880a99e18')) paddle.fluid.layers.sign (ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None), ('document', 'fa2f457a81714430c5677c2d68744728')) -paddle.fluid.layers.deformable_conv (ArgSpec(args=['input', 'offset', 'mask', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'deformable_groups', 'im2col_step', 'param_attr', 'bias_attr', 'modulated', 'name'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, None, None, True, None)), ('document', '335193ac57d41d7199f8d26d30c069b1')) +paddle.fluid.layers.deformable_conv (ArgSpec(args=['input', 'offset', 'mask', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'deformable_groups', 'im2col_step', 'param_attr', 'bias_attr', 'modulated', 'name'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, None, None, True, None)), ('document', '3e090f9e90b9c24d07348243bf137b56')) paddle.fluid.layers.unfold (ArgSpec(args=['x', 'kernel_sizes', 'strides', 'paddings', 'dilations', 'name'], varargs=None, keywords=None, defaults=(1, 0, 1, None)), ('document', '3f884662ad443d9ecc2b3734b4f61ad6')) paddle.fluid.layers.deformable_roi_pooling (ArgSpec(args=['input', 'rois', 'trans', 'no_trans', 'spatial_scale', 'group_size', 'pooled_height', 'pooled_width', 'part_size', 'sample_per_part', 'trans_std', 'position_sensitive', 'name'], varargs=None, keywords=None, defaults=(False, 1.0, [1, 1], 1, 1, None, 1, 0.1, False, None)), ('document', 'e0e7bf35da2287efb015546f1b8350df')) paddle.fluid.layers.filter_by_instag (ArgSpec(args=['ins', 'ins_tag', 'filter_tag', 'is_lod'], varargs=None, keywords=None, defaults=None), ('document', '7703a2088af8de4128b143ff1164ca4a')) @@ -426,7 +426,7 @@ paddle.fluid.layers.generate_proposals (ArgSpec(args=['scores', 'bbox_deltas', ' paddle.fluid.layers.generate_mask_labels (ArgSpec(args=['im_info', 'gt_classes', 'is_crowd', 'gt_segms', 'rois', 'labels_int32', 'num_classes', 'resolution'], varargs=None, keywords=None, defaults=None), ('document', 'b319b10ddaf17fb4ddf03518685a17ef')) paddle.fluid.layers.iou_similarity (ArgSpec(args=['x', 'y', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'e24478fd1fcf1727d4947fe14356b3d4')) paddle.fluid.layers.box_coder (ArgSpec(args=['prior_box', 'prior_box_var', 'target_box', 'code_type', 'box_normalized', 'name', 'axis'], varargs=None, keywords=None, defaults=('encode_center_size', True, None, 0)), ('document', '511d7033c0cfce1a5b88c04ad6e7ed5b')) -paddle.fluid.layers.polygon_box_transform (ArgSpec(args=['input', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'e308ce1661cb722b220a6f482f85b9e4')) +paddle.fluid.layers.polygon_box_transform (ArgSpec(args=['input', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '2183f03c4f16712dcef6a474dbcefa24')) paddle.fluid.layers.yolov3_loss (ArgSpec(args=['x', 'gt_box', 'gt_label', 'anchors', 'anchor_mask', 'class_num', 'ignore_thresh', 'downsample_ratio', 'gt_score', 'use_label_smooth', 'name'], varargs=None, keywords=None, defaults=(None, True, None)), ('document', 'df35e6510e8db0844320ec77dc8b7dc4')) paddle.fluid.layers.yolo_box (ArgSpec(args=['x', 'img_size', 'anchors', 'class_num', 'conf_thresh', 'downsample_ratio', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '7f255b1f6a548f8fa78bbbc06285fc46')) paddle.fluid.layers.box_clip (ArgSpec(args=['input', 'im_info', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'ce2bfbd685f2a36eda400e00569908cb')) diff --git a/python/paddle/fluid/layers/detection.py b/python/paddle/fluid/layers/detection.py index 915afc7e09..f216f5b470 100644 --- a/python/paddle/fluid/layers/detection.py +++ b/python/paddle/fluid/layers/detection.py @@ -792,17 +792,19 @@ def polygon_box_transform(input, name=None): ${comment} Args: - input(${input_type}): ${input_comment} + input(Variable): The input with shape [batch_size, geometry_channels, height, width]. + A Tensor with type float32, float64. + name(str, Optional): For details, please refer to :ref:`api_guide_Name`. + Generally, no setting is required. Default: None. Returns: - output(${output_type}): ${output_comment} + Variable: The output with the same shape as input. A Tensor with type float32, float64. Examples: .. code-block:: python import paddle.fluid as fluid - input = fluid.layers.data(name='input', shape=[4, 10, 5, 5], - append_batch_size=False, dtype='float32') + input = fluid.data(name='input', shape=[4, 10, 5, 5], dtype='float32') out = fluid.layers.polygon_box_transform(input) """ helper = LayerHelper("polygon_box_transform", **locals()) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 20f97ce5ad..8a1367ff48 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -11359,8 +11359,9 @@ def soft_relu(x, threshold=40.0, name=None): def flatten(x, axis=1, name=None): """ - **Flatten layer** - Flattens the input tensor into a 2D matrix. + **Flatten op** + + Flatten the input tensor into a 2D matrix. For Example: @@ -11389,21 +11390,20 @@ def flatten(x, axis=1, name=None): Out.shape = (1, 3 * 100 * 100 * 4) Args: - x (Variable): A tensor of rank >= axis. + x (Variable): A tensor of rank >= axis. A tensor with type float32, + float64, int8, int32, int64. axis (int): Indicate up to which input dimensions (exclusive) should be flattened to the outer dimension of the output. The value for axis must be in the range [0, R], where R - is the rank of the input tensor. When axis = 0, the shape - of the output tensor is (1, (d_0 X d_1 ... d_n), where the - shape of the input tensor is (d_0, d_1, ... d_n). - name(str|None): A name for this layer(optional). If set None, the layer - will be named automatically. + is the rank of the input tensor. Default: 1. + name(str, Optional): For details, please refer to :ref:`api_guide_Name`. + Generally, no setting is required. Default: None. Returns: Variable: A 2D tensor with the contents of the input tensor, with input \ dimensions up to axis flattened to the outer dimension of \ the output and remaining input dimensions flattened into the \ - inner dimension of the output. + inner dimension of the output. A Tensor with type same as input x. Raises: ValueError: If x is not a variable. @@ -11414,8 +11414,10 @@ def flatten(x, axis=1, name=None): .. code-block:: python import paddle.fluid as fluid - x = fluid.layers.data(name="x", shape=[4, 4, 3], dtype="float32") + x = fluid.data(name="x", shape=[4, 4, 3], dtype="float32") + # x shape is [4, 4, 3] out = fluid.layers.flatten(x=x, axis=2) + # out shape is [16, 3] """ helper = LayerHelper('flatten', **locals()) @@ -14989,7 +14991,7 @@ def fsp_matrix(x, y): **FSP matrix op** - This op is used to calculate the flow of solution procedure (FSP) matrix of two feature maps. + This op is used to calculate the flow of solution procedure (FSP) matrix of two 4-D Tensor feature maps. Given feature map x with shape [x_channel, h, w] and feature map y with shape [y_channel, h, w], we can get the fsp matrix of x and y in two steps: @@ -15001,22 +15003,25 @@ def fsp_matrix(x, y): Args: - x (Variable): A feature map with shape [batch_size, x_channel, height, width]. - y (Variable): A feature map with shape [batch_size, y_channel, height, width]. + x (Variable): A 4-D Tensor feature map with shape [batch_size, x_channel, height, width]. + A Tensor with type float32, float64. + y (Variable): A 4-D Tensor feature map with shape [batch_size, y_channel, height, width]. The y_channel can be different with the x_channel of Input(X) - while the other dimensions must be the same with Input(X)'s. + while the other dimensions must be the same with Input(X)'s. A Tensor with + type float32, float64. Returns: fsp matrix (Variable): The output of FSP op with shape [batch_size, x_channel, y_channel]. - The x_channel is the channel of x and the y_channel is the channel of y. + The x_channel is the channel of x and the y_channel is the channel of y. A Tensor with + type float32, float64. Examples: .. code-block:: python import paddle.fluid as fluid - data = fluid.layers.data(name='data', shape=[3, 32, 32]) + data = fluid.data(name='data', shape=[None, 3, 32, 32]) feature_map_0 = fluid.layers.conv2d(data, num_filters=2, filter_size=3) feature_map_1 = fluid.layers.conv2d(feature_map_0, num_filters=2, @@ -15271,7 +15276,7 @@ def deformable_conv(input, modulated=True, name=None): """ - **Deformable Convolution Layer** + **Deformable Convolution op** Compute 2-D deformable convolution on 4-D input. Given input image x, output feature map y, the deformable convolution operation can be expressed as follow: @@ -15290,7 +15295,7 @@ def deformable_conv(input, y(p) = \sum_{k=1}^{K}{w_k * x(p + p_k + \Delta p_k)} Where :math:`\Delta p_k` and :math:`\Delta m_k` are the learnable offset and modulation scalar for the k-th location, - which :math:`\Delta m_k` is one in deformable convolution v1. Please refer to `Deformable ConvNets v2: More Deformable, Better Results + Which :math:`\Delta m_k` is one in deformable convolution v1. Please refer to `Deformable ConvNets v2: More Deformable, Better Results `_ and `Deformable Convolutional Networks `_. Example: @@ -15316,12 +15321,16 @@ def deformable_conv(input, W_{out}&= \\frac{(W_{in} + 2 * paddings[1] - (dilations[1] * (W_f - 1) + 1))}{strides[1]} + 1 Args: - input (Variable): The input image with [N, C, H, W] format. + input (Variable): The input image with [N, C, H, W] format. A Tensor with type + float32, float64. offset (Variable): The input coordinate offset of deformable convolution layer. - Mask (Variable): The input mask of deformable covolution layer. + A Tensor with type float32, float64. + Mask (Variable, Optional): The input mask of deformable covolution layer. + A Tensor with type float32, float64.It should be None when you use + deformable_conv_v2. num_filters(int): The number of filter. It is as same as the output image channel. - filter_size (int|tuple|None): The filter size. If filter_size is a tuple, + filter_size (int|tuple): The filter size. If filter_size is a tuple, it must contain two integers, (filter_size_H, filter_size_W). Otherwise, the filter will be a square. stride (int|tuple): The stride size. If stride is a tuple, it must @@ -15345,24 +15354,24 @@ def deformable_conv(input, than this value; if you face out of memory problem, you can try to use a smaller value here. Default: im2col_step = 64. - param_attr (ParamAttr|None): The parameter attribute for learnable parameters/weights + param_attr (ParamAttr, Optional): The parameter attribute for learnable parameters/weights of deformable conv. If it is set to None or one attribute of ParamAttr, deformable conv will create ParamAttr as param_attr. If the Initializer of the param_attr is not set, the parameter is initialized with :math:`Normal(0.0, std)`, and the :math:`std` is :math:`(\\frac{2.0 }{filter\_elem\_num})^{0.5}`. Default: None. - bias_attr (ParamAttr|bool|None): The parameter attribute for the bias of + bias_attr (ParamAttr|bool, Optional): The parameter attribute for the bias of deformable conv layer. If it is set to False, no bias will be added to the output units. If it is set to None or one attribute of ParamAttr, conv2d will create ParamAttr as bias_attr. If the Initializer of the bias_attr is not set, the bias is initialized zero. Default: None. modulated (bool): Make sure which version should be used between v1 and v2, where v2 is \ used while True. Default: True. - name (str|None): A name for this layer(optional). If set None, the layer - will be named automatically. Default: None + name(str, Optional): For details, please refer to :ref:`api_guide_Name`. + Generally, no setting is required. Default: None. Returns: Variable: The tensor variable storing the deformable convolution \ - result. + result. A Tensor with type float32, float64. Raises: ValueError: If the shapes of input, filter_size, stride, padding and groups mismatch. @@ -15372,19 +15381,23 @@ def deformable_conv(input, #deformable conv v2: import paddle.fluid as fluid - data = fluid.layers.data(name='data', shape=[3, 32, 32], dtype='float32') - offset = fluid.layers.data(name='offset', shape=[18, 32, 32], dtype='float32') - mask = fluid.layers.data(name='mask', shape=[9, 32, 32], dtype='float32') + C_in, H_in, W_in = 3, 32, 32 + filter_size, deformable_groups = 3, 1 + data = fluid.data(name='data', shape=[None, C_in, H_in, W_in], dtype='float32') + offset = fluid.data(name='offset', shape=[None, 2*deformable_groups*filter_size**2, H_in, W_in], dtype='float32') + mask = fluid.data(name='mask', shape=[None, deformable_groups*filter_size**2, H_in, W_in], dtype='float32') out = fluid.layers.deformable_conv(input=data, offset=offset, mask=mask, - num_filters=2, filter_size=3, padding=1, modulated=True) + num_filters=2, filter_size=filter_size, padding=1, modulated=True) #deformable conv v1: import paddle.fluid as fluid - data = fluid.layers.data(name='data', shape=[3, 32, 32], dtype='float32') - offset = fluid.layers.data(name='offset', shape=[18, 32, 32], dtype='float32') + C_in, H_in, W_in = 3, 32, 32 + filter_size, deformable_groups = 3, 1 + data = fluid.data(name='data', shape=[None, C_in, H_in, W_in], dtype='float32') + offset = fluid.data(name='offset', shape=[None, 2*deformable_groups*filter_size**2, H_in, W_in], dtype='float32') out = fluid.layers.deformable_conv(input=data, offset=offset, mask=None, - num_filters=2, filter_size=3, padding=1, modulated=False) + num_filters=2, filter_size=filter_size, padding=1, modulated=False) """ num_channels = input.shape[1] -- GitLab