From 131b1dc3240e53ea295cc49323bb2a7e7dcc717f Mon Sep 17 00:00:00 2001 From: Bai Yifan Date: Tue, 8 Oct 2019 16:40:13 +0800 Subject: [PATCH] Fix api doc, test=develop, test=document_preview, test=document_fix (#19947) --- paddle/fluid/API.spec | 8 +-- python/paddle/fluid/layers/detection.py | 7 ++- python/paddle/fluid/layers/nn.py | 77 +++++++++++++++---------- 3 files changed, 54 insertions(+), 38 deletions(-) diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index 4788d9c1b2..ca50d1ac53 100644 --- 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', '631a6d5d7a58ec80575993bf7c647212')) 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', 'a41a93253c937697e900e19af172490d')) 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', 'd803767ef4fb885013a28c98634e0bc4')) 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', '9b9c9d1282f994ccd4538201e0b6856f')) 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', '47c5d1c890b36fa00ff3285c9398f613')) 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', '72fca4a39ccf82d5c746ae62d1868a99')) 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', '1d5144c3856673d05c29c752c7c8f821')) -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', '4b6e1b6b113147ea7234448a6a271e3b')) 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', '400403175718d5a632402cdae88b01b8')) 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', 'ed56ff21536ca5c8ad418d0cfaf6a7b9')) paddle.fluid.layers.box_clip (ArgSpec(args=['input', 'im_info', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '882c99ed2adad54f612a40275b881850')) diff --git a/python/paddle/fluid/layers/detection.py b/python/paddle/fluid/layers/detection.py index 1b606da006..39b27d0b2f 100644 --- a/python/paddle/fluid/layers/detection.py +++ b/python/paddle/fluid/layers/detection.py @@ -780,10 +780,13 @@ 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 diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 7b8ea4b7b0..ba19f64ff1 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -11067,8 +11067,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: @@ -11097,21 +11098,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. @@ -11122,8 +11122,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.layers.data(name="x", shape=[4, 4, 3], append_batch_size=False, 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()) @@ -14618,7 +14620,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: @@ -14630,15 +14632,18 @@ 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: @@ -14900,7 +14905,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: @@ -14919,7 +14924,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: @@ -14945,12 +14950,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 @@ -14974,24 +14983,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. @@ -15001,19 +15010,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.layers.data(name='data', shape=[C_in, H_in, W_in], dtype='float32') + offset = fluid.layers.data(name='offset', shape=[2*deformable_groups*filter_size**2, H_in, W_in], dtype='float32') + mask = fluid.layers.data(name='mask', shape=[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.layers.data(name='data', shape=[C_in, H_in, W_in], dtype='float32') + offset = fluid.layers.data(name='offset', shape=[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