From 4aeb101436eafa4faf622e4c3370cecdf2b16f30 Mon Sep 17 00:00:00 2001 From: ceci3 <592712189@qq.com> Date: Fri, 27 Sep 2019 08:41:52 +0000 Subject: [PATCH 1/7] fix conv_grad_grad --- paddle/fluid/operators/conv_cudnn_op.cu.cc | 49 +++++++++++---------- paddle/fluid/operators/conv_op.cc | 17 +++++--- paddle/fluid/operators/conv_op.h | 50 +++++++++++----------- 3 files changed, 63 insertions(+), 53 deletions(-) diff --git a/paddle/fluid/operators/conv_cudnn_op.cu.cc b/paddle/fluid/operators/conv_cudnn_op.cu.cc index 6629a203f80ede..f82d9f6d2b981c 100644 --- a/paddle/fluid/operators/conv_cudnn_op.cu.cc +++ b/paddle/fluid/operators/conv_cudnn_op.cu.cc @@ -355,15 +355,17 @@ class CUDNNConvDoubleGradOpKernel : public framework::OpKernel { size_t workspace_size = 0; if (ddO) { ddy = ddO->mutable_data(ctx.GetPlace()); - args1.handle = handle; - args1.idesc.set(*ddX, iwo_group); - args1.wdesc.set(*W, layout, iwo_group); - args1.odesc.set(*ddO, iwo_group); - args1.cdesc.set(dtype, paddings, strides, dilations, c_group); - - using search1 = SearchAlgorithm; - fwd_algo1 = search1::Find(args1, exhaustive_search, false, 0, ctx); - workspace_size = search1::GetWorkspaceSize(args1, fwd_algo1); + if (ddX) { + args1.handle = handle; + args1.idesc.set(*ddX, iwo_group); + args1.wdesc.set(*W, layout, iwo_group); + args1.odesc.set(*ddO, iwo_group); + args1.cdesc.set(dtype, paddings, strides, dilations, c_group); + + using search1 = SearchAlgorithm; + fwd_algo1 = search1::Find(args1, exhaustive_search, false, 0, ctx); + workspace_size = search1::GetWorkspaceSize(args1, fwd_algo1); + } if (ddW) { ddw = ddW->data(); @@ -380,7 +382,7 @@ class CUDNNConvDoubleGradOpKernel : public framework::OpKernel { } } - if (dW) { + if (dW && ddX) { dw = dW->mutable_data(ctx.GetPlace()); args3.handle = handle; args3.idesc.set(*ddX, iwo_group); @@ -423,17 +425,20 @@ class CUDNNConvDoubleGradOpKernel : public framework::OpKernel { auto wkspace_handle = dev_ctx.cudnn_workspace_handle(); if (ddO) { - ddx = ddX->data(); - for (int i = 0; i < groups; i++) { - wkspace_handle.RunFunc( - [&](void* workspace_ptr) { - CUDNN_ENFORCE(platform::dynload::cudnnConvolutionForward( - handle, &alpha, args1.idesc.desc(), ddx + i * group_offset_in, - args1.wdesc.desc(), w + i * group_offset_filter, - args1.cdesc.desc(), fwd_algo1, workspace_ptr, workspace_size, - &beta, args1.odesc.desc(), ddy + i * group_offset_out)); - }, - workspace_size); + if (ddX) { + ddx = ddX->data(); + for (int i = 0; i < groups; i++) { + wkspace_handle.RunFunc( + [&](void* workspace_ptr) { + CUDNN_ENFORCE(platform::dynload::cudnnConvolutionForward( + handle, &alpha, args1.idesc.desc(), + ddx + i * group_offset_in, args1.wdesc.desc(), + w + i * group_offset_filter, args1.cdesc.desc(), fwd_algo1, + workspace_ptr, workspace_size, &beta, args1.odesc.desc(), + ddy + i * group_offset_out)); + }, + workspace_size); + } } if (ddW) { for (int i = 0; i < groups; i++) { @@ -451,7 +456,7 @@ class CUDNNConvDoubleGradOpKernel : public framework::OpKernel { } } - if (dW) { + if (dW && ddX) { ddx = ddX->data(); for (int i = 0; i < groups; i++) { wkspace_handle.RunFunc( diff --git a/paddle/fluid/operators/conv_op.cc b/paddle/fluid/operators/conv_op.cc index 1cfdf7da86a5f4..5528f758732b5c 100644 --- a/paddle/fluid/operators/conv_op.cc +++ b/paddle/fluid/operators/conv_op.cc @@ -553,9 +553,10 @@ class Conv2DDoubleGradMaker : public framework::SingleGradOpDescMaker { auto ddw = OutputGrad(framework::GradVarName("Filter")); std::vector empty_str = {}; - op->SetOutput( - "DDOutput", - ddx.empty() ? empty_str : InputGrad(framework::GradVarName("Output"))); + op->SetOutput("DDOutput", + (ddx.empty() && ddw.empty()) + ? empty_str + : InputGrad(framework::GradVarName("Output"))); op->SetOutput("DFilter", ddx.empty() ? empty_str : InputGrad("Filter")); op->SetOutput("DInput", ddw.empty() ? empty_str : InputGrad("Input")); @@ -587,9 +588,10 @@ class Conv3DDoubleGradMaker : public framework::SingleGradOpDescMaker { auto ddw = OutputGrad(framework::GradVarName("Filter")); std::vector empty_str = {}; - op->SetOutput( - "DDOutput", - ddx.empty() ? empty_str : InputGrad(framework::GradVarName("Output"))); + op->SetOutput("DDOutput", + (ddx.empty() && ddw.empty()) + ? empty_str + : InputGrad(framework::GradVarName("Output"))); op->SetOutput("DFilter", ddx.empty() ? empty_str : InputGrad("Filter")); op->SetOutput("DInput", ddw.empty() ? empty_str : InputGrad("Input")); @@ -604,7 +606,8 @@ void ConvOpDoubleGrad::InferShape(framework::InferShapeContext* ctx) const { auto w_dims = ctx->GetInputDim("Filter"); auto do_dims = ctx->GetInputDim("DOutput"); - if (ctx->HasOutput("DDOutput") && ctx->HasInput("DDInput")) { + if (ctx->HasOutput("DDOutput") && + (ctx->HasInput("DDInput") || (ctx->HasInput("DDFilter")))) { ctx->SetOutputDim("DDOutput", do_dims); } if (ctx->HasOutput("DFilter") && ctx->HasInput("DDInput")) { diff --git a/paddle/fluid/operators/conv_op.h b/paddle/fluid/operators/conv_op.h index aa621529b52583..a6882897ad766b 100644 --- a/paddle/fluid/operators/conv_op.h +++ b/paddle/fluid/operators/conv_op.h @@ -506,7 +506,7 @@ class GemmConvDoubleGradKernel : public framework::OpKernel { // dw = ddx * dy ==> dw(Cout, Cin, kh, kw), ddx(N, Cin, H, W), dy(N, Cout, // oH, oW) // dw convolution double grad: im2col(vol2col) + gemm - if (dW) { + if (dW && ddX) { dW->mutable_data(ctx.GetPlace()); set_zero(dev_ctx, dW, static_cast(0)); Tensor dW_arr = *dW; @@ -549,36 +549,38 @@ class GemmConvDoubleGradKernel : public framework::OpKernel { math::Im2ColFunctor im2col; math::Vol2ColFunctor vol2col; for (int i = 0; i < batch_size; ++i) { - Tensor ddx_batch = ddX->Slice(i, i + 1).Resize(input_shape); - Tensor x_batch = X->Slice(i, i + 1).Resize(input_shape); Tensor ddy_batch = ddY->Slice(i, i + 1).Resize(output_matrix_shape); for (int g = 0; g < groups; ++g) { - Tensor x_slice = x_batch.Slice(g * in_step, (g + 1) * in_step); - Tensor ddx_slice = ddx_batch.Slice(g * in_step, (g + 1) * in_step); - if (!is_expand) { - col.ShareDataWith(ddx_slice); - col_matrix.ShareDataWith(col); - col_matrix.Resize(col_matrix_shape); - } else if (data_dim == 2U) { - // im2col - im2col(dev_ctx, ddx_slice, dilations, strides, - std::vector{paddings[0], paddings[1], paddings[0], - paddings[1]}, - &col); - } else if (data_dim == 3U) { - // vol2col - vol2col(dev_ctx, ddx_slice, dilations, strides, paddings, &col); - } - - // gemm Tensor ddy_slice = ddy_batch.Slice(g * out_step, (g + 1) * out_step); - Tensor w_slice = W.Slice(g * out_step, (g + 1) * out_step); - blas.MatMul(w_slice, false, col_matrix, false, T(1.0), &ddy_slice, - T(0.0)); + if (ddX) { + Tensor ddx_batch = ddX->Slice(i, i + 1).Resize(input_shape); + Tensor ddx_slice = ddx_batch.Slice(g * in_step, (g + 1) * in_step); + if (!is_expand) { + col.ShareDataWith(ddx_slice); + col_matrix.ShareDataWith(col); + col_matrix.Resize(col_matrix_shape); + } else if (data_dim == 2U) { + // im2col + im2col(dev_ctx, ddx_slice, dilations, strides, + std::vector{paddings[0], paddings[1], paddings[0], + paddings[1]}, + &col); + } else if (data_dim == 3U) { + // vol2col + vol2col(dev_ctx, ddx_slice, dilations, strides, paddings, &col); + } + + // gemm + Tensor w_slice = W.Slice(g * out_step, (g + 1) * out_step); + blas.MatMul(w_slice, false, col_matrix, false, T(1.0), &ddy_slice, + T(0.0)); + } if (ddW_in) { Tensor ddW; ddW.ShareDataWith(*ddW_in).Resize(filter_matrix_shape); + Tensor x_batch = X->Slice(i, i + 1).Resize(input_shape); + Tensor x_slice = x_batch.Slice(g * in_step, (g + 1) * in_step); if (!is_expand) { col.ShareDataWith(x_slice); From 3fd05bba64d0b1363b6dae1ff059ecc959129d2e Mon Sep 17 00:00:00 2001 From: ceci3 <592712189@qq.com> Date: Sun, 29 Sep 2019 07:03:34 +0000 Subject: [PATCH 2/7] refine en doc, test=develop, test=document_fix --- paddle/fluid/API.spec | 20 ++-- paddle/fluid/operators/cos_sim_op.cc | 8 +- python/paddle/fluid/layers/nn.py | 158 ++++++++++++++------------- python/paddle/fluid/nets.py | 6 +- 4 files changed, 100 insertions(+), 92 deletions(-) diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index e90eb305f8f62a..4a4f7d0a653a5b 100644 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -123,14 +123,14 @@ paddle.fluid.layers.dynamic_gru (ArgSpec(args=['input', 'size', 'param_attr', 'b paddle.fluid.layers.gru_unit (ArgSpec(args=['input', 'hidden', 'size', 'param_attr', 'bias_attr', 'activation', 'gate_activation', 'origin_mode'], varargs=None, keywords=None, defaults=(None, None, 'tanh', 'sigmoid', False)), ('document', '33974b9bfa69f2f1eb85e6f956dff04e')) paddle.fluid.layers.linear_chain_crf (ArgSpec(args=['input', 'label', 'param_attr', 'length'], varargs=None, keywords=None, defaults=(None, None)), ('document', '9045b8971e4232132ec9952695f4c3ae')) paddle.fluid.layers.crf_decoding (ArgSpec(args=['input', 'param_attr', 'label'], varargs=None, keywords=None, defaults=(None,)), ('document', '5ce117258e243be1c81539e254178d90')) -paddle.fluid.layers.cos_sim (ArgSpec(args=['X', 'Y'], varargs=None, keywords=None, defaults=None), ('document', '8e6ce424cf9e261ef32ee229c06a6e66')) +paddle.fluid.layers.cos_sim (ArgSpec(args=['X', 'Y'], varargs=None, keywords=None, defaults=None), ('document', '01fe5c35363aab3d8e2d9caee2cef911')) paddle.fluid.layers.cross_entropy (ArgSpec(args=['input', 'label', 'soft_label', 'ignore_index'], varargs=None, keywords=None, defaults=(False, -100)), ('document', 'f43c659ca1749a3f0ff2231e6dfda07d')) paddle.fluid.layers.bpr_loss (ArgSpec(args=['input', 'label', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '6263dfdeb6c670fa0922c9cbc8fb1bf4')) paddle.fluid.layers.square_error_cost (ArgSpec(args=['input', 'label'], varargs=None, keywords=None, defaults=None), ('document', 'bbb9e708bab250359864fefbdf48e9d9')) paddle.fluid.layers.chunk_eval (ArgSpec(args=['input', 'label', 'chunk_scheme', 'num_chunk_types', 'excluded_chunk_types', 'seq_length'], varargs=None, keywords=None, defaults=(None, None)), ('document', 'b02844e0ad4bd713c5fe6802aa13219c')) paddle.fluid.layers.sequence_conv (ArgSpec(args=['input', 'num_filters', 'filter_size', 'filter_stride', 'padding', 'padding_start', 'bias_attr', 'param_attr', 'act', 'name'], varargs=None, keywords=None, defaults=(3, 1, True, None, None, None, None, None)), ('document', '2bf23e7884c380c3b27f2709aa322cb9')) -paddle.fluid.layers.conv2d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None)), ('document', '06de9adb5994f6f8cb806c75b55550af')) -paddle.fluid.layers.conv3d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None)), ('document', '71b09227709475fa178c1739dff64af6')) +paddle.fluid.layers.conv2d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None)), ('document', 'd380c2c7f89884681f58f554ed485609')) +paddle.fluid.layers.conv3d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None)), ('document', '3e4223461ea20534b4e605dd912d4597')) paddle.fluid.layers.sequence_pool (ArgSpec(args=['input', 'pool_type', 'is_test', 'pad_value'], varargs=None, keywords=None, defaults=(False, 0.0)), ('document', 'e90a93251c52dc4e6fb34fb3991b3f82')) paddle.fluid.layers.sequence_softmax (ArgSpec(args=['input', 'use_cudnn', 'name'], varargs=None, keywords=None, defaults=(False, None)), ('document', 'eaa9d0bbd3d4e017c8bc4ecdac483711')) paddle.fluid.layers.softmax (ArgSpec(args=['input', 'use_cudnn', 'name', 'axis'], varargs=None, keywords=None, defaults=(False, None, -1)), ('document', 'cee673c79e3ff4582656a24e04f841e5')) @@ -138,12 +138,12 @@ paddle.fluid.layers.pool2d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'po paddle.fluid.layers.pool3d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'pool_stride', 'pool_padding', 'global_pooling', 'use_cudnn', 'ceil_mode', 'name', 'exclusive'], varargs=None, keywords=None, defaults=(-1, 'max', 1, 0, False, True, False, None, True)), ('document', '053b1a855f13a066d005759171724bc6')) paddle.fluid.layers.adaptive_pool2d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'require_index', 'name'], varargs=None, keywords=None, defaults=('max', False, None)), ('document', '52343203de40afe29607397e13aaf0d2')) paddle.fluid.layers.adaptive_pool3d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'require_index', 'name'], varargs=None, keywords=None, defaults=('max', False, None)), ('document', '55db6ae7275fb9678a6814aebab81a9c')) -paddle.fluid.layers.batch_norm (ArgSpec(args=['input', 'act', 'is_test', 'momentum', 'epsilon', 'param_attr', 'bias_attr', 'data_layout', 'in_place', 'name', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var', 'fuse_with_relu', 'use_global_stats'], varargs=None, keywords=None, defaults=(None, False, 0.9, 1e-05, None, None, 'NCHW', False, None, None, None, False, False, False)), ('document', '9e5a9f4f6d82d34a33d9ca632379cbcc')) -paddle.fluid.layers.instance_norm (ArgSpec(args=['input', 'epsilon', 'param_attr', 'bias_attr', 'name'], varargs=None, keywords=None, defaults=(1e-05, None, None, None)), ('document', '02972097e089629efdb0ed9404fd36ae')) +paddle.fluid.layers.batch_norm (ArgSpec(args=['input', 'act', 'is_test', 'momentum', 'epsilon', 'param_attr', 'bias_attr', 'data_layout', 'in_place', 'name', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var', 'fuse_with_relu', 'use_global_stats'], varargs=None, keywords=None, defaults=(None, False, 0.9, 1e-05, None, None, 'NCHW', False, None, None, None, False, False, False)), ('document', 'ba4db9b833ea6e1c7011acf9cd036362')) +paddle.fluid.layers.instance_norm (ArgSpec(args=['input', 'epsilon', 'param_attr', 'bias_attr', 'name'], varargs=None, keywords=None, defaults=(1e-05, None, None, None)), ('document', '6dc0bc0ea1a744f2b2aeef94b809c37e')) paddle.fluid.layers.data_norm (ArgSpec(args=['input', 'act', 'epsilon', 'param_attr', 'data_layout', 'in_place', 'name', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var'], varargs=None, keywords=None, defaults=(None, 1e-05, None, 'NCHW', False, None, None, None, False)), ('document', '2460b30fb87037555208fa8ac6fc1787')) paddle.fluid.layers.beam_search_decode (ArgSpec(args=['ids', 'scores', 'beam_size', 'end_id', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '83e08f21af41ac8bac37aeab1f86fdd0')) -paddle.fluid.layers.conv2d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None)), ('document', 'ab58296b567bf0c686084add7f3280a4')) -paddle.fluid.layers.conv3d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None)), ('document', 'fe15dbfb17d97d3d29b2fa7ee6390ee6')) +paddle.fluid.layers.conv2d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None)), ('document', 'cd81fffa4c1c51bdd5c9e04964dcd8c4')) +paddle.fluid.layers.conv3d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None)), ('document', '5ab6f248eab45b4431ebb5356867bec0')) paddle.fluid.layers.sequence_expand (ArgSpec(args=['x', 'y', 'ref_level', 'name'], varargs=None, keywords=None, defaults=(-1, None)), ('document', '10e122eb755c2bd1f78ef2332b28f1a0')) paddle.fluid.layers.sequence_expand_as (ArgSpec(args=['x', 'y', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '858c432e7cbd8bb952cc2eb555457d50')) paddle.fluid.layers.sequence_pad (ArgSpec(args=['x', 'pad_value', 'maxlen', 'name'], varargs=None, keywords=None, defaults=(None, None)), ('document', 'df08b9c499ab3a90f95d08ab5b6c6c62')) @@ -159,7 +159,7 @@ paddle.fluid.layers.reduce_any (ArgSpec(args=['input', 'dim', 'keep_dim', 'name' paddle.fluid.layers.sequence_first_step (ArgSpec(args=['input'], varargs=None, keywords=None, defaults=None), ('document', 'f2dfd65b859de9844e7261e7a4503f63')) paddle.fluid.layers.sequence_last_step (ArgSpec(args=['input'], varargs=None, keywords=None, defaults=None), ('document', '1af2e3a887e4f914f9d6650406186ab6')) paddle.fluid.layers.sequence_slice (ArgSpec(args=['input', 'offset', 'length', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '39fbc5437be389f6c0c769f82fc1fba2')) -paddle.fluid.layers.dropout (ArgSpec(args=['x', 'dropout_prob', 'is_test', 'seed', 'name', 'dropout_implementation'], varargs=None, keywords=None, defaults=(False, None, None, 'downgrade_in_infer')), ('document', '558d13133596209190df9a624264f28f')) +paddle.fluid.layers.dropout (ArgSpec(args=['x', 'dropout_prob', 'is_test', 'seed', 'name', 'dropout_implementation'], varargs=None, keywords=None, defaults=(False, None, None, 'downgrade_in_infer')), ('document', 'd69730425965bf4ff9de8cd9e63b37a9')) paddle.fluid.layers.split (ArgSpec(args=['input', 'num_or_sections', 'dim', 'name'], varargs=None, keywords=None, defaults=(-1, None)), ('document', '78cf3a7323d1a7697658242e13f63759')) paddle.fluid.layers.ctc_greedy_decoder (ArgSpec(args=['input', 'blank', 'input_length', 'padding_value', 'name'], varargs=None, keywords=None, defaults=(None, 0, None)), ('document', '9abb7bb8d267e017620a39a146dc47ea')) paddle.fluid.layers.edit_distance (ArgSpec(args=['input', 'label', 'normalized', 'ignored_tokens', 'input_length', 'label_length'], varargs=None, keywords=None, defaults=(True, None, None, None)), ('document', '77cbfb28cd2fc589f589c7013c5086cd')) @@ -286,7 +286,7 @@ paddle.fluid.layers.prroi_pool (ArgSpec(args=['input', 'rois', 'output_channels' paddle.fluid.layers.teacher_student_sigmoid_loss (ArgSpec(args=['input', 'label', 'soft_max_up_bound', 'soft_max_lower_bound'], varargs=None, keywords=None, defaults=(15.0, -15.0)), ('document', '07cb0d95a646dba1b9cc7cdce89e59f0')) paddle.fluid.layers.huber_loss (ArgSpec(args=['input', 'label', 'delta'], varargs=None, keywords=None, defaults=None), ('document', '11bb8e62cc9256958eff3991fe4834da')) 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', '6b6ee1170fe20a79cf0631a1f49b0df2')) +paddle.fluid.layers.npair_loss (ArgSpec(args=['anchor', 'positive', 'labels', 'l2_reg'], varargs=None, keywords=None, defaults=(0.002,)), ('document', '713d93dc898862daed6de36438999a10')) 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.continuous_value_model (ArgSpec(args=['input', 'cvm', 'use_cvm'], varargs=None, keywords=None, defaults=(True,)), ('document', 'c03490ffaa1b78258747157c313db4cd')) @@ -896,7 +896,7 @@ paddle.fluid.nets.simple_img_conv_pool (ArgSpec(args=['input', 'num_filters', 'f paddle.fluid.nets.sequence_conv_pool (ArgSpec(args=['input', 'num_filters', 'filter_size', 'param_attr', 'act', 'pool_type', 'bias_attr'], varargs=None, keywords=None, defaults=(None, 'sigmoid', 'max', None)), ('document', 'd6a1e527b53f5cc15594fee307dfc5cf')) paddle.fluid.nets.glu (ArgSpec(args=['input', 'dim'], varargs=None, keywords=None, defaults=(-1,)), ('document', 'b87bacfc70dd3477ed25ef14aa01389a')) paddle.fluid.nets.scaled_dot_product_attention (ArgSpec(args=['queries', 'keys', 'values', 'num_heads', 'dropout_rate'], varargs=None, keywords=None, defaults=(1, 0.0)), ('document', 'b1a07a0000eb9103e3a143ca8c13de5b')) -paddle.fluid.nets.img_conv_group (ArgSpec(args=['input', 'conv_num_filter', 'pool_size', 'conv_padding', 'conv_filter_size', 'conv_act', 'param_attr', 'conv_with_batchnorm', 'conv_batchnorm_drop_rate', 'pool_stride', 'pool_type', 'use_cudnn'], varargs=None, keywords=None, defaults=(1, 3, None, None, False, 0.0, 1, 'max', True)), ('document', '4913d846264f17112bf7bc04273388cc')) +paddle.fluid.nets.img_conv_group (ArgSpec(args=['input', 'conv_num_filter', 'pool_size', 'conv_padding', 'conv_filter_size', 'conv_act', 'param_attr', 'conv_with_batchnorm', 'conv_batchnorm_drop_rate', 'pool_stride', 'pool_type', 'use_cudnn'], varargs=None, keywords=None, defaults=(1, 3, None, None, False, 0.0, 1, 'max', True)), ('document', '97a3185b1edc97cb7eab25e0a6ddc407')) paddle.fluid.optimizer.SGDOptimizer ('paddle.fluid.optimizer.SGDOptimizer', ('document', 'c3c8dd3193d991adf8bda505560371d6')) paddle.fluid.optimizer.SGDOptimizer.__init__ (ArgSpec(args=['self', 'learning_rate', 'regularization', 'name'], varargs=None, keywords=None, defaults=(None, None)), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) paddle.fluid.optimizer.SGDOptimizer.apply_gradients (ArgSpec(args=['self', 'params_grads'], varargs=None, keywords=None, defaults=None), ('document', '80ea99c9af7ef5fac7e57fb302103610')) diff --git a/paddle/fluid/operators/cos_sim_op.cc b/paddle/fluid/operators/cos_sim_op.cc index 93304ec6700b79..289bb5d2dddef7 100644 --- a/paddle/fluid/operators/cos_sim_op.cc +++ b/paddle/fluid/operators/cos_sim_op.cc @@ -73,8 +73,12 @@ class CosSimOp : public framework::OperatorWithKernel { class CosSimOpMaker : public framework::OpProtoAndCheckerMaker { public: void Make() override { - AddInput("X", "The 1st input of cos_sim op."); - AddInput("Y", "The 2nd input of cos_sim op."); + AddInput("X", + "The 1st input of cos_sim op, LoDTensor with shape ``[N_1, N_2, " + "..., N_k]``, the data type is float32."); + AddInput("Y", + "The 2nd input of cos_sim op, Tensor with shape ``[N_1 or 1, N_2, " + "..., N_k]``, the data type is float32."); AddOutput("Out", "The output of cos_sim op."); AddOutput("XNorm", "Norm of the first input, reduced along the 1st " diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 8f6c8a5d127947..736d7a1efeebe3 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -1574,7 +1574,7 @@ def cos_sim(X, Y): Y (Variable): ${y_comment}. Returns: - Variable: the output of cosine(X, Y). + Variable: LoDTensor, the output of cosine(X, Y). Examples: .. code-block:: python @@ -1616,13 +1616,13 @@ def dropout(x, dropout op can be removed from the program to make the program more efficient. Args: - x (Variable): The input tensor variable. - dropout_prob (float): Probability of setting units to zero. + x (Variable): The input tensor variable. The data type is float16 or float32 or float64. + dropout_prob (float): Probability of setting units to zero. Default: 0.5. is_test (bool): A flag indicating whether it is in test phrase or not. seed (int): A Python integer used to create random seeds. If this parameter is set to None, a random seed is used. NOTE: If an integer seed is given, always the same output - units will be dropped. DO NOT use a fixed seed in training. + units will be dropped. DO NOT use a fixed seed in training.Default: None. name (str|None): A name for this layer(optional). If set None, the layer will be named automatically. dropout_implementation(string): ['downgrade_in_infer'(default)|'upscale_in_train'] @@ -2336,20 +2336,21 @@ def conv2d(input, padding mode is 'SAME' and 'VALID' can reference this link`_ Args: - input (Variable): The input image with [N, C, H, W] format. + input (Variable): The input is 4-D Tensor with shape [N, C, H, W], the data type of input is float16 or float32 or float64. num_filters(int): The number of filter. It is as same as the output image channel. filter_size (int|tuple): The filter size. If filter_size is a tuple, it must contain two integers, (filter_size_height, filter_size_width). Otherwise, filter_size_height = filter_\ size_width = filter_size. - stride (int|tuple): The stride size. If stride is a tuple, it must - contain two integers, (stride_height, stride_width). Otherwise, - stride_height = stride_width = stride. Default: stride = 1. - padding (int|tuple): The padding size. If padding is a tuple, it must + stride (int|tuple): The stride size. It means the stride in convolution. + If stride is a tuple, it must contain two integers, (stride_height, stride_width). + Otherwise, stride_height = stride_width = stride. Default: stride = 1. + padding (int|tuple): The padding size. It means the number of zero-paddings + on both sides for each dimention. If padding is a tuple, it must contain two integers, (padding_height, padding_width). Otherwise, padding_height = padding_width = padding. Default: padding = 0. - dilation (int|tuple): The dilation size. If dilation is a tuple, it must + dilation (int|tuple): The dilation size. It means the spacing between the kernel points. This `link`_ has a nice visualization of what dilation does. If dilation is a tuple, it must contain two integers, (dilation_height, dilation_width). Otherwise, dilation_height = dilation_width = dilation. Default: dilation = 1. groups (int): The groups number of the Conv2d Layer. According to grouped @@ -2371,16 +2372,12 @@ def conv2d(input, library is installed. Default: True act (str): Activation type, if it is set to None, activation is not appended. Default: None - name (str|None): A name for this layer(optional). If set None, the layer - will be named automatically. Default: None + name(str|None): For detailed information, please refer + to :ref:`api_guide_Name`. Usually name is no need to set and + None by default. Returns: - Variable: The tensor variable storing the convolution and \ - non-linearity activation result. - - Raises: - ValueError: If the shapes of input, filter_size, stride, padding and - groups mismatch. + Variable: The output tensor and input tensor have same shape. If act is None, The tensor variable storing the convolution result, and if act is not None, the tensor variable storing convolution and non-linearity activation result. Examples: .. code-block:: python @@ -2512,20 +2509,21 @@ def conv3d(input, W_{out}&= \\frac{(W_{in} + 2 * paddings[2] - (dilations[2] * (W_f - 1) + 1))}{strides[2]} + 1 Args: - input (Variable): The input image with [N, C, D, H, W] format. + input (Variable): The input is 5-D Tensor with shape [N, C, D, H, W], the data type of input is float16 or float32 or float64. num_filters(int): The number of filter. It is as same as the output image channel. filter_size (int|tuple): The filter size. If filter_size is a tuple, it must contain three integers, (filter_size_depth, filter_size_height, filter_size_width). Otherwise, filter_size_depth = filter_size_height = \ filter_size_width = filter_size. - stride (int|tuple): The stride size. If stride is a tuple, it must - contain three integers, (stride_depth, stride_height, stride_width). Otherwise, - stride_depth = stride_height = stride_width = stride. Default: stride = 1. - padding (int|tuple): The padding size. If padding is a tuple, it must - contain three integers, (padding_depth, padding_height, padding_width). Otherwise, - padding_depth = padding_height = padding_width = padding. Default: padding = 0. - dilation (int|tuple): The dilation size. If dilation is a tuple, it must + stride (int|tuple): The stride size. It means the stride in convolution. If stride is a + tuple, it must contain three integers, (stride_depth, stride_height, stride_width). + Otherwise, stride_depth = stride_height = stride_width = stride. Default: stride = 1. + padding (int|tuple): The padding size. It means the number of zero-paddings on both sides + for each dimention. If padding is a tuple, it must contain three integers, (padding_depth, + padding_height, padding_width). Otherwise, padding_depth = padding_height = padding_width = \ + padding. Default: padding = 0. + dilation (int|tuple): The dilation size. It means the spacing between the kernel points. This `link`_ has a nice visualization of what dilation does. If dilation is a tuple, it must contain three integers, (dilation_depth, dilation_height, dilation_width). Otherwise, dilation_depth = dilation_height = dilation_width = dilation. Default: dilation = 1. groups (int): The groups number of the Conv3d Layer. According to grouped @@ -2547,16 +2545,12 @@ def conv3d(input, library is installed. Default: True act (str): Activation type, if it is set to None, activation is not appended. Default: None. - name (str|None): A name for this layer(optional). If set None, the layer - will be named automatically. Default: None. + name(str|None): For detailed information, please refer + to :ref:`api_guide_Name`. Usually name is no need to set and + None by default. Returns: - Variable: The tensor variable storing the convolution and \ - non-linearity activation result. - - Raises: - ValueError: If the shapes of input, filter_size, stride, padding and - groups mismatch. + Variable: The output tensor and input tensor have same shape. If act is None, The tensor variable storing the convolution result, and if act is not None, the tensor variable storing convolution and non-linearity activation result. Examples: .. code-block:: python @@ -3332,7 +3326,7 @@ def batch_norm(input, """ **Batch Normalization Layer** - Can be used as a normalizer function for conv2d and fully_connected operations. + Can be used as a normalizer function for convolution and fully_connected operations. The required data format for this layer is one of the following: 1. NHWC `[batch, in_height, in_width, in_channels]` @@ -3377,7 +3371,7 @@ def batch_norm(input, sync_batch_norm automatically. Args: - input(variable): The rank of input variable can be 2, 3, 4, 5. + input(variable): The rank of input variable can be 2, 3, 4, 5. The data type is float16 or float32 or float64. act(string, Default None): Activation type, linear|relu|prelu|... is_test (bool, Default False): A flag indicating whether it is in test phrase or not. @@ -3398,14 +3392,13 @@ def batch_norm(input, will create ParamAttr as bias_attr, the name of bias can be set in ParamAttr. If the Initializer of the bias_attr is not set, the bias is initialized zero. Default: None. - data_layout(string, default NCHW): NCHW|NHWC + data_layout(str, default NCHW): the data_layout of input, is NCHW or NHWC. in_place(bool, Default False): Make the input and output of batch norm reuse memory. - name(string, Default None): A name for this layer(optional). If set None, the layer - will be named automatically. - moving_mean_name(string, Default None): The name of moving_mean which store the global Mean. If it + name(str|None): For detailed information, please refer to :ref:`api_guide_Name`. Usually name is no need to set and None by default. + moving_mean_name(str, Default None): The name of moving_mean which store the global Mean. If it is set to None, batch_norm will save global mean with a random name, otherwise, batch_norm will save global mean with the string. - moving_variance_name(string, Default None): The name of the moving_variance which store the global Variance. + moving_variance_name(str, Default None): The name of the moving_variance which store the global Variance. If it is set to None, batch_norm will save global variance with a random name, otherwise, batch_norm will save global variance with the string. do_model_average_for_mean_and_var(bool, Default False): Do model average for mean and variance or not. @@ -3417,7 +3410,7 @@ def batch_norm(input, and variance are also used during train period. Returns: - Variable: A tensor variable which is the result after applying batch normalization on the input. + Variable: A tensor variable which is the result after applying batch normalization on the input. The shape of output equal to the shape of input. Examples: @@ -3552,7 +3545,7 @@ def instance_norm(input, y_i &\\gets \\gamma \\hat{x_i} + \\beta Args: - input(variable): The rank of input variable can be 2, 3, 4, 5. + input(variable): The rank of input variable can be 2, 3, 4, 5. The data type is float32 or float64. epsilon(float, Default 1e-05): A value added to the denominator for numerical stability. Default is 1e-5. param_attr(ParamAttr|None): The parameter attribute for Parameter `scale` @@ -4113,32 +4106,32 @@ def conv2d_transpose(input, W_{out} &\in [ W^\prime_{out}, W^\prime_{out} + strides[1] ] Note: - if output_size is None, :math:`H_{out} = H^\prime_{out}, W_{out} = W^\prime_{out}`; + The conv2d_transpose can be seen as the backward of the conv2d. For conv2d, when stride > 1, conv2d maps multiple input shape to the same output shape, so for conv2d_transpose, when stride > 1, input shape maps multiple output shape. + If output_size is None, :math:`H_{out} = H^\prime_{out}, W_{out} = W^\prime_{out}`; else, the :math:`H_{out}` of the output size must between :math:`H^\prime_{out}` and :math:`H^\prime_{out} + strides[0]`, and the :math:`W_{out}` of the output size must between :math:`W^\prime_{out}` and :math:`W^\prime_{out} + strides[1]`, conv2d_transpose can compute the kernel size automatically. Args: - input(Variable): The input image with [N, C, H, W] format. + input(Variable): The input is 4-D Tensor with shape [N, C, H, W], the data type of input is float32 or float64. num_filters(int): The number of the filter. It is as same as the output image channel. output_size(int|tuple|None): The output image size. If output size is a tuple, it must contain two integers, (image_height, image_width). None if use filter_size, padding, and stride to calculate output_size. - if output_size and filter_size are specified at the same time, They - should follow the formula above. + If output_size and filter_size are specified at the same time, They + should follow the formula above. Default: None. output_size and filter_size should not be None at the same time. filter_size(int|tuple|None): The filter size. If filter_size is a tuple, it must contain two integers, (filter_size_height, filter_size_width). Otherwise, filter_size_height = filter_size_width = filter_size. None if - use output size to calculate filter_size. - padding(int|tuple): The padding size. If padding is a tuple, it must - contain two integers, (padding_height, padding_width). Otherwise, + use output size to calculate filter_size. Default: None. filter_size and output_size should not be None at the same time. + padding(int|tuple): The padding size. The padding argument effectively adds `dilation * (kernel - 1)` amount of zero-padding on both sidee of input. If padding is a tuple, it must contain two integers, (padding_height, padding_width). Otherwise, padding_height = padding_width = padding. Default: padding = 0. - stride(int|tuple): The stride size. If stride is a tuple, it must + stride(int|tuple): The stride size. It means the stride in transposed convolution. If stride is a tuple, it must contain two integers, (stride_height, stride_width). Otherwise, stride_height = stride_width = stride. Default: stride = 1. - dilation(int|tuple): The dilation size. If dilation is a tuple, it must + dilation(int|tuple): The dilation size. It means the spacing between the kernel points. This `link`_ has a nice visualization of what dilation does. If dilation is a tuple, it must contain two integers, (dilation_height, dilation_width). Otherwise, dilation_height = dilation_width = dilation. Default: dilation = 1. groups(int): The groups number of the Conv2d transpose layer. Inspired by @@ -4160,14 +4153,15 @@ def conv2d_transpose(input, library is installed. Default: True. act (str): Activation type, if it is set to None, activation is not appended. Default: None. - name(str|None): A name for this layer(optional). If set None, the layer - will be named automatically. Default: True. + name(str|None): For detailed information, please refer + to :ref:`api_guide_Name`. Usually name is no need to set and + None by default. Returns: - Variable: The tensor variable storing the convolution transpose result. + Variable: The output tensor and input tensor have same shape. If act is None, The tensor variable storing the transposed convolution result, and if act is not None, the tensor variable storing transposed convolution and non-linearity activation result. Raises: - ValueError: If the shapes of input, filter_size, stride, padding and + ValueError: If the shapes of output, input, filter_size, stride, padding and groups mismatch. Examples: @@ -4306,29 +4300,38 @@ def conv3d_transpose(input, .. math:: - D_{out} &= (D_{in} - 1) * strides[0] - 2 * paddings[0] + dilations[0] * (D_f - 1) + 1 \\\\ - H_{out} &= (H_{in} - 1) * strides[1] - 2 * paddings[1] + dilations[1] * (H_f - 1) + 1 \\\\ - W_{out} &= (W_{in} - 1) * strides[2] - 2 * paddings[2] + dilations[2] * (W_f - 1) + 1 + D^\prime_{out} &= (D_{in} - 1) * strides[0] - 2 * paddings[0] + dilations[0] * (D_f - 1) + 1 \\\\ + H^\prime_{out} &= (H_{in} - 1) * strides[1] - 2 * paddings[1] + dilations[1] * (H_f - 1) + 1 \\\\ + W^\prime_{out} &= (W_{in} - 1) * strides[2] - 2 * paddings[2] + dilations[2] * (W_f - 1) + 1 \\\\ + D_{out} &\in [ D^\prime_{out}, D^\prime_{out} + strides[0] ] \\\\ + H_{out} &\in [ H^\prime_{out}, H^\prime_{out} + strides[1] ] \\\\ + W_{out} &\in [ W^\prime_{out}, W^\prime_{out} + strides[2] ] + + Note: + The conv3d_transpose can be seen as the backward of the conv3d. For conv3d, when stride > 1, conv3d maps multiple input shape to the same output shape, so for conv3d_transpose, when stride > 1, input shape maps multiple output shape. + If output_size is None, :math:`H_{out} = H^\prime_{out}, :math:`H_{out} = H^\prime_{out}, W_{out} = W^\prime_{out}`; + else, the :math:`D_{out}` of the output size must between :math:`D^\prime_{out}` and :math:`D^\prime_{out} + strides[0]`, the :math:`H_{out}` of the output size must between :math:`H^\prime_{out}` + and :math:`H^\prime_{out} + strides[1]`, and the :math:`W_{out}` of the output size must + between :math:`W^\prime_{out}` and :math:`W^\prime_{out} + strides[2]`, + conv3d_transpose can compute the kernel size automatically. Args: - input(Variable): The input image with [N, C, D, H, W] format. + input(Variable): The input is 5-D Tensor with shape [N, C, D, H, W], the data type of input is float32 or float64. num_filters(int): The number of the filter. It is as same as the output image channel. output_size(int|tuple|None): The output image size. If output size is a - tuple, it must contain three integers, (image_D, image_H, image_W). This - parameter only works when filter_size is None. + tuple, it must contain three integers, (image_depth, image_height, image_width). This + parameter only works when filter_size is None. If output_size and filter_size are specified at the same time, They should follow the formula above. Default: None. output_size and filter_size should not be None at the same time. filter_size(int|tuple|None): The filter size. If filter_size is a tuple, it must contain three integers, (filter_size_depth, filter_size_height, \ filter_size_width). Otherwise, filter_size_depth = filter_size_height = \ filter_size_width = filter_size. None if use output size to - calculate filter_size. - padding(int|tuple): The padding size. If padding is a tuple, it must - contain three integers, (padding_depth, padding_height, padding_width). Otherwise, - padding_depth = padding_height = padding_width = padding. Default: padding = 0. - stride(int|tuple): The stride size. If stride is a tuple, it must + calculate filter_size. Default: None. filter_size and output_size should not be None at the same time. + padding(int|tuple): The padding size. The padding argument effectively adds `dilation * (kernel - 1)` amount of zero-padding on both sidee of input. If padding is a tuple, it must contain three integers, (padding_depth, padding_height, padding_width). Otherwise, padding_depth = padding_height = padding_width = padding. Default: padding = 0. + stride(int|tuple): The stride size. It means the stride in transposed convolution. If stride is a tuple, it must contain three integers, (stride_depth, stride_height, stride_width). Otherwise, stride_depth = stride_height = stride_width = stride. Default: stride = 1. - dilation(int|tuple): The dilation size. If dilation is a tuple, it must + dilation(int|tuple): The dilation size. It means the spacing between the kernel points. This `link`_ has a nice visualization of what dilation does. If dilation is a tuple, it must contain three integers, (dilation_depth, dilation_height, dilation_width). Otherwise, dilation_depth = dilation_height = dilation_width = dilation. Default: dilation = 1. groups(int): The groups number of the Conv3d transpose layer. Inspired by @@ -4350,14 +4353,15 @@ def conv3d_transpose(input, library is installed. Default: True act (str): Activation type, if it is set to None, activation is not appended. Default: None. - name(str|None): A name for this layer(optional). If set None, the layer - will be named automatically. + name(str|None): For detailed information, please refer + to :ref:`api_guide_Name`. Usually name is no need to set and + None by default. Returns: - Variable: The tensor variable storing the convolution transpose result. + Variable: The output tensor and input tensor have same shape. If act is None, The tensor variable storing the transposed convolution result, and if act is not None, the tensor variable storing transposed convolution and non-linearity activation result. Raises: - ValueError: If the shapes of input, filter_size, stride, padding and + ValueError: If the shapes of output, input, filter_size, stride, padding and groups mismatch. Examples: @@ -13921,13 +13925,13 @@ def npair_loss(anchor, positive, labels, l2_reg=0.002): takes the similarity matrix of anchor and positive as logits. Args: - anchor(Variable): embedding vector for the anchor image. shape=[batch_size, embedding_dims] - positive(Variable): embedding vector for the positive image. shape=[batch_size, embedding_dims] - labels(Variable): 1-D tensor. shape=[batch_size] - l2_reg(float32): L2 regularization term on embedding vector, default: 0.002 + anchor(Variable): embedding vector for the anchor image. shape=[batch_size, embedding_dims], the data type is float32 or float32. + positive(Variable): embedding vector for the positive image. shape=[batch_size, embedding_dims], the data type is float32 or float32. + labels(Variable): 1-D tensor. shape=[batch_size], the data type is float32 or float32 or int64. + l2_reg(float32): L2 regularization term on embedding vector, default: 0.002. Returns: - npair loss(Variable): return npair loss, shape=[1] + Variable: Tensor, return npair loss, shape=[1] Examples: .. code-block:: python diff --git a/python/paddle/fluid/nets.py b/python/paddle/fluid/nets.py index e340f03161ef6d..49837721ead66f 100644 --- a/python/paddle/fluid/nets.py +++ b/python/paddle/fluid/nets.py @@ -152,11 +152,11 @@ def img_conv_group(input, result to Pool2d. Args: - input (Variable): The input image with [N, C, H, W] format. + input (Variable): The input is 4-D Tensor with shape [N, C, H, W], the data type of input is float32 or float64. conv_num_filter(list|tuple): Indicates the numbers of filter of this group. pool_size (int|list|tuple): The pooling size of Pool2d Layer. If pool_size - is a list or tuple, it must contain two integers, (pool_size_H, pool_size_W). - Otherwise, the pool_size_H = pool_size_W = pool_size. + is a list or tuple, it must contain two integers, (pool_size_height, pool_size_width). + Otherwise, the pool_size_height = pool_size_width = pool_size. conv_padding (int|list|tuple): The padding size of the Conv2d Layer. If padding is a list or tuple, its length must be equal to the length of conv_num_filter. Otherwise the conv_padding of all Conv2d Layers are the same. Default 1. From e14bb3254cc8324fb639230c6275f193bdcfa108 Mon Sep 17 00:00:00 2001 From: ceci3 <592712189@qq.com> Date: Sun, 29 Sep 2019 09:02:13 +0000 Subject: [PATCH 3/7] refine en doc, test=develop, test=document_fix --- paddle/fluid/API.spec | 16 ++-- python/paddle/fluid/layers/nn.py | 134 +++++++++++++++++++++---------- 2 files changed, 98 insertions(+), 52 deletions(-) diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index f42e7aa95558fd..aa0c1b30cdff54 100644 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -134,14 +134,14 @@ paddle.fluid.layers.dynamic_gru (ArgSpec(args=['input', 'size', 'param_attr', 'b paddle.fluid.layers.gru_unit (ArgSpec(args=['input', 'hidden', 'size', 'param_attr', 'bias_attr', 'activation', 'gate_activation', 'origin_mode'], varargs=None, keywords=None, defaults=(None, None, 'tanh', 'sigmoid', False)), ('document', '33974b9bfa69f2f1eb85e6f956dff04e')) paddle.fluid.layers.linear_chain_crf (ArgSpec(args=['input', 'label', 'param_attr', 'length'], varargs=None, keywords=None, defaults=(None, None)), ('document', '9045b8971e4232132ec9952695f4c3ae')) paddle.fluid.layers.crf_decoding (ArgSpec(args=['input', 'param_attr', 'label'], varargs=None, keywords=None, defaults=(None,)), ('document', '5ce117258e243be1c81539e254178d90')) -paddle.fluid.layers.cos_sim (ArgSpec(args=['X', 'Y'], varargs=None, keywords=None, defaults=None), ('document', '01fe5c35363aab3d8e2d9caee2cef911')) +paddle.fluid.layers.cos_sim (ArgSpec(args=['X', 'Y'], varargs=None, keywords=None, defaults=None), ('document', '9c15f6734cc5cf7e7be07ee3949af96e')) paddle.fluid.layers.cross_entropy (ArgSpec(args=['input', 'label', 'soft_label', 'ignore_index'], varargs=None, keywords=None, defaults=(False, -100)), ('document', '789a141e97fd0b37241f630935936d08')) paddle.fluid.layers.bpr_loss (ArgSpec(args=['input', 'label', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '6263dfdeb6c670fa0922c9cbc8fb1bf4')) paddle.fluid.layers.square_error_cost (ArgSpec(args=['input', 'label'], varargs=None, keywords=None, defaults=None), ('document', 'bbb9e708bab250359864fefbdf48e9d9')) paddle.fluid.layers.chunk_eval (ArgSpec(args=['input', 'label', 'chunk_scheme', 'num_chunk_types', 'excluded_chunk_types', 'seq_length'], varargs=None, keywords=None, defaults=(None, None)), ('document', 'b02844e0ad4bd713c5fe6802aa13219c')) paddle.fluid.layers.sequence_conv (ArgSpec(args=['input', 'num_filters', 'filter_size', 'filter_stride', 'padding', 'padding_start', 'bias_attr', 'param_attr', 'act', 'name'], varargs=None, keywords=None, defaults=(3, 1, True, None, None, None, None, None)), ('document', '2bf23e7884c380c3b27f2709aa322cb9')) -paddle.fluid.layers.conv2d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None)), ('document', 'd380c2c7f89884681f58f554ed485609')) -paddle.fluid.layers.conv3d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None)), ('document', '3e4223461ea20534b4e605dd912d4597')) +paddle.fluid.layers.conv2d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None)), ('document', '9dada3e2b3ff477ff7ed85915ef5575e')) +paddle.fluid.layers.conv3d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None)), ('document', 'b0a63d84f6bbcaa8a756c85e7f75de54')) paddle.fluid.layers.sequence_pool (ArgSpec(args=['input', 'pool_type', 'is_test', 'pad_value'], varargs=None, keywords=None, defaults=(False, 0.0)), ('document', 'e90a93251c52dc4e6fb34fb3991b3f82')) paddle.fluid.layers.sequence_softmax (ArgSpec(args=['input', 'use_cudnn', 'name'], varargs=None, keywords=None, defaults=(False, None)), ('document', 'eaa9d0bbd3d4e017c8bc4ecdac483711')) paddle.fluid.layers.softmax (ArgSpec(args=['input', 'use_cudnn', 'name', 'axis'], varargs=None, keywords=None, defaults=(False, None, -1)), ('document', 'cee673c79e3ff4582656a24e04f841e5')) @@ -149,12 +149,12 @@ paddle.fluid.layers.pool2d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'po paddle.fluid.layers.pool3d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'pool_stride', 'pool_padding', 'global_pooling', 'use_cudnn', 'ceil_mode', 'name', 'exclusive', 'data_format'], varargs=None, keywords=None, defaults=(-1, 'max', 1, 0, False, True, False, None, True, 'NCDHW')), ('document', 'db0035a3132b1dfb12e53c57591fb9f6')) paddle.fluid.layers.adaptive_pool2d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'require_index', 'name'], varargs=None, keywords=None, defaults=('max', False, None)), ('document', '52343203de40afe29607397e13aaf0d2')) paddle.fluid.layers.adaptive_pool3d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'require_index', 'name'], varargs=None, keywords=None, defaults=('max', False, None)), ('document', '55db6ae7275fb9678a6814aebab81a9c')) -paddle.fluid.layers.batch_norm (ArgSpec(args=['input', 'act', 'is_test', 'momentum', 'epsilon', 'param_attr', 'bias_attr', 'data_layout', 'in_place', 'name', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var', 'fuse_with_relu', 'use_global_stats'], varargs=None, keywords=None, defaults=(None, False, 0.9, 1e-05, None, None, 'NCHW', False, None, None, None, False, False, False)), ('document', 'ba4db9b833ea6e1c7011acf9cd036362')) -paddle.fluid.layers.instance_norm (ArgSpec(args=['input', 'epsilon', 'param_attr', 'bias_attr', 'name'], varargs=None, keywords=None, defaults=(1e-05, None, None, None)), ('document', '6dc0bc0ea1a744f2b2aeef94b809c37e')) +paddle.fluid.layers.batch_norm (ArgSpec(args=['input', 'act', 'is_test', 'momentum', 'epsilon', 'param_attr', 'bias_attr', 'data_layout', 'in_place', 'name', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var', 'fuse_with_relu', 'use_global_stats'], varargs=None, keywords=None, defaults=(None, False, 0.9, 1e-05, None, None, 'NCHW', False, None, None, None, False, False, False)), ('document', '803d1af04a738c74bfd1fe73606094d6')) +paddle.fluid.layers.instance_norm (ArgSpec(args=['input', 'epsilon', 'param_attr', 'bias_attr', 'name'], varargs=None, keywords=None, defaults=(1e-05, None, None, None)), ('document', '4af2dd074bdc419a013a35266401a0fe')) paddle.fluid.layers.data_norm (ArgSpec(args=['input', 'act', 'epsilon', 'param_attr', 'data_layout', 'in_place', 'name', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var'], varargs=None, keywords=None, defaults=(None, 1e-05, None, 'NCHW', False, None, None, None, False)), ('document', '2460b30fb87037555208fa8ac6fc1787')) paddle.fluid.layers.beam_search_decode (ArgSpec(args=['ids', 'scores', 'beam_size', 'end_id', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '83e08f21af41ac8bac37aeab1f86fdd0')) -paddle.fluid.layers.conv2d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None)), ('document', 'cd81fffa4c1c51bdd5c9e04964dcd8c4')) -paddle.fluid.layers.conv3d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None)), ('document', '5ab6f248eab45b4431ebb5356867bec0')) +paddle.fluid.layers.conv2d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None)), ('document', '2d5a4ec914b1f72082fbe052be10d7d9')) +paddle.fluid.layers.conv3d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None)), ('document', '86443b70ad12a92acc3aa2e5134646ef')) paddle.fluid.layers.sequence_expand (ArgSpec(args=['x', 'y', 'ref_level', 'name'], varargs=None, keywords=None, defaults=(-1, None)), ('document', '10e122eb755c2bd1f78ef2332b28f1a0')) paddle.fluid.layers.sequence_expand_as (ArgSpec(args=['x', 'y', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '858c432e7cbd8bb952cc2eb555457d50')) paddle.fluid.layers.sequence_pad (ArgSpec(args=['x', 'pad_value', 'maxlen', 'name'], varargs=None, keywords=None, defaults=(None, None)), ('document', 'df08b9c499ab3a90f95d08ab5b6c6c62')) @@ -297,7 +297,7 @@ paddle.fluid.layers.prroi_pool (ArgSpec(args=['input', 'rois', 'output_channels' paddle.fluid.layers.teacher_student_sigmoid_loss (ArgSpec(args=['input', 'label', 'soft_max_up_bound', 'soft_max_lower_bound'], varargs=None, keywords=None, defaults=(15.0, -15.0)), ('document', '07cb0d95a646dba1b9cc7cdce89e59f0')) paddle.fluid.layers.huber_loss (ArgSpec(args=['input', 'label', 'delta'], varargs=None, keywords=None, defaults=None), ('document', '11bb8e62cc9256958eff3991fe4834da')) 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', '713d93dc898862daed6de36438999a10')) +paddle.fluid.layers.npair_loss (ArgSpec(args=['anchor', 'positive', 'labels', 'l2_reg'], varargs=None, keywords=None, defaults=(0.002,)), ('document', '26fa1239852cc6043c0b1bc221a01af2')) 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.continuous_value_model (ArgSpec(args=['input', 'cvm', 'use_cvm'], varargs=None, keywords=None, defaults=(True,)), ('document', 'c03490ffaa1b78258747157c313db4cd')) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 559254912f54d8..1caa903bf3a350 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -2311,10 +2311,12 @@ def conv2d(input, W_{out}&= \\frac{(W_{in} + 2 * paddings[1] - (dilations[1] * (W_f - 1) + 1))}{strides[1]} + 1 Note: - padding mode is 'SAME' and 'VALID' can reference this link`_ + padding mode is 'SAME' and 'VALID' can reference this link`_ Args: - input (Variable): The input is 4-D Tensor with shape [N, C, H, W], the data type of input is float16 or float32 or float64. + input (Variable): The input is 4-D Tensor with shape [N, C, H, W], the data type + of input is float16 or float32 or float64. num_filters(int): The number of filter. It is as same as the output image channel. filter_size (int|tuple): The filter size. If filter_size @@ -2328,7 +2330,9 @@ def conv2d(input, on both sides for each dimention. If padding is a tuple, it must contain two integers, (padding_height, padding_width). Otherwise, padding_height = padding_width = padding. Default: padding = 0. - dilation (int|tuple): The dilation size. It means the spacing between the kernel points. This `link`_ has a nice visualization of what dilation does. If dilation is a tuple, it must + dilation (int|tuple): The dilation size. It means the spacing between the kernel + points. This `link`_ + has a nice visualization of what dilation does. If dilation is a tuple, it must contain two integers, (dilation_height, dilation_width). Otherwise, dilation_height = dilation_width = dilation. Default: dilation = 1. groups (int): The groups number of the Conv2d Layer. According to grouped @@ -2355,7 +2359,9 @@ def conv2d(input, None by default. Returns: - Variable: The output tensor and input tensor have same shape. If act is None, The tensor variable storing the convolution result, and if act is not None, the tensor variable storing convolution and non-linearity activation result. + Variable: The output tensor and input tensor have same shape. If act is None, + the tensor variable storing the convolution result, and if act is not + None, the tensor variable storing convolution and non-linearity activation result. Examples: .. code-block:: python @@ -2441,8 +2447,6 @@ def conv3d(input, act=None, name=None): """ - **Convlution3D Layer** - The convolution3D layer calculates the output based on the input, filter and strides, paddings, dilations, groups parameters. Input(Input) and Output(Output) are in NCDHW format. Where N is batch size C is the number of @@ -2487,7 +2491,8 @@ def conv3d(input, W_{out}&= \\frac{(W_{in} + 2 * paddings[2] - (dilations[2] * (W_f - 1) + 1))}{strides[2]} + 1 Args: - input (Variable): The input is 5-D Tensor with shape [N, C, D, H, W], the data type of input is float16 or float32 or float64. + input (Variable): The input is 5-D Tensor with shape [N, C, D, H, W], the data + type of input is float16 or float32 or float64. num_filters(int): The number of filter. It is as same as the output image channel. filter_size (int|tuple): The filter size. If filter_size is a tuple, @@ -2501,7 +2506,9 @@ def conv3d(input, for each dimention. If padding is a tuple, it must contain three integers, (padding_depth, padding_height, padding_width). Otherwise, padding_depth = padding_height = padding_width = \ padding. Default: padding = 0. - dilation (int|tuple): The dilation size. It means the spacing between the kernel points. This `link`_ has a nice visualization of what dilation does. If dilation is a tuple, it must + dilation (int|tuple): The dilation size. It means the spacing between the kernel points. + This `link`_ + has a nice visualization of what dilation does. If dilation is a tuple, it must contain three integers, (dilation_depth, dilation_height, dilation_width). Otherwise, dilation_depth = dilation_height = dilation_width = dilation. Default: dilation = 1. groups (int): The groups number of the Conv3d Layer. According to grouped @@ -2528,7 +2535,10 @@ def conv3d(input, None by default. Returns: - Variable: The output tensor and input tensor have same shape. If act is None, The tensor variable storing the convolution result, and if act is not None, the tensor variable storing convolution and non-linearity activation result. + Variable: The output tensor and input tensor have same shape. If act is None, + the tensor variable storing the convolution result, and if act is not + None, the tensor variable storing convolution and non-linearity + activation result. Examples: .. code-block:: python @@ -3517,7 +3527,8 @@ def batch_norm(input, sync_batch_norm automatically. Args: - input(variable): The rank of input variable can be 2, 3, 4, 5. The data type is float16 or float32 or float64. + input(variable): The rank of input variable can be 2, 3, 4, 5. The data type + is float16 or float32 or float64. act(string, Default None): Activation type, linear|relu|prelu|... is_test (bool, Default False): A flag indicating whether it is in test phrase or not. @@ -3540,7 +3551,8 @@ def batch_norm(input, Default: None. data_layout(str, default NCHW): the data_layout of input, is NCHW or NHWC. in_place(bool, Default False): Make the input and output of batch norm reuse memory. - name(str|None): For detailed information, please refer to :ref:`api_guide_Name`. Usually name is no need to set and None by default. + name(str|None): For detailed information, please refer to :ref:`api_guide_Name`. + Usually name is no need to set and None by default. moving_mean_name(str, Default None): The name of moving_mean which store the global Mean. If it is set to None, batch_norm will save global mean with a random name, otherwise, batch_norm will save global mean with the string. @@ -3556,7 +3568,8 @@ def batch_norm(input, and variance are also used during train period. Returns: - Variable: A tensor variable which is the result after applying batch normalization on the input. The shape of output equal to the shape of input. + Variable: A tensor variable which is the result after applying batch normalization on the input. + The shape of output equal to the shape of input. Examples: @@ -3691,7 +3704,8 @@ def instance_norm(input, y_i &\\gets \\gamma \\hat{x_i} + \\beta Args: - input(variable): The rank of input variable can be 2, 3, 4, 5. The data type is float32 or float64. + input(variable): The rank of input variable can be 2, 3, 4, 5. + The data type is float32 or float64. epsilon(float, Default 1e-05): A value added to the denominator for numerical stability. Default is 1e-5. param_attr(ParamAttr|None): The parameter attribute for Parameter `scale` @@ -3708,7 +3722,8 @@ def instance_norm(input, will be named automatically. Returns: - Variable: A tensor variable which is the result after applying instance normalization on the input. + Variable: A tensor variable which is the result after applying instance normalization + on the input. Examples: @@ -4201,8 +4216,6 @@ def conv2d_transpose(input, act=None, name=None): """ - **Convlution2D transpose layer** - The convolution2D transpose layer calculates the output based on the input, filter, and dilations, strides, paddings. Input(Input) and output(Output) are in NCHW format. Where N is batch size, C is the number of channels, @@ -4252,7 +4265,9 @@ def conv2d_transpose(input, W_{out} &\in [ W^\prime_{out}, W^\prime_{out} + strides[1] ] Note: - The conv2d_transpose can be seen as the backward of the conv2d. For conv2d, when stride > 1, conv2d maps multiple input shape to the same output shape, so for conv2d_transpose, when stride > 1, input shape maps multiple output shape. + The conv2d_transpose can be seen as the backward of the conv2d. For conv2d, + when stride > 1, conv2d maps multiple input shape to the same output shape, + so for conv2d_transpose, when stride > 1, input shape maps multiple output shape. If output_size is None, :math:`H_{out} = H^\prime_{out}, W_{out} = W^\prime_{out}`; else, the :math:`H_{out}` of the output size must between :math:`H^\prime_{out}` and :math:`H^\prime_{out} + strides[0]`, and the :math:`W_{out}` of the output size must @@ -4260,24 +4275,32 @@ def conv2d_transpose(input, conv2d_transpose can compute the kernel size automatically. Args: - input(Variable): The input is 4-D Tensor with shape [N, C, H, W], the data type of input is float32 or float64. + input(Variable): The input is 4-D Tensor with shape [N, C, H, W], the data type + of input is float32 or float64. num_filters(int): The number of the filter. It is as same as the output image channel. output_size(int|tuple|None): The output image size. If output size is a tuple, it must contain two integers, (image_height, image_width). None if use filter_size, padding, and stride to calculate output_size. If output_size and filter_size are specified at the same time, They - should follow the formula above. Default: None. output_size and filter_size should not be None at the same time. + should follow the formula above. Default: None. output_size and filter_size + should not be None at the same time. filter_size(int|tuple|None): The filter size. If filter_size is a tuple, it must contain two integers, (filter_size_height, filter_size_width). Otherwise, filter_size_height = filter_size_width = filter_size. None if - use output size to calculate filter_size. Default: None. filter_size and output_size should not be None at the same time. - padding(int|tuple): The padding size. The padding argument effectively adds `dilation * (kernel - 1)` amount of zero-padding on both sidee of input. If padding is a tuple, it must contain two integers, (padding_height, padding_width). Otherwise, - padding_height = padding_width = padding. Default: padding = 0. - stride(int|tuple): The stride size. It means the stride in transposed convolution. If stride is a tuple, it must - contain two integers, (stride_height, stride_width). Otherwise, - stride_height = stride_width = stride. Default: stride = 1. - dilation(int|tuple): The dilation size. It means the spacing between the kernel points. This `link`_ has a nice visualization of what dilation does. If dilation is a tuple, it must + use output size to calculate filter_size. Default: None. filter_size and + output_size should not be None at the same time. + padding(int|tuple): The padding size. The padding argument effectively adds + `dilation * (kernel - 1)` amount of zero-padding on both sides of input. + If padding is a tuple, it must contain two integers, (padding_height, \ + padding_width). Otherwise, padding_height = padding_width = padding. + Default: padding = 0. + stride(int|tuple): The stride size. It means the stride in transposed convolution. + If stride is a tuple, it must contain two integers, (stride_height, stride_width). + Otherwise, stride_height = stride_width = stride. Default: stride = 1. + dilation(int|tuple): The dilation size. It means the spacing between the kernel points. + This `link`_ + has a nice visualization of what dilation does. If dilation is a tuple, it must contain two integers, (dilation_height, dilation_width). Otherwise, dilation_height = dilation_width = dilation. Default: dilation = 1. groups(int): The groups number of the Conv2d transpose layer. Inspired by @@ -4304,7 +4327,10 @@ def conv2d_transpose(input, None by default. Returns: - Variable: The output tensor and input tensor have same shape. If act is None, The tensor variable storing the transposed convolution result, and if act is not None, the tensor variable storing transposed convolution and non-linearity activation result. + Variable: The output tensor and input tensor have same shape. If act is None, + the tensor variable storing the transposed convolution result, and + if act is not None, the tensor variable storing transposed convolution + and non-linearity activation result. Raises: ValueError: If the shapes of output, input, filter_size, stride, padding and @@ -4401,8 +4427,6 @@ def conv3d_transpose(input, act=None, name=None): """ - **Convlution3D transpose layer** - The convolution3D transpose layer calculates the output based on the input, filter, and dilations, strides, paddings. Input(Input) and output(Output) are in NCDHW format. Where N is batch size, C is the number of channels, @@ -4454,30 +4478,45 @@ def conv3d_transpose(input, W_{out} &\in [ W^\prime_{out}, W^\prime_{out} + strides[2] ] Note: - The conv3d_transpose can be seen as the backward of the conv3d. For conv3d, when stride > 1, conv3d maps multiple input shape to the same output shape, so for conv3d_transpose, when stride > 1, input shape maps multiple output shape. - If output_size is None, :math:`H_{out} = H^\prime_{out}, :math:`H_{out} = H^\prime_{out}, W_{out} = W^\prime_{out}`; - else, the :math:`D_{out}` of the output size must between :math:`D^\prime_{out}` and :math:`D^\prime_{out} + strides[0]`, the :math:`H_{out}` of the output size must between :math:`H^\prime_{out}` + The conv3d_transpose can be seen as the backward of the conv3d. For conv3d, + when stride > 1, conv3d maps multiple input shape to the same output shape, + so for conv3d_transpose, when stride > 1, input shape maps multiple output shape. + If output_size is None, :math:`H_{out} = H^\prime_{out}, :math:`H_{out} = \ + H^\prime_{out}, W_{out} = W^\prime_{out}`; else, the :math:`D_{out}` of the output + size must between :math:`D^\prime_{out}` and :math:`D^\prime_{out} + strides[0]`, + the :math:`H_{out}` of the output size must between :math:`H^\prime_{out}` and :math:`H^\prime_{out} + strides[1]`, and the :math:`W_{out}` of the output size must between :math:`W^\prime_{out}` and :math:`W^\prime_{out} + strides[2]`, conv3d_transpose can compute the kernel size automatically. Args: - input(Variable): The input is 5-D Tensor with shape [N, C, D, H, W], the data type of input is float32 or float64. + input(Variable): The input is 5-D Tensor with shape [N, C, D, H, W], the data type + of input is float32 or float64. num_filters(int): The number of the filter. It is as same as the output image channel. output_size(int|tuple|None): The output image size. If output size is a tuple, it must contain three integers, (image_depth, image_height, image_width). This - parameter only works when filter_size is None. If output_size and filter_size are specified at the same time, They should follow the formula above. Default: None. output_size and filter_size should not be None at the same time. + parameter only works when filter_size is None. If output_size and filter_size are + specified at the same time, They should follow the formula above. Default: None. + Output_size and filter_size should not be None at the same time. filter_size(int|tuple|None): The filter size. If filter_size is a tuple, it must contain three integers, (filter_size_depth, filter_size_height, \ filter_size_width). Otherwise, filter_size_depth = filter_size_height = \ filter_size_width = filter_size. None if use output size to - calculate filter_size. Default: None. filter_size and output_size should not be None at the same time. - padding(int|tuple): The padding size. The padding argument effectively adds `dilation * (kernel - 1)` amount of zero-padding on both sidee of input. If padding is a tuple, it must contain three integers, (padding_depth, padding_height, padding_width). Otherwise, padding_depth = padding_height = padding_width = padding. Default: padding = 0. - stride(int|tuple): The stride size. It means the stride in transposed convolution. If stride is a tuple, it must - contain three integers, (stride_depth, stride_height, stride_width). Otherwise, - stride_depth = stride_height = stride_width = stride. Default: stride = 1. - dilation(int|tuple): The dilation size. It means the spacing between the kernel points. This `link`_ has a nice visualization of what dilation does. If dilation is a tuple, it must + calculate filter_size. Default: None. filter_size and output_size should not be + None at the same time. + padding(int|tuple): The padding size. The padding argument effectively adds + `dilation * (kernel - 1)` amount of zero-padding on both sides of input. If padding + is a tuple, it must contain three integers, (padding_depth, padding_height, \ + padding_width). Otherwise, padding_depth = padding_height = padding_width = \ + padding. Default: padding = 0. + stride(int|tuple): The stride size. It means the stride in transposed convolution. + If stride is a tuple, it must contain three integers, (stride_depth, stride_height, + stride_width). Otherwise, stride_depth = stride_height = stride_width = stride. + Default: stride = 1. + dilation(int|tuple): The dilation size. It means the spacing between the kernel points. + This `link`_ has + a nice visualization of what dilation does. If dilation is a tuple, it must contain three integers, (dilation_depth, dilation_height, dilation_width). Otherwise, dilation_depth = dilation_height = dilation_width = dilation. Default: dilation = 1. groups(int): The groups number of the Conv3d transpose layer. Inspired by @@ -4504,7 +4543,10 @@ def conv3d_transpose(input, None by default. Returns: - Variable: The output tensor and input tensor have same shape. If act is None, The tensor variable storing the transposed convolution result, and if act is not None, the tensor variable storing transposed convolution and non-linearity activation result. + Variable: The output tensor and input tensor have same shape. If act is None, + the tensor variable storing the transposed convolution result, and + if act is not None, the tensor variable storing transposed convolution + and non-linearity activation result. Raises: ValueError: If the shapes of output, input, filter_size, stride, padding and @@ -14086,15 +14128,19 @@ def npair_loss(anchor, positive, labels, l2_reg=0.002): ''' **Npair Loss Layer** - Read `Improved Deep Metric Learning with Multi class N pair Loss Objective `_ . + Read `Improved Deep Metric Learning with Multi class N pair Loss Objective + `_ . Npair loss requires paired data. Npair loss has two parts: the first part is L2 regularizer on the embedding vector; the second part is cross entropy loss which takes the similarity matrix of anchor and positive as logits. Args: - anchor(Variable): embedding vector for the anchor image. shape=[batch_size, embedding_dims], the data type is float32 or float32. - positive(Variable): embedding vector for the positive image. shape=[batch_size, embedding_dims], the data type is float32 or float32. + anchor(Variable): embedding vector for the anchor image. shape=[batch_size, embedding_dims], + the data type is float32 or float32. + positive(Variable): embedding vector for the positive image. shape=[batch_size, embedding_dims], + the data type is float32 or float32. labels(Variable): 1-D tensor. shape=[batch_size], the data type is float32 or float32 or int64. l2_reg(float32): L2 regularization term on embedding vector, default: 0.002. From ad8f54a767a698f5d17f269289a057a5ad5061d8 Mon Sep 17 00:00:00 2001 From: ceci3 <592712189@qq.com> Date: Fri, 4 Oct 2019 07:39:22 +0000 Subject: [PATCH 4/7] add return, test=develop, test=document_fix --- paddle/fluid/API.spec | 16 ++++---- python/paddle/fluid/layers/nn.py | 68 +++++++++++++++----------------- 2 files changed, 40 insertions(+), 44 deletions(-) diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index fc1e76a2c4f1c0..3c838912ba3eeb 100644 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -140,8 +140,8 @@ paddle.fluid.layers.bpr_loss (ArgSpec(args=['input', 'label', 'name'], varargs=N paddle.fluid.layers.square_error_cost (ArgSpec(args=['input', 'label'], varargs=None, keywords=None, defaults=None), ('document', 'bbb9e708bab250359864fefbdf48e9d9')) paddle.fluid.layers.chunk_eval (ArgSpec(args=['input', 'label', 'chunk_scheme', 'num_chunk_types', 'excluded_chunk_types', 'seq_length'], varargs=None, keywords=None, defaults=(None, None)), ('document', 'b02844e0ad4bd713c5fe6802aa13219c')) paddle.fluid.layers.sequence_conv (ArgSpec(args=['input', 'num_filters', 'filter_size', 'filter_stride', 'padding', 'padding_start', 'bias_attr', 'param_attr', 'act', 'name'], varargs=None, keywords=None, defaults=(3, 1, True, None, None, None, None, None)), ('document', '2bf23e7884c380c3b27f2709aa322cb9')) -paddle.fluid.layers.conv2d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None)), ('document', 'd1b0f0224e840cb23308c8a01348c09f')) -paddle.fluid.layers.conv3d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None)), ('document', '7cc8979bc150ebb547b6c098202f4833')) +paddle.fluid.layers.conv2d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name', 'data_format'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None, 'NCHW')), ('document', 'f9602b8700cbdab2c6d3588b3defb398')) +paddle.fluid.layers.conv3d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name', 'data_format'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None, 'NCDHW')), ('document', 'c3dc7c4fc4f13b45c67b5701b9b2be25')) paddle.fluid.layers.sequence_pool (ArgSpec(args=['input', 'pool_type', 'is_test', 'pad_value'], varargs=None, keywords=None, defaults=(False, 0.0)), ('document', 'e90a93251c52dc4e6fb34fb3991b3f82')) paddle.fluid.layers.sequence_softmax (ArgSpec(args=['input', 'use_cudnn', 'name'], varargs=None, keywords=None, defaults=(False, None)), ('document', 'eaa9d0bbd3d4e017c8bc4ecdac483711')) paddle.fluid.layers.softmax (ArgSpec(args=['input', 'use_cudnn', 'name', 'axis'], varargs=None, keywords=None, defaults=(False, None, -1)), ('document', 'cee673c79e3ff4582656a24e04f841e5')) @@ -149,12 +149,12 @@ paddle.fluid.layers.pool2d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'po paddle.fluid.layers.pool3d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'pool_stride', 'pool_padding', 'global_pooling', 'use_cudnn', 'ceil_mode', 'name', 'exclusive', 'data_format'], varargs=None, keywords=None, defaults=(-1, 'max', 1, 0, False, True, False, None, True, 'NCDHW')), ('document', 'db0035a3132b1dfb12e53c57591fb9f6')) paddle.fluid.layers.adaptive_pool2d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'require_index', 'name'], varargs=None, keywords=None, defaults=('max', False, None)), ('document', '52343203de40afe29607397e13aaf0d2')) paddle.fluid.layers.adaptive_pool3d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'require_index', 'name'], varargs=None, keywords=None, defaults=('max', False, None)), ('document', '55db6ae7275fb9678a6814aebab81a9c')) -paddle.fluid.layers.batch_norm (ArgSpec(args=['input', 'act', 'is_test', 'momentum', 'epsilon', 'param_attr', 'bias_attr', 'data_layout', 'in_place', 'name', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var', 'fuse_with_relu', 'use_global_stats'], varargs=None, keywords=None, defaults=(None, False, 0.9, 1e-05, None, None, 'NCHW', False, None, None, None, False, False, False)), ('document', '803d1af04a738c74bfd1fe73606094d6')) -paddle.fluid.layers.instance_norm (ArgSpec(args=['input', 'epsilon', 'param_attr', 'bias_attr', 'name'], varargs=None, keywords=None, defaults=(1e-05, None, None, None)), ('document', '4af2dd074bdc419a013a35266401a0fe')) +paddle.fluid.layers.batch_norm (ArgSpec(args=['input', 'act', 'is_test', 'momentum', 'epsilon', 'param_attr', 'bias_attr', 'data_layout', 'in_place', 'name', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var', 'fuse_with_relu', 'use_global_stats'], varargs=None, keywords=None, defaults=(None, False, 0.9, 1e-05, None, None, 'NCHW', False, None, None, None, False, False, False)), ('document', '4b0c445fe804babe3a381b574e950554')) +paddle.fluid.layers.instance_norm (ArgSpec(args=['input', 'epsilon', 'param_attr', 'bias_attr', 'name'], varargs=None, keywords=None, defaults=(1e-05, None, None, None)), ('document', '6a97b3fcc98eeba368d6d2acb0858718')) paddle.fluid.layers.data_norm (ArgSpec(args=['input', 'act', 'epsilon', 'param_attr', 'data_layout', 'in_place', 'name', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var'], varargs=None, keywords=None, defaults=(None, 1e-05, None, 'NCHW', False, None, None, None, False)), ('document', '2460b30fb87037555208fa8ac6fc1787')) paddle.fluid.layers.beam_search_decode (ArgSpec(args=['ids', 'scores', 'beam_size', 'end_id', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '83e08f21af41ac8bac37aeab1f86fdd0')) -paddle.fluid.layers.conv2d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None)), ('document', '2d5a4ec914b1f72082fbe052be10d7d9')) -paddle.fluid.layers.conv3d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None)), ('document', '86443b70ad12a92acc3aa2e5134646ef')) +paddle.fluid.layers.conv2d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None)), ('document', 'a8d641712d76a27a14c9e13d9b2b3d78')) +paddle.fluid.layers.conv3d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None)), ('document', '0c18e1ed927c7ac33788b30f9aad016b')) paddle.fluid.layers.sequence_expand (ArgSpec(args=['x', 'y', 'ref_level', 'name'], varargs=None, keywords=None, defaults=(-1, None)), ('document', '10e122eb755c2bd1f78ef2332b28f1a0')) paddle.fluid.layers.sequence_expand_as (ArgSpec(args=['x', 'y', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '858c432e7cbd8bb952cc2eb555457d50')) paddle.fluid.layers.sequence_pad (ArgSpec(args=['x', 'pad_value', 'maxlen', 'name'], varargs=None, keywords=None, defaults=(None, None)), ('document', 'df08b9c499ab3a90f95d08ab5b6c6c62')) @@ -170,7 +170,7 @@ paddle.fluid.layers.reduce_any (ArgSpec(args=['input', 'dim', 'keep_dim', 'name' paddle.fluid.layers.sequence_first_step (ArgSpec(args=['input'], varargs=None, keywords=None, defaults=None), ('document', 'f2dfd65b859de9844e7261e7a4503f63')) paddle.fluid.layers.sequence_last_step (ArgSpec(args=['input'], varargs=None, keywords=None, defaults=None), ('document', '1af2e3a887e4f914f9d6650406186ab6')) paddle.fluid.layers.sequence_slice (ArgSpec(args=['input', 'offset', 'length', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '39fbc5437be389f6c0c769f82fc1fba2')) -paddle.fluid.layers.dropout (ArgSpec(args=['x', 'dropout_prob', 'is_test', 'seed', 'name', 'dropout_implementation'], varargs=None, keywords=None, defaults=(False, None, None, 'downgrade_in_infer')), ('document', 'd69730425965bf4ff9de8cd9e63b37a9')) +paddle.fluid.layers.dropout (ArgSpec(args=['x', 'dropout_prob', 'is_test', 'seed', 'name', 'dropout_implementation'], varargs=None, keywords=None, defaults=(False, None, None, 'downgrade_in_infer')), ('document', '70ae46baf90e2377e8d094d1c7e04129')) paddle.fluid.layers.split (ArgSpec(args=['input', 'num_or_sections', 'dim', 'name'], varargs=None, keywords=None, defaults=(-1, None)), ('document', '78cf3a7323d1a7697658242e13f63759')) paddle.fluid.layers.ctc_greedy_decoder (ArgSpec(args=['input', 'blank', 'input_length', 'padding_value', 'name'], varargs=None, keywords=None, defaults=(None, 0, None)), ('document', '9abb7bb8d267e017620a39a146dc47ea')) paddle.fluid.layers.edit_distance (ArgSpec(args=['input', 'label', 'normalized', 'ignored_tokens', 'input_length', 'label_length'], varargs=None, keywords=None, defaults=(True, None, None, None)), ('document', '77cbfb28cd2fc589f589c7013c5086cd')) @@ -297,7 +297,7 @@ paddle.fluid.layers.prroi_pool (ArgSpec(args=['input', 'rois', 'output_channels' paddle.fluid.layers.teacher_student_sigmoid_loss (ArgSpec(args=['input', 'label', 'soft_max_up_bound', 'soft_max_lower_bound'], varargs=None, keywords=None, defaults=(15.0, -15.0)), ('document', '07cb0d95a646dba1b9cc7cdce89e59f0')) paddle.fluid.layers.huber_loss (ArgSpec(args=['input', 'label', 'delta'], varargs=None, keywords=None, defaults=None), ('document', '11bb8e62cc9256958eff3991fe4834da')) 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', '26fa1239852cc6043c0b1bc221a01af2')) +paddle.fluid.layers.npair_loss (ArgSpec(args=['anchor', 'positive', 'labels', 'l2_reg'], varargs=None, keywords=None, defaults=(0.002,)), ('document', '623bb9849b65faa67b1cd2cf485a672c')) 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.continuous_value_model (ArgSpec(args=['input', 'cvm', 'use_cvm'], varargs=None, keywords=None, defaults=(True,)), ('document', 'c03490ffaa1b78258747157c313db4cd')) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 8d5cbdf73e4a66..39f4fdb2b68a4e 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -1645,7 +1645,7 @@ def dropout(x, Returns: - Variable: A tensor variable is the shape with `x`. + Variable: A Tensor Variable has same shape and data type with `x`. Examples: @@ -2311,10 +2311,6 @@ def conv2d(input, H_{out}&= \\frac{(H_{in} + 2 * paddings[0] - (dilations[0] * (H_f - 1) + 1))}{strides[0]} + 1 \\\\ W_{out}&= \\frac{(W_{in} + 2 * paddings[1] - (dilations[1] * (W_f - 1) + 1))}{strides[1]} + 1 - Note: - padding mode is 'SAME' and 'VALID' can reference this link`_ - Args: input (Variable): The input is 4-D Tensor with shape [N, C, H, W], the data type of input is float16 or float32 or float64. @@ -2368,9 +2364,10 @@ def conv2d(input, `[batch_size, input_channels, input_height, input_width]`. Returns: - Variable: The output tensor and input tensor have same shape. If act is None, - the tensor variable storing the convolution result, and if act is not - None, the tensor variable storing convolution and non-linearity activation result. + Variable: A Variable holding Tensor representing the conv2d, whose data type is the + same with input. If act is None, the tensor variable storing the convolution + result, and if act is not None, the tensor variable storing convolution + and non-linearity activation result. Examples: .. code-block:: python @@ -2616,10 +2613,10 @@ def conv3d(input, `[batch_size, input_channels, input_depth, input_height, input_width]`. Returns: - Variable: The output tensor and input tensor have same shape. If act is None, - the tensor variable storing the convolution result, and if act is not - None, the tensor variable storing convolution and non-linearity - activation result. + Variable: A Variable holding Tensor representing the conv3d, whose data type is + the same with input. If act is None, the tensor variable storing the + convolution result, and if act is not None, the tensor variable storing + convolution and non-linearity activation result. Examples: .. code-block:: python @@ -3714,8 +3711,8 @@ def batch_norm(input, and variance are also used during train period. Returns: - Variable: A tensor variable which is the result after applying batch normalization on the input. - The shape of output equal to the shape of input. + Variable: A Variable holding Tensor which is the result after applying batch normalization on the input, + has same shape and data type with input. Examples: @@ -3868,8 +3865,8 @@ def instance_norm(input, will be named automatically. Returns: - Variable: A tensor variable which is the result after applying instance normalization - on the input. + Variable: A Variable holding Tensor which is the result after applying instance normalization on the input, + has same shape and data type with input. Examples: @@ -4445,10 +4442,8 @@ def conv2d_transpose(input, If stride is a tuple, it must contain two integers, (stride_height, stride_width). Otherwise, stride_height = stride_width = stride. Default: stride = 1. dilation(int|tuple): The dilation size. It means the spacing between the kernel points. - This `link`_ - has a nice visualization of what dilation does. If dilation is a tuple, it must - contain two integers, (dilation_height, dilation_width). Otherwise, - dilation_height = dilation_width = dilation. Default: dilation = 1. + If dilation is a tuple, it must contain two integers, (dilation_height, dilation_width). + Otherwise, dilation_height = dilation_width = dilation. Default: dilation = 1. groups(int): The groups number of the Conv2d transpose layer. Inspired by grouped convolution in Alex Krizhevsky's Deep CNN paper, in which when group=2, the first half of the filters is only connected to the @@ -4473,10 +4468,11 @@ def conv2d_transpose(input, None by default. Returns: - Variable: The output tensor and input tensor have same shape. If act is None, - the tensor variable storing the transposed convolution result, and - if act is not None, the tensor variable storing transposed convolution - and non-linearity activation result. + Variable: A Variable holding Tensor representing the conv2d_transpose, whose + data type is the same with input. If act is None, the tensor variable + storing the transposed convolution result, and if act is not None, the + tensor variable storing transposed convolution and non-linearity activation + result. Raises: ValueError: If the shapes of output, input, filter_size, stride, padding and @@ -4661,10 +4657,9 @@ def conv3d_transpose(input, stride_width). Otherwise, stride_depth = stride_height = stride_width = stride. Default: stride = 1. dilation(int|tuple): The dilation size. It means the spacing between the kernel points. - This `link`_ has - a nice visualization of what dilation does. If dilation is a tuple, it must - contain three integers, (dilation_depth, dilation_height, dilation_width). Otherwise, - dilation_depth = dilation_height = dilation_width = dilation. Default: dilation = 1. + If dilation is a tuple, it must contain three integers, (dilation_depth, dilation_height, + dilation_width). Otherwise, dilation_depth = dilation_height = dilation_width = dilation. + Default: dilation = 1. groups(int): The groups number of the Conv3d transpose layer. Inspired by grouped convolution in Alex Krizhevsky's Deep CNN paper, in which when group=2, the first half of the filters is only connected to the @@ -4689,10 +4684,10 @@ def conv3d_transpose(input, None by default. Returns: - Variable: The output tensor and input tensor have same shape. If act is None, - the tensor variable storing the transposed convolution result, and - if act is not None, the tensor variable storing transposed convolution - and non-linearity activation result. + Variable: A Variable holding Tensor representing the conv3d_transpose, whose data + type is the same with input. If act is None, the tensor variable storing + the transposed convolution result, and if act is not None, the tensor + variable storing transposed convolution and non-linearity activation result. Raises: ValueError: If the shapes of output, input, filter_size, stride, padding and @@ -14284,14 +14279,15 @@ def npair_loss(anchor, positive, labels, l2_reg=0.002): Args: anchor(Variable): embedding vector for the anchor image. shape=[batch_size, embedding_dims], - the data type is float32 or float32. + the data type is float32 or float64. positive(Variable): embedding vector for the positive image. shape=[batch_size, embedding_dims], - the data type is float32 or float32. - labels(Variable): 1-D tensor. shape=[batch_size], the data type is float32 or float32 or int64. + the data type is float32 or float64. + labels(Variable): 1-D tensor. shape=[batch_size], the data type is float32 or float64 or int64. l2_reg(float32): L2 regularization term on embedding vector, default: 0.002. Returns: - Variable: Tensor, return npair loss, shape=[1] + Variable: A Variable holding Tensor representing the npair loss, the data type is the same as + anchor, the shape is [1]. Examples: .. code-block:: python From b1671bb3f0429eefaf36e10b4757cf992dd2483d Mon Sep 17 00:00:00 2001 From: ceci3 <592712189@qq.com> Date: Sun, 6 Oct 2019 17:18:18 +0000 Subject: [PATCH 5/7] update doc --- paddle/fluid/API.spec | 20 +++---- python/paddle/fluid/layers/nn.py | 89 +++++++++++++++----------------- python/paddle/fluid/nets.py | 4 +- 3 files changed, 55 insertions(+), 58 deletions(-) diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index 2b361da0d3d888..1c90f811e27d28 100644 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -134,14 +134,14 @@ paddle.fluid.layers.dynamic_gru (ArgSpec(args=['input', 'size', 'param_attr', 'b paddle.fluid.layers.gru_unit (ArgSpec(args=['input', 'hidden', 'size', 'param_attr', 'bias_attr', 'activation', 'gate_activation', 'origin_mode'], varargs=None, keywords=None, defaults=(None, None, 'tanh', 'sigmoid', False)), ('document', '33974b9bfa69f2f1eb85e6f956dff04e')) paddle.fluid.layers.linear_chain_crf (ArgSpec(args=['input', 'label', 'param_attr', 'length'], varargs=None, keywords=None, defaults=(None, None)), ('document', '9045b8971e4232132ec9952695f4c3ae')) paddle.fluid.layers.crf_decoding (ArgSpec(args=['input', 'param_attr', 'label'], varargs=None, keywords=None, defaults=(None,)), ('document', '5ce117258e243be1c81539e254178d90')) -paddle.fluid.layers.cos_sim (ArgSpec(args=['X', 'Y'], varargs=None, keywords=None, defaults=None), ('document', '9c15f6734cc5cf7e7be07ee3949af96e')) +paddle.fluid.layers.cos_sim (ArgSpec(args=['X', 'Y'], varargs=None, keywords=None, defaults=None), ('document', '07bb25484c98d529fbe67338422724af')) paddle.fluid.layers.cross_entropy (ArgSpec(args=['input', 'label', 'soft_label', 'ignore_index'], varargs=None, keywords=None, defaults=(False, -100)), ('document', '789a141e97fd0b37241f630935936d08')) paddle.fluid.layers.bpr_loss (ArgSpec(args=['input', 'label', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '6263dfdeb6c670fa0922c9cbc8fb1bf4')) paddle.fluid.layers.square_error_cost (ArgSpec(args=['input', 'label'], varargs=None, keywords=None, defaults=None), ('document', 'bbb9e708bab250359864fefbdf48e9d9')) paddle.fluid.layers.chunk_eval (ArgSpec(args=['input', 'label', 'chunk_scheme', 'num_chunk_types', 'excluded_chunk_types', 'seq_length'], varargs=None, keywords=None, defaults=(None, None)), ('document', 'b02844e0ad4bd713c5fe6802aa13219c')) paddle.fluid.layers.sequence_conv (ArgSpec(args=['input', 'num_filters', 'filter_size', 'filter_stride', 'padding', 'padding_start', 'bias_attr', 'param_attr', 'act', 'name'], varargs=None, keywords=None, defaults=(3, 1, True, None, None, None, None, None)), ('document', '2bf23e7884c380c3b27f2709aa322cb9')) -paddle.fluid.layers.conv2d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name', 'data_format'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None, 'NCHW')), ('document', 'f9602b8700cbdab2c6d3588b3defb398')) -paddle.fluid.layers.conv3d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name', 'data_format'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None, 'NCDHW')), ('document', 'c3dc7c4fc4f13b45c67b5701b9b2be25')) +paddle.fluid.layers.conv2d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name', 'data_format'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None, 'NCHW')), ('document', 'b9be3712a46e196c7329eed52ed91d05')) +paddle.fluid.layers.conv3d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name', 'data_format'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None, 'NCDHW')), ('document', 'a7e4573745c40b8b1d726709f209b6e4')) paddle.fluid.layers.sequence_pool (ArgSpec(args=['input', 'pool_type', 'is_test', 'pad_value'], varargs=None, keywords=None, defaults=(False, 0.0)), ('document', 'e90a93251c52dc4e6fb34fb3991b3f82')) paddle.fluid.layers.sequence_softmax (ArgSpec(args=['input', 'use_cudnn', 'name'], varargs=None, keywords=None, defaults=(False, None)), ('document', 'eaa9d0bbd3d4e017c8bc4ecdac483711')) paddle.fluid.layers.softmax (ArgSpec(args=['input', 'use_cudnn', 'name', 'axis'], varargs=None, keywords=None, defaults=(False, None, -1)), ('document', 'cee673c79e3ff4582656a24e04f841e5')) @@ -149,12 +149,12 @@ paddle.fluid.layers.pool2d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'po paddle.fluid.layers.pool3d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'pool_stride', 'pool_padding', 'global_pooling', 'use_cudnn', 'ceil_mode', 'name', 'exclusive', 'data_format'], varargs=None, keywords=None, defaults=(-1, 'max', 1, 0, False, True, False, None, True, 'NCDHW')), ('document', 'db0035a3132b1dfb12e53c57591fb9f6')) paddle.fluid.layers.adaptive_pool2d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'require_index', 'name'], varargs=None, keywords=None, defaults=('max', False, None)), ('document', '52343203de40afe29607397e13aaf0d2')) paddle.fluid.layers.adaptive_pool3d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'require_index', 'name'], varargs=None, keywords=None, defaults=('max', False, None)), ('document', '55db6ae7275fb9678a6814aebab81a9c')) -paddle.fluid.layers.batch_norm (ArgSpec(args=['input', 'act', 'is_test', 'momentum', 'epsilon', 'param_attr', 'bias_attr', 'data_layout', 'in_place', 'name', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var', 'fuse_with_relu', 'use_global_stats'], varargs=None, keywords=None, defaults=(None, False, 0.9, 1e-05, None, None, 'NCHW', False, None, None, None, False, False, False)), ('document', '4b0c445fe804babe3a381b574e950554')) -paddle.fluid.layers.instance_norm (ArgSpec(args=['input', 'epsilon', 'param_attr', 'bias_attr', 'name'], varargs=None, keywords=None, defaults=(1e-05, None, None, None)), ('document', '6a97b3fcc98eeba368d6d2acb0858718')) +paddle.fluid.layers.batch_norm (ArgSpec(args=['input', 'act', 'is_test', 'momentum', 'epsilon', 'param_attr', 'bias_attr', 'data_layout', 'in_place', 'name', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var', 'fuse_with_relu', 'use_global_stats'], varargs=None, keywords=None, defaults=(None, False, 0.9, 1e-05, None, None, 'NCHW', False, None, None, None, False, False, False)), ('document', 'b88a2a2d5de3e6d845d134782fb54857')) +paddle.fluid.layers.instance_norm (ArgSpec(args=['input', 'epsilon', 'param_attr', 'bias_attr', 'name'], varargs=None, keywords=None, defaults=(1e-05, None, None, None)), ('document', '5e2d18e85599ede7e71b06ed64d0f69e')) paddle.fluid.layers.data_norm (ArgSpec(args=['input', 'act', 'epsilon', 'param_attr', 'data_layout', 'in_place', 'name', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var'], varargs=None, keywords=None, defaults=(None, 1e-05, None, 'NCHW', False, None, None, None, False)), ('document', '2460b30fb87037555208fa8ac6fc1787')) paddle.fluid.layers.beam_search_decode (ArgSpec(args=['ids', 'scores', 'beam_size', 'end_id', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '83e08f21af41ac8bac37aeab1f86fdd0')) -paddle.fluid.layers.conv2d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None)), ('document', 'a8d641712d76a27a14c9e13d9b2b3d78')) -paddle.fluid.layers.conv3d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None)), ('document', '0c18e1ed927c7ac33788b30f9aad016b')) +paddle.fluid.layers.conv2d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None)), ('document', 'de4f1dffa8245f010a5f7e8f3952e90c')) +paddle.fluid.layers.conv3d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None)), ('document', 'fbbd2eab215f00a6ccd51d54d30dba87')) paddle.fluid.layers.sequence_expand (ArgSpec(args=['x', 'y', 'ref_level', 'name'], varargs=None, keywords=None, defaults=(-1, None)), ('document', '10e122eb755c2bd1f78ef2332b28f1a0')) paddle.fluid.layers.sequence_expand_as (ArgSpec(args=['x', 'y', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '858c432e7cbd8bb952cc2eb555457d50')) paddle.fluid.layers.sequence_pad (ArgSpec(args=['x', 'pad_value', 'maxlen', 'name'], varargs=None, keywords=None, defaults=(None, None)), ('document', 'df08b9c499ab3a90f95d08ab5b6c6c62')) @@ -170,7 +170,7 @@ paddle.fluid.layers.reduce_any (ArgSpec(args=['input', 'dim', 'keep_dim', 'name' paddle.fluid.layers.sequence_first_step (ArgSpec(args=['input'], varargs=None, keywords=None, defaults=None), ('document', 'f2dfd65b859de9844e7261e7a4503f63')) paddle.fluid.layers.sequence_last_step (ArgSpec(args=['input'], varargs=None, keywords=None, defaults=None), ('document', '1af2e3a887e4f914f9d6650406186ab6')) paddle.fluid.layers.sequence_slice (ArgSpec(args=['input', 'offset', 'length', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '39fbc5437be389f6c0c769f82fc1fba2')) -paddle.fluid.layers.dropout (ArgSpec(args=['x', 'dropout_prob', 'is_test', 'seed', 'name', 'dropout_implementation'], varargs=None, keywords=None, defaults=(False, None, None, 'downgrade_in_infer')), ('document', '70ae46baf90e2377e8d094d1c7e04129')) +paddle.fluid.layers.dropout (ArgSpec(args=['x', 'dropout_prob', 'is_test', 'seed', 'name', 'dropout_implementation'], varargs=None, keywords=None, defaults=(False, None, None, 'downgrade_in_infer')), ('document', 'b5542d9c05c673d13e7c653fe259c9ab')) paddle.fluid.layers.split (ArgSpec(args=['input', 'num_or_sections', 'dim', 'name'], varargs=None, keywords=None, defaults=(-1, None)), ('document', '78cf3a7323d1a7697658242e13f63759')) paddle.fluid.layers.ctc_greedy_decoder (ArgSpec(args=['input', 'blank', 'input_length', 'padding_value', 'name'], varargs=None, keywords=None, defaults=(None, 0, None)), ('document', '9abb7bb8d267e017620a39a146dc47ea')) paddle.fluid.layers.edit_distance (ArgSpec(args=['input', 'label', 'normalized', 'ignored_tokens', 'input_length', 'label_length'], varargs=None, keywords=None, defaults=(True, None, None, None)), ('document', '77cbfb28cd2fc589f589c7013c5086cd')) @@ -297,7 +297,7 @@ paddle.fluid.layers.prroi_pool (ArgSpec(args=['input', 'rois', 'output_channels' paddle.fluid.layers.teacher_student_sigmoid_loss (ArgSpec(args=['input', 'label', 'soft_max_up_bound', 'soft_max_lower_bound'], varargs=None, keywords=None, defaults=(15.0, -15.0)), ('document', '07cb0d95a646dba1b9cc7cdce89e59f0')) paddle.fluid.layers.huber_loss (ArgSpec(args=['input', 'label', 'delta'], varargs=None, keywords=None, defaults=None), ('document', '11bb8e62cc9256958eff3991fe4834da')) 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', '623bb9849b65faa67b1cd2cf485a672c')) +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.continuous_value_model (ArgSpec(args=['input', 'cvm', 'use_cvm'], varargs=None, keywords=None, defaults=(True,)), ('document', 'c03490ffaa1b78258747157c313db4cd')) @@ -907,7 +907,7 @@ paddle.fluid.nets.simple_img_conv_pool (ArgSpec(args=['input', 'num_filters', 'f paddle.fluid.nets.sequence_conv_pool (ArgSpec(args=['input', 'num_filters', 'filter_size', 'param_attr', 'act', 'pool_type', 'bias_attr'], varargs=None, keywords=None, defaults=(None, 'sigmoid', 'max', None)), ('document', 'd6a1e527b53f5cc15594fee307dfc5cf')) paddle.fluid.nets.glu (ArgSpec(args=['input', 'dim'], varargs=None, keywords=None, defaults=(-1,)), ('document', 'b87bacfc70dd3477ed25ef14aa01389a')) paddle.fluid.nets.scaled_dot_product_attention (ArgSpec(args=['queries', 'keys', 'values', 'num_heads', 'dropout_rate'], varargs=None, keywords=None, defaults=(1, 0.0)), ('document', 'b1a07a0000eb9103e3a143ca8c13de5b')) -paddle.fluid.nets.img_conv_group (ArgSpec(args=['input', 'conv_num_filter', 'pool_size', 'conv_padding', 'conv_filter_size', 'conv_act', 'param_attr', 'conv_with_batchnorm', 'conv_batchnorm_drop_rate', 'pool_stride', 'pool_type', 'use_cudnn'], varargs=None, keywords=None, defaults=(1, 3, None, None, False, 0.0, 1, 'max', True)), ('document', '97a3185b1edc97cb7eab25e0a6ddc407')) +paddle.fluid.nets.img_conv_group (ArgSpec(args=['input', 'conv_num_filter', 'pool_size', 'conv_padding', 'conv_filter_size', 'conv_act', 'param_attr', 'conv_with_batchnorm', 'conv_batchnorm_drop_rate', 'pool_stride', 'pool_type', 'use_cudnn'], varargs=None, keywords=None, defaults=(1, 3, None, None, False, 0.0, 1, 'max', True)), ('document', '591a48aa9d871896aa8548c977c4c120')) paddle.fluid.optimizer.SGDOptimizer ('paddle.fluid.optimizer.SGDOptimizer', ('document', 'c3c8dd3193d991adf8bda505560371d6')) paddle.fluid.optimizer.SGDOptimizer.__init__ (ArgSpec(args=['self', 'learning_rate', 'regularization', 'name'], varargs=None, keywords=None, defaults=(None, None)), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) paddle.fluid.optimizer.SGDOptimizer.apply_gradients (ArgSpec(args=['self', 'params_grads'], varargs=None, keywords=None, defaults=None), ('document', '80ea99c9af7ef5fac7e57fb302103610')) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 7bde29caca5c84..4e1e71c67d8504 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -1575,7 +1575,7 @@ def cos_sim(X, Y): Y (Variable): ${y_comment}. Returns: - Variable: LoDTensor, the output of cosine(X, Y). + A Variable holding LoDTensor representing the output of cosine(X, Y). Examples: .. code-block:: python @@ -1645,7 +1645,7 @@ def dropout(x, Returns: - Variable: A Tensor Variable has same shape and data type with `x`. + A Variable holding Tensor representing the dropout, has same shape and data type with `x`. Examples: @@ -2318,8 +2318,8 @@ def conv2d(input, image channel. filter_size (int|tuple): The filter size. If filter_size is a tuple, it must contain two integers, (filter_size_height, - filter_size_width). Otherwise, filter_size_height = filter_\ - size_width = filter_size. + filter_size_width). Otherwise, filter_size_height = filter_size_width =\ + filter_size. stride (int|tuple): The stride size. It means the stride in convolution. If stride is a tuple, it must contain two integers, (stride_height, stride_width). Otherwise, stride_height = stride_width = stride. Default: stride = 1. @@ -2328,13 +2328,13 @@ def conv2d(input, 'SAME' which is the padding algorithm. If padding size is a tuple or list, it could be in three forms: `[pad_height, pad_width]` or `[pad_height_top, pad_height_bottom, pad_width_left, pad_width_right]`, and when - `data_format` is `"NCHW"`, `padding` can be in the form `[[0,0], [0,0], \ + `data_format` is `"NCHW"`, `padding` can be in the form `[[0,0], [0,0], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right]]`. when `data_format` is `"NHWC"`, `pool_padding` can be in the form `[[0,0], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right], [0,0]]`. Default: padding = 0. dilation (int|tuple): The dilation size. It means the spacing between the kernel - points. If dilation is a tuple, it must contain two integers, (dilation_height, \ + points. If dilation is a tuple, it must contain two integers, (dilation_height, dilation_width). Otherwise, dilation_height = dilation_width = dilation. Default: dilation = 1. groups (int): The groups number of the Conv2d Layer. According to grouped @@ -2364,10 +2364,10 @@ def conv2d(input, `[batch_size, input_channels, input_height, input_width]`. Returns: - Variable: A Variable holding Tensor representing the conv2d, whose data type is the - same with input. If act is None, the tensor variable storing the convolution - result, and if act is not None, the tensor variable storing convolution - and non-linearity activation result. + A Variable holding Tensor representing the conv2d, whose data type is the + same with input. If act is None, the tensor variable storing the convolution + result, and if act is not None, the tensor variable storing convolution + and non-linearity activation result. Examples: .. code-block:: python @@ -2569,9 +2569,6 @@ def conv3d(input, stride (int|tuple): The stride size. It means the stride in convolution. If stride is a tuple, it must contain three integers, (stride_depth, stride_height, stride_width). Otherwise, stride_depth = stride_height = stride_width = stride. Default: stride = 1. - dilation (int|tuple): The dilation size. It means the spacing between the kernel points. - This `link`_ - has a nice visualization of what dilation does. If dilation is a tuple, it must padding (string|int|list|tuple): The padding size. It means the number of zero-paddings on both sides for each dimention. If `padding` is a string, either 'VALID' or 'SAME' which is the padding algorithm. If padding size is a tuple or list, @@ -2583,7 +2580,7 @@ def conv3d(input, `[[0,0], [pad_depth_front, pad_depth_back], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right], [0,0]]`. Default: padding = 0. dilation (int|tuple): The dilation size. It means the spacing between the kernel points. - If dilation is a tuple, it must contain three integers, (dilation_depth, dilation_height, \ + If dilation is a tuple, it must contain three integers, (dilation_depth, dilation_height, dilation_width). Otherwise, dilation_depth = dilation_height = dilation_width = dilation. Default: dilation = 1. groups (int): The groups number of the Conv3d Layer. According to grouped @@ -2613,10 +2610,10 @@ def conv3d(input, `[batch_size, input_channels, input_depth, input_height, input_width]`. Returns: - Variable: A Variable holding Tensor representing the conv3d, whose data type is - the same with input. If act is None, the tensor variable storing the - convolution result, and if act is not None, the tensor variable storing - convolution and non-linearity activation result. + A Variable holding Tensor representing the conv3d, whose data type is + the same with input. If act is None, the tensor variable storing the + convolution result, and if act is not None, the tensor variable storing + convolution and non-linearity activation result. Examples: .. code-block:: python @@ -3625,7 +3622,7 @@ def batch_norm(input, """ **Batch Normalization Layer** - Can be used as a normalizer function for convolution and fully_connected operations. + Can be used as a normalizer function for convolution or fully_connected operations. The required data format for this layer is one of the following: 1. NHWC `[batch, in_height, in_width, in_channels]` @@ -3648,10 +3645,11 @@ def batch_norm(input, \\sigma_{\\beta}^{2} + \\epsilon}} \\qquad &//\ normalize \\\\ y_i &\\gets \\gamma \\hat{x_i} + \\beta \\qquad &//\ scale\ and\ shift - moving\_mean = moving\_mean * momentum + mini-batch\_mean * (1. - momentum) - moving\_var = moving\_var * momentum + mini-batch\_var * (1. - momentum) - moving_mean and moving_var is global mean and global variance. + moving\_mean = moving\_mean * momentum + mini-batch\_mean * (1. - momentum) \\\\ + moving\_var = moving\_var * momentum + mini-batch\_var * (1. - momentum) + + moving_mean is global mean and moving_var is global variance. When use_global_stats = True, the :math:`\\mu_{\\beta}` and :math:`\\sigma_{\\beta}^{2}` are not the statistics of one mini-batch. @@ -3711,8 +3709,8 @@ def batch_norm(input, and variance are also used during train period. Returns: - Variable: A Variable holding Tensor which is the result after applying batch normalization on the input, - has same shape and data type with input. + A Variable holding Tensor which is the result after applying batch normalization on the input, + has same shape and data type with input. Examples: @@ -3821,7 +3819,7 @@ def instance_norm(input, """ **Instance Normalization Layer** - Can be used as a normalizer function for conv2d and fully_connected operations. + Can be used as a normalizer function for convolution or fully_connected operations. The required data format for this layer is one of the following: DataLayout: NCHW `[batch, in_channels, in_height, in_width]` @@ -3835,16 +3833,15 @@ def instance_norm(input, .. math:: \\mu_{\\beta} &\\gets \\frac{1}{HW} \\sum_{i=1}^{HW} x_i \\qquad &//\\ - \\ mean of one feature map in mini-batch \\\\ + \\ mean\ of\ one\ feature\ map\ in\ mini-batch \\\\ \\sigma_{\\beta}^{2} &\\gets \\frac{1}{HW} \\sum_{i=1}^{HW}(x_i - \\ - \\mu_{\\beta})^2 \\qquad &//\ variance of one feature map in mini-batch \\\\ + \\mu_{\\beta})^2 \\qquad &//\ variance\ of\ one\ feature\ map\ in\ mini-batch \\\\ \\hat{x_i} &\\gets \\frac{x_i - \\mu_\\beta} {\\sqrt{\\ \\sigma_{\\beta}^{2} + \\epsilon}} \\qquad &//\ normalize \\\\ y_i &\\gets \\gamma \\hat{x_i} + \\beta \\qquad &//\ scale\ and\ shift - \\hat{x_i} &\\gets \\frac{x_i - \\mu_\\beta} {\\sqrt{\\ - \\sigma_{\\beta}^{2} + \\epsilon}} \\\\ - y_i &\\gets \\gamma \\hat{x_i} + \\beta + Note: + `H` means height of feature map, `W` means width of feature map. Args: input(variable): The rank of input variable can be 2, 3, 4, 5. @@ -3865,8 +3862,8 @@ def instance_norm(input, will be named automatically. Returns: - Variable: A Variable holding Tensor which is the result after applying instance normalization on the input, - has same shape and data type with input. + A Variable holding Tensor which is the result after applying instance normalization on the input, + has same shape and data type with input. Examples: @@ -4468,11 +4465,11 @@ def conv2d_transpose(input, None by default. Returns: - Variable: A Variable holding Tensor representing the conv2d_transpose, whose - data type is the same with input. If act is None, the tensor variable - storing the transposed convolution result, and if act is not None, the - tensor variable storing transposed convolution and non-linearity activation - result. + A Variable holding Tensor representing the conv2d_transpose, whose + data type is the same with input. If act is None, the tensor variable + storing the transposed convolution result, and if act is not None, the + tensor variable storing transposed convolution and non-linearity activation + result. Raises: ValueError: If the shapes of output, input, filter_size, stride, padding and @@ -4642,14 +4639,14 @@ def conv3d_transpose(input, specified at the same time, They should follow the formula above. Default: None. Output_size and filter_size should not be None at the same time. filter_size(int|tuple|None): The filter size. If filter_size is a tuple, - it must contain three integers, (filter_size_depth, filter_size_height, \ + it must contain three integers, (filter_size_depth, filter_size_height, filter_size_width). Otherwise, filter_size_depth = filter_size_height = \ filter_size_width = filter_size. None if use output size to calculate filter_size. Default: None. filter_size and output_size should not be None at the same time. padding(int|tuple): The padding size. The padding argument effectively adds `dilation * (kernel - 1)` amount of zero-padding on both sides of input. If padding - is a tuple, it must contain three integers, (padding_depth, padding_height, \ + is a tuple, it must contain three integers, (padding_depth, padding_height, padding_width). Otherwise, padding_depth = padding_height = padding_width = \ padding. Default: padding = 0. stride(int|tuple): The stride size. It means the stride in transposed convolution. @@ -4684,10 +4681,10 @@ def conv3d_transpose(input, None by default. Returns: - Variable: A Variable holding Tensor representing the conv3d_transpose, whose data - type is the same with input. If act is None, the tensor variable storing - the transposed convolution result, and if act is not None, the tensor - variable storing transposed convolution and non-linearity activation result. + A Variable holding Tensor representing the conv3d_transpose, whose data + type is the same with input. If act is None, the tensor variable storing + the transposed convolution result, and if act is not None, the tensor + variable storing transposed convolution and non-linearity activation result. Raises: ValueError: If the shapes of output, input, filter_size, stride, padding and @@ -14287,7 +14284,7 @@ def npair_loss(anchor, positive, labels, l2_reg=0.002): ''' **Npair Loss Layer** - Read `Improved Deep Metric Learning with Multi class N pair Loss Objective + Read `Improved Deep Metric Learning with Multi class N pair Loss Objective\ `_ . @@ -14304,8 +14301,8 @@ def npair_loss(anchor, positive, labels, l2_reg=0.002): l2_reg(float32): L2 regularization term on embedding vector, default: 0.002. Returns: - Variable: A Variable holding Tensor representing the npair loss, the data type is the same as - anchor, the shape is [1]. + A Variable holding Tensor representing the npair loss, the data type is the same as + anchor, the shape is [1]. Examples: .. code-block:: python diff --git a/python/paddle/fluid/nets.py b/python/paddle/fluid/nets.py index 49837721ead66f..14bf9e874043e9 100644 --- a/python/paddle/fluid/nets.py +++ b/python/paddle/fluid/nets.py @@ -184,8 +184,8 @@ def img_conv_group(input, library is installed. Default: True Return: - Variable: The final result after serial computation using Convolution2d, - BatchNorm, DropOut, and Pool2d. + The final result after serial computation using Convolution2d, + BatchNorm, DropOut, and Pool2d. Examples: .. code-block:: python From 90df8996c9454e99490c6e9506fa21c3d8f217cf Mon Sep 17 00:00:00 2001 From: ceci3 <592712189@qq.com> Date: Mon, 7 Oct 2019 03:20:05 +0000 Subject: [PATCH 6/7] delete dropout_prob default, test=develop, test=document_fix --- paddle/fluid/API.spec | 6 +++--- python/paddle/fluid/layers/nn.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index 1c90f811e27d28..5e313f66563f01 100644 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -132,8 +132,8 @@ paddle.fluid.layers.dynamic_lstm (ArgSpec(args=['input', 'size', 'h_0', 'c_0', ' paddle.fluid.layers.dynamic_lstmp (ArgSpec(args=['input', 'size', 'proj_size', 'param_attr', 'bias_attr', 'use_peepholes', 'is_reverse', 'gate_activation', 'cell_activation', 'candidate_activation', 'proj_activation', 'dtype', 'name', 'h_0', 'c_0', 'cell_clip', 'proj_clip'], varargs=None, keywords=None, defaults=(None, None, True, False, 'sigmoid', 'tanh', 'tanh', 'tanh', 'float32', None, None, None, None, None)), ('document', 'c37d51aad655c8a9f9b045c64717320a')) paddle.fluid.layers.dynamic_gru (ArgSpec(args=['input', 'size', 'param_attr', 'bias_attr', 'is_reverse', 'gate_activation', 'candidate_activation', 'h_0', 'origin_mode'], varargs=None, keywords=None, defaults=(None, None, False, 'sigmoid', 'tanh', None, False)), ('document', '83617c165827e030636c80486d5de6f3')) paddle.fluid.layers.gru_unit (ArgSpec(args=['input', 'hidden', 'size', 'param_attr', 'bias_attr', 'activation', 'gate_activation', 'origin_mode'], varargs=None, keywords=None, defaults=(None, None, 'tanh', 'sigmoid', False)), ('document', '33974b9bfa69f2f1eb85e6f956dff04e')) -paddle.fluid.layers.linear_chain_crf (ArgSpec(args=['input', 'label', 'param_attr', 'length'], varargs=None, keywords=None, defaults=(None, None)), ('document', '9045b8971e4232132ec9952695f4c3ae')) -paddle.fluid.layers.crf_decoding (ArgSpec(args=['input', 'param_attr', 'label'], varargs=None, keywords=None, defaults=(None,)), ('document', '5ce117258e243be1c81539e254178d90')) +paddle.fluid.layers.linear_chain_crf (ArgSpec(args=['input', 'label', 'param_attr', 'length'], varargs=None, keywords=None, defaults=(None, None)), ('document', 'bc7a0fd2bb2b35dfd2f54947320e78fa')) +paddle.fluid.layers.crf_decoding (ArgSpec(args=['input', 'param_attr', 'label', 'length'], varargs=None, keywords=None, defaults=(None, None)), ('document', '933b7e268c4ffa3d5c3ef953a5ee9f0b')) paddle.fluid.layers.cos_sim (ArgSpec(args=['X', 'Y'], varargs=None, keywords=None, defaults=None), ('document', '07bb25484c98d529fbe67338422724af')) paddle.fluid.layers.cross_entropy (ArgSpec(args=['input', 'label', 'soft_label', 'ignore_index'], varargs=None, keywords=None, defaults=(False, -100)), ('document', '789a141e97fd0b37241f630935936d08')) paddle.fluid.layers.bpr_loss (ArgSpec(args=['input', 'label', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '6263dfdeb6c670fa0922c9cbc8fb1bf4')) @@ -170,7 +170,7 @@ paddle.fluid.layers.reduce_any (ArgSpec(args=['input', 'dim', 'keep_dim', 'name' paddle.fluid.layers.sequence_first_step (ArgSpec(args=['input'], varargs=None, keywords=None, defaults=None), ('document', 'f2dfd65b859de9844e7261e7a4503f63')) paddle.fluid.layers.sequence_last_step (ArgSpec(args=['input'], varargs=None, keywords=None, defaults=None), ('document', '1af2e3a887e4f914f9d6650406186ab6')) paddle.fluid.layers.sequence_slice (ArgSpec(args=['input', 'offset', 'length', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '39fbc5437be389f6c0c769f82fc1fba2')) -paddle.fluid.layers.dropout (ArgSpec(args=['x', 'dropout_prob', 'is_test', 'seed', 'name', 'dropout_implementation'], varargs=None, keywords=None, defaults=(False, None, None, 'downgrade_in_infer')), ('document', 'b5542d9c05c673d13e7c653fe259c9ab')) +paddle.fluid.layers.dropout (ArgSpec(args=['x', 'dropout_prob', 'is_test', 'seed', 'name', 'dropout_implementation'], varargs=None, keywords=None, defaults=(False, None, None, 'downgrade_in_infer')), ('document', '4fd396b6cf16bb4ef2a56d695d0ad941')) paddle.fluid.layers.split (ArgSpec(args=['input', 'num_or_sections', 'dim', 'name'], varargs=None, keywords=None, defaults=(-1, None)), ('document', '78cf3a7323d1a7697658242e13f63759')) paddle.fluid.layers.ctc_greedy_decoder (ArgSpec(args=['input', 'blank', 'input_length', 'padding_value', 'name'], varargs=None, keywords=None, defaults=(None, 0, None)), ('document', '9abb7bb8d267e017620a39a146dc47ea')) paddle.fluid.layers.edit_distance (ArgSpec(args=['input', 'label', 'normalized', 'ignored_tokens', 'input_length', 'label_length'], varargs=None, keywords=None, defaults=(True, None, None, None)), ('document', '77cbfb28cd2fc589f589c7013c5086cd')) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 4e1e71c67d8504..1891c9a5348b64 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -1618,7 +1618,7 @@ def dropout(x, Args: x (Variable): The input tensor variable. The data type is float16 or float32 or float64. - dropout_prob (float): Probability of setting units to zero. Default: 0.5. + dropout_prob (float): Probability of setting units to zero. is_test (bool): A flag indicating whether it is in test phrase or not. seed (int): A Python integer used to create random seeds. If this parameter is set to None, a random seed is used. From e0987bb7177fa44c9094725fae7382dbb4a81ec1 Mon Sep 17 00:00:00 2001 From: ceci3 <592712189@qq.com> Date: Tue, 8 Oct 2019 02:25:47 +0000 Subject: [PATCH 7/7] update API.spec,test=develop,test=document_fix --- paddle/fluid/API.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index 6b4350141ab54c..b7ff52f1d3e17a 100644 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -154,7 +154,7 @@ paddle.fluid.layers.instance_norm (ArgSpec(args=['input', 'epsilon', 'param_attr paddle.fluid.layers.data_norm (ArgSpec(args=['input', 'act', 'epsilon', 'param_attr', 'data_layout', 'in_place', 'name', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var'], varargs=None, keywords=None, defaults=(None, 1e-05, None, 'NCHW', False, None, None, None, False)), ('document', '2460b30fb87037555208fa8ac6fc1787')) paddle.fluid.layers.beam_search_decode (ArgSpec(args=['ids', 'scores', 'beam_size', 'end_id', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '83e08f21af41ac8bac37aeab1f86fdd0')) paddle.fluid.layers.conv2d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name', 'data_format'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None, 'NCHW')), ('document', '0ca6c549ac2b63096bdc7832a08b4431')) -paddle.fluid.layers.conv3d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name', 'data_format'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None, 'NCDHW')), ('document', '3393afeec7bf6fb6ebff086eecbc244a')) +paddle.fluid.layers.conv3d_transpose (ArgSpec(args=['input', 'num_filters', 'output_size', 'filter_size', 'padding', 'stride', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name', 'data_format'], varargs=None, keywords=None, defaults=(None, None, 0, 1, 1, None, None, None, True, None, None, 'NCDHW')), ('document', '709d7ca3a94f52a253d15b06aafb1bd0')) paddle.fluid.layers.sequence_expand (ArgSpec(args=['x', 'y', 'ref_level', 'name'], varargs=None, keywords=None, defaults=(-1, None)), ('document', '10e122eb755c2bd1f78ef2332b28f1a0')) paddle.fluid.layers.sequence_expand_as (ArgSpec(args=['x', 'y', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '858c432e7cbd8bb952cc2eb555457d50')) paddle.fluid.layers.sequence_pad (ArgSpec(args=['x', 'pad_value', 'maxlen', 'name'], varargs=None, keywords=None, defaults=(None, None)), ('document', 'df08b9c499ab3a90f95d08ab5b6c6c62'))