From 97f6f81cc0d17f48d0f9098759f13a1bd33c3939 Mon Sep 17 00:00:00 2001 From: zq19 <50872563+zq19@users.noreply.github.com> Date: Tue, 3 Sep 2019 15:53:16 +0800 Subject: [PATCH] Fix bug 0902 (#1134) * fixed one error of http://newicafe.baidu.com/issue/DLTP-2186/show * update api_cn of develop * fixed some errors of http://newicafe.baidu.com/issue/DLTP-2129/show --- doc/fluid/api_cn/fluid_cn/Executor_cn.rst | 2 +- .../api_cn/io_cn/save_persistables_cn.rst | 2 - doc/fluid/api_cn/layers_cn.rst | 19 ++++-- .../api_cn/layers_cn/Preprocessor_cn.rst | 40 ----------- .../api_cn/layers_cn/anchor_generator_cn.rst | 2 +- doc/fluid/api_cn/layers_cn/batch_cn.rst | 47 ------------- doc/fluid/api_cn/layers_cn/beam_search_cn.rst | 2 +- .../api_cn/layers_cn/conv2d_transpose_cn.rst | 2 +- doc/fluid/api_cn/layers_cn/elu_cn.rst | 4 +- doc/fluid/api_cn/layers_cn/lstm_unit_cn.rst | 4 +- doc/fluid/api_cn/layers_cn/open_files_cn.rst | 47 ------------- .../layers_cn/random_data_generator_cn.rst | 43 ------------ doc/fluid/api_cn/layers_cn/shard_index_cn.rst | 67 +++++++++++++++++++ .../api_guides/low_level/layers/math.rst | 4 +- 14 files changed, 92 insertions(+), 193 deletions(-) delete mode 100644 doc/fluid/api_cn/layers_cn/Preprocessor_cn.rst delete mode 100644 doc/fluid/api_cn/layers_cn/batch_cn.rst delete mode 100644 doc/fluid/api_cn/layers_cn/open_files_cn.rst delete mode 100644 doc/fluid/api_cn/layers_cn/random_data_generator_cn.rst create mode 100644 doc/fluid/api_cn/layers_cn/shard_index_cn.rst diff --git a/doc/fluid/api_cn/fluid_cn/Executor_cn.rst b/doc/fluid/api_cn/fluid_cn/Executor_cn.rst index e7ae1ee0f..76e26ad45 100644 --- a/doc/fluid/api_cn/fluid_cn/Executor_cn.rst +++ b/doc/fluid/api_cn/fluid_cn/Executor_cn.rst @@ -136,7 +136,7 @@ feed map为该program提供输入数据。fetch_list提供program训练结束后 - **fetch_var_name** (str) – 结果获取算子(fetch operator)的输出变量名称 - **scope** (Scope) – 执行这个program的域,用户可以指定不同的域。缺省为全局域 - **return_numpy** (bool) – 如果为True,则将结果张量(fetched tensor)转化为numpy - - **use_program_cache** (bool) – 是否跨批使用缓存程序设置。设置为True时,只有当(1)程序没有用数据并行编译,并且(2)program、 feed变量名和fetch_list变量名与上一步相比没有更改时,运行速度才会更快。 + - **use_program_cache** (bool) – 是否在不同的批次间使用相同的缓存程序设置。设置为True时,只有当(1)程序没有用数据并行编译,并且(2)program、 feed变量名和fetch_list变量名与上一步相比没有更改时,运行速度才会更快。 返回: 根据fetch_list来获取结果 diff --git a/doc/fluid/api_cn/io_cn/save_persistables_cn.rst b/doc/fluid/api_cn/io_cn/save_persistables_cn.rst index 773ccb7e0..d4d80f623 100644 --- a/doc/fluid/api_cn/io_cn/save_persistables_cn.rst +++ b/doc/fluid/api_cn/io_cn/save_persistables_cn.rst @@ -13,8 +13,6 @@ save_persistables - **executor** (Executor) – 保存变量的 executor - **dirname** (str) – 目录路径 - **main_program** (Program|None) – 需要保存变量的 Program。如果为 None,则使用 default_main_Program 。默认值: None - - **predicate** (function|None) – 如果不等于None,当指定main_program, 那么只有 predicate(variable)==True 时,main_program中的变量 - - **vars** (list[Variable]|None) – 要保存的所有变量的列表。 优先级高于main_program。默认值: None - **filename** (str|None) – 保存变量的文件。如果想分开保存变量,设置 filename=None. 默认值: None 返回: None diff --git a/doc/fluid/api_cn/layers_cn.rst b/doc/fluid/api_cn/layers_cn.rst index f812e6ad5..286e7a5e9 100644 --- a/doc/fluid/api_cn/layers_cn.rst +++ b/doc/fluid/api_cn/layers_cn.rst @@ -28,7 +28,6 @@ fluid.layers layers_cn/atan_cn.rst layers_cn/auc_cn.rst layers_cn/autoincreased_step_counter_cn.rst - layers_cn/batch_cn.rst layers_cn/batch_norm_cn.rst layers_cn/beam_search_cn.rst layers_cn/beam_search_decode_cn.rst @@ -41,6 +40,7 @@ fluid.layers layers_cn/brelu_cn.rst layers_cn/cast_cn.rst layers_cn/ceil_cn.rst + layers_cn/center_loss_cn.rst layers_cn/chunk_eval_cn.rst layers_cn/clip_by_norm_cn.rst layers_cn/clip_cn.rst @@ -96,9 +96,11 @@ fluid.layers layers_cn/exp_cn.rst layers_cn/expand_cn.rst layers_cn/exponential_decay_cn.rst + layers_cn/eye_cn.rst layers_cn/fc_cn.rst layers_cn/fill_constant_batch_size_like_cn.rst layers_cn/fill_constant_cn.rst + layers_cn/filter_by_instag_cn.rst layers_cn/flatten_cn.rst layers_cn/floor_cn.rst layers_cn/fsp_matrix_cn.rst @@ -116,6 +118,7 @@ fluid.layers layers_cn/gru_unit_cn.rst layers_cn/hard_shrink_cn.rst layers_cn/hard_sigmoid_cn.rst + layers_cn/hard_swish_cn.rst layers_cn/has_inf_cn.rst layers_cn/has_nan_cn.rst layers_cn/hash_cn.rst @@ -141,6 +144,7 @@ fluid.layers layers_cn/linear_lr_warmup_cn.rst layers_cn/linspace_cn.rst layers_cn/load_cn.rst + layers_cn/lod_append_cn.rst layers_cn/lod_reset_cn.rst layers_cn/log_cn.rst layers_cn/log_loss_cn.rst @@ -153,6 +157,7 @@ fluid.layers layers_cn/lstm_cn.rst layers_cn/lstm_unit_cn.rst layers_cn/margin_rank_loss_cn.rst + layers_cn/match_matrix_tensor_cn.rst layers_cn/matmul_cn.rst layers_cn/maxout_cn.rst layers_cn/mean_cn.rst @@ -165,11 +170,12 @@ fluid.layers layers_cn/natural_exp_decay_cn.rst layers_cn/nce_cn.rst layers_cn/noam_decay_cn.rst + layers_cn/Normal_cn.rst layers_cn/not_equal_cn.rst layers_cn/npair_loss_cn.rst layers_cn/one_hot_cn.rst layers_cn/ones_cn.rst - layers_cn/open_files_cn.rst + layers_cn/ones_like_cn.rst layers_cn/pad_cn.rst layers_cn/pad_constant_like_cn.rst layers_cn/pad2d_cn.rst @@ -181,14 +187,12 @@ fluid.layers layers_cn/pool3d_cn.rst layers_cn/pow_cn.rst layers_cn/prelu_cn.rst - layers_cn/Preprocessor_cn.rst layers_cn/Print_cn.rst layers_cn/prior_box_cn.rst layers_cn/psroi_pool_cn.rst layers_cn/py_func_cn.rst layers_cn/py_reader_cn.rst layers_cn/random_crop_cn.rst - layers_cn/random_data_generator_cn.rst layers_cn/range_cn.rst layers_cn/rank_cn.rst layers_cn/rank_loss_cn.rst @@ -207,6 +211,7 @@ fluid.layers layers_cn/reshape_cn.rst layers_cn/resize_bilinear_cn.rst layers_cn/resize_nearest_cn.rst + layers_cn/resize_trilinear_cn.rst layers_cn/retinanet_detection_output_cn.rst layers_cn/retinanet_target_assign_cn.rst layers_cn/reverse_cn.rst @@ -239,6 +244,7 @@ fluid.layers layers_cn/sequence_softmax_cn.rst layers_cn/sequence_unpad_cn.rst layers_cn/shape_cn.rst + layers_cn/shard_index_cn.rst layers_cn/shuffle_channel_cn.rst layers_cn/shuffle_cn.rst layers_cn/sigmoid_cn.rst @@ -280,10 +286,15 @@ fluid.layers layers_cn/topk_cn.rst layers_cn/transpose_cn.rst layers_cn/tree_conv_cn.rst + layers_cn/unfold_cn.rst + layers_cn/Uniform_cn.rst layers_cn/uniform_random_cn.rst layers_cn/uniform_random_batch_size_like_cn.rst + layers_cn/unique_cn.rst + layers_cn/unique_with_counts_cn.rst layers_cn/unsqueeze_cn.rst layers_cn/unstack_cn.rst + layers_cn/var_conv_2d_cn.rst layers_cn/warpctc_cn.rst layers_cn/where_cn.rst layers_cn/While_cn.rst diff --git a/doc/fluid/api_cn/layers_cn/Preprocessor_cn.rst b/doc/fluid/api_cn/layers_cn/Preprocessor_cn.rst deleted file mode 100644 index 95df07783..000000000 --- a/doc/fluid/api_cn/layers_cn/Preprocessor_cn.rst +++ /dev/null @@ -1,40 +0,0 @@ -.. _cn_api_fluid_layers_Preprocessor: - -Preprocessor -------------------------------- - -.. py:class:: paddle.fluid.layers.Preprocessor(reader, name=None) - -reader变量中数据预处理块。 - -参数: - - **reader** (Variable)-reader变量 - - **name** (str,默认None)-reader的名称 - -**代码示例**: - -.. code-block:: python - - import paddle.fluid as fluid - reader = fluid.layers.io.open_files( - filenames=['./data1.recordio', './data2.recordio'], - shapes=[(3, 224, 224), (1, )], - lod_levels=[0, 0], - dtypes=['float32', 'int64']) - - preprocessor = fluid.layers.io.Preprocessor(reader=reader) - with preprocessor.block(): - img, lbl = preprocessor.inputs() - img_out = img / 2 - lbl_out = lbl + 1 - preprocessor.outputs(img_out, lbl_out) - data_file = fluid.layers.io.double_buffer(preprocessor()) - - - - - - - - - diff --git a/doc/fluid/api_cn/layers_cn/anchor_generator_cn.rst b/doc/fluid/api_cn/layers_cn/anchor_generator_cn.rst index 655f61403..b6bd703a4 100644 --- a/doc/fluid/api_cn/layers_cn/anchor_generator_cn.rst +++ b/doc/fluid/api_cn/layers_cn/anchor_generator_cn.rst @@ -19,7 +19,7 @@ anchor_generator - **name** (str) - 先验框操作符名称。默认:None 返回: - - Anchors(Varibale): 输出anchor,布局[H,W,num_anchors,4] , ``H`` 是输入的高度, ``W`` 是输入的宽度, ``num_priors`` 是输入每位的框数,每个anchor格式(未归一化)为(xmin,ymin,xmax,ymax) + - Anchors(Varibale): 输出anchor,布局[H,W,num_anchors,4] , ``H`` 是输入的高度, ``W`` 是输入的宽度, ``num_anchors`` 是输入每位的框数,每个anchor格式(未归一化)为(xmin,ymin,xmax,ymax) - Variances(Variable): anchor的扩展变量布局为 [H,W,num_priors,4]。 ``H`` 是输入的高度, ``W`` 是输入的宽度, ``num_priors`` 是输入每个位置的框数,每个变量的格式为(xcenter,ycenter,w,h)。 diff --git a/doc/fluid/api_cn/layers_cn/batch_cn.rst b/doc/fluid/api_cn/layers_cn/batch_cn.rst deleted file mode 100644 index ebf09ca5b..000000000 --- a/doc/fluid/api_cn/layers_cn/batch_cn.rst +++ /dev/null @@ -1,47 +0,0 @@ -.. _cn_api_fluid_layers_batch: - -batch -------------------------------- - -.. py:function:: paddle.fluid.layers.batch(reader, batch_size) - -该层是一个reader装饰器。接受一个reader变量并添加``batching``装饰。读取装饰的reader,输出数据自动组织成batch的形式。 - -参数: - - **reader** (Variable)-装饰有“batching”的reader变量 - - **batch_size** (int)-批尺寸 - -返回:装饰有``batching``的reader变量 - -返回类型:变量(Variable) - -**代码示例**: - -.. code-block:: python - - import paddle.fluid as fluid - raw_reader = fluid.layers.io.open_files(filenames=['./data1.recordio', - './data2.recordio'], - shapes=[(3,224,224), (1,)], - lod_levels=[0, 0], - dtypes=['float32', 'int64'], - thread_num=2, - buffer_size=2) - batch_reader = fluid.layers.batch(reader=raw_reader, batch_size=5) - - # 如果用raw_reader读取数据: - # data = fluid.layers.read_file(raw_reader) - # 只能得到数据实例。 - # - # 但如果用batch_reader读取数据: - # data = fluid.layers.read_file(batch_reader) - # 每5个相邻的实例自动连接成一个batch。因此get('data')得到的是一个batch数据而不是一个实例。 - - - - - - - - - diff --git a/doc/fluid/api_cn/layers_cn/beam_search_cn.rst b/doc/fluid/api_cn/layers_cn/beam_search_cn.rst index 7bb2e241b..d053ab386 100644 --- a/doc/fluid/api_cn/layers_cn/beam_search_cn.rst +++ b/doc/fluid/api_cn/layers_cn/beam_search_cn.rst @@ -22,7 +22,7 @@ beam_search 参数: - **pre_ids** (Variable) - LodTensor变量,它是上一步 ``beam_search`` 的输出。在第一步中。它应该是LodTensor,shape为 :math:`(batch\_size,1)` , :math:`lod [[0,1,...,batch\_size],[0,1,...,batch\_size]]` - **pre_scores** (Variable) - LodTensor变量,它是上一步中beam_search的输出 - - **ids** (Variable) - 包含候选ID的LodTensor变量。shape为 :math:`(batch\_size×beam\_ize,K)` ,其中 ``K`` 应该是 ``beam_size`` + - **ids** (Variable) - 包含候选ID的LodTensor变量。shape为 :math:`(batch\_size×beam\_size,K)` ,其中 ``K`` 应该是 ``beam_size`` - **scores** (Variable) - 与 ``ids`` 及其shape对应的累积分数的LodTensor变量, 与 ``ids`` 的shape相同。 - **beam_size** (int) - 束搜索中的束宽度。 - **end_id** (int) - 结束标记的id。 diff --git a/doc/fluid/api_cn/layers_cn/conv2d_transpose_cn.rst b/doc/fluid/api_cn/layers_cn/conv2d_transpose_cn.rst index 0bfe3e20b..7cc64f2be 100644 --- a/doc/fluid/api_cn/layers_cn/conv2d_transpose_cn.rst +++ b/doc/fluid/api_cn/layers_cn/conv2d_transpose_cn.rst @@ -65,7 +65,7 @@ conv2d_transpose - **filter_size** (int|tuple|None) - 滤波器大小。如果filter_size是一个tuple,则形式为(filter_size_H, filter_size_W)。否则,滤波器将是一个方阵。如果filter_size=None,则内部会计算输出大小。 - **padding** (int|tuple) - 填充大小。如果padding是一个元组,它必须包含两个整数(padding_H、padding_W)。否则,padding_H = padding_W = padding。默认:padding = 0。 - **stride** (int|tuple) - 步长大小。如果stride是一个元组,那么元组的形式为(stride_H、stride_W)。否则,stride_H = stride_W = stride。默认:stride = 1。 - - **dilation** (int|元组) - 膨胀(dilation)大小。如果dilation是一个元组,那么元组的形式为(dilation_H, dilation_W)。否则,dilation_H = dilation_W = dilation_W。默认:dilation= 1。 + - **dilation** (int|元组) - 膨胀(dilation)大小。如果dilation是一个元组,那么元组的形式为(dilation_H, dilation_W)。否则,dilation_H = dilation_W = dilation。默认:dilation= 1。 - **groups** (int) - Conv2d转置层的groups个数。从Alex Krizhevsky的CNN Deep论文中的群卷积中受到启发,当group=2时,前半部分滤波器只连接到输入通道的前半部分,而后半部分滤波器只连接到输入通道的后半部分。默认值:group = 1。 - **param_attr** (ParamAttr|None) - conv2d_transfer中可学习参数/权重的属性。如果param_attr值为None或ParamAttr的一个属性,conv2d_transfer使用ParamAttrs作为param_attr的值。如果没有设置的param_attr初始化器,那么使用Xavier初始化。默认值:None。 - **bias_attr** (ParamAttr|bool|None) - conv2d_tran_bias中的bias属性。如果设置为False,则不会向输出单元添加偏置。如果param_attr值为None或ParamAttr的一个属性,将conv2d_transfer使用ParamAttrs作为,bias_attr。如果没有设置bias_attr的初始化器,bias将初始化为零。默认值:None。 diff --git a/doc/fluid/api_cn/layers_cn/elu_cn.rst b/doc/fluid/api_cn/layers_cn/elu_cn.rst index 370e393a9..8fe2b3a80 100644 --- a/doc/fluid/api_cn/layers_cn/elu_cn.rst +++ b/doc/fluid/api_cn/layers_cn/elu_cn.rst @@ -10,11 +10,11 @@ ELU激活层(ELU Activation Operator) 根据 https://arxiv.org/abs/1511.07289 对输入张量中每个元素应用以下计算。 .. math:: - \\out=max(0,x)+min(0,α∗(ex−1))\\ + \\out=max(0,x)+min(0,α∗(e^{x}−1))\\ 参数: - x(Variable)- ELU operator的输入 - - alpha(FAOAT|1.0)- ELU的alpha值 + - alpha(float|1.0)- ELU的alpha值 - name (str|None) -这个层的名称(可选)。如果设置为None,该层将被自动命名。 返回: ELU操作符的输出 diff --git a/doc/fluid/api_cn/layers_cn/lstm_unit_cn.rst b/doc/fluid/api_cn/layers_cn/lstm_unit_cn.rst index 7e919a7d8..fc7180629 100644 --- a/doc/fluid/api_cn/layers_cn/lstm_unit_cn.rst +++ b/doc/fluid/api_cn/layers_cn/lstm_unit_cn.rst @@ -33,8 +33,8 @@ lstm单元的输入包括 :math:`x_{t}` , :math:`h_{t-1}` 和 :math:`c_{t-1}` 参数: - **x_t** (Variable) - 当前步的输入值,二维张量,shape为 M x N ,M是批尺寸,N是输入尺寸 - - **hidden_t_prev** (Variable) - lstm单元的隐藏状态值,二维张量,shape为 M x S,M是批尺寸,N是lstm单元的大小 - - **cell_t_prev** (Variable) - lstm单元的cell值,二维张量,shape为 M x S ,M是批尺寸,N是lstm单元的大小 + - **hidden_t_prev** (Variable) - lstm单元的隐藏状态值,二维张量,shape为 M x S,M是批尺寸,S是lstm单元的大小 + - **cell_t_prev** (Variable) - lstm单元的cell值,二维张量,shape为 M x S ,M是批尺寸,S是lstm单元的大小 - **forget_bias** (Variable) - lstm单元的遗忘bias - **param_attr** (ParamAttr|None) - 可学习hidden-hidden权重的擦参数属性。如果设为None或者 ``ParamAttr`` 的一个属性,lstm_unit创建 ``ParamAttr`` 为param_attr。如果param_attr的初始化函数未设置,参数初始化为Xavier。默认:None - **bias_attr** (ParamAttr|None) - 可学习bias权重的bias属性。如果设为False,输出单元中则不添加bias。如果设为None或者 ``ParamAttr`` 的一个属性,lstm_unit创建 ``ParamAttr`` 为bias_attr。如果bias_attr的初始化函数未设置,bias初始化为0.默认:None diff --git a/doc/fluid/api_cn/layers_cn/open_files_cn.rst b/doc/fluid/api_cn/layers_cn/open_files_cn.rst deleted file mode 100644 index 6cd0a4a6c..000000000 --- a/doc/fluid/api_cn/layers_cn/open_files_cn.rst +++ /dev/null @@ -1,47 +0,0 @@ -.. _cn_api_fluid_layers_open_files: - -open_files -------------------------------- - -.. py:function:: paddle.fluid.layers.open_files(filenames, shapes, lod_levels, dtypes, thread_num=None, buffer_size=None, pass_num=1, is_test=None) - -打开文件(Open files) - -该函数获取需要读取的文件列表,并返回Reader变量。通过Reader变量,我们可以从给定的文件中获取数据。所有文件必须有名称后缀来表示它们的格式,例如,``*.recordio``。 - -参数: - - **filenames** (list)-文件名列表 - - **shape** (list)-元组类型值列表,声明数据维度 - - **lod_levels** (list)-整形值列表,声明数据的lod层级 - - **dtypes** (list)-字符串类型值列表,声明数据类型 - - **thread_num** (None)-用于读文件的线程数。默认:min(len(filenames),cpu_number) - - **buffer_size** (None)-reader的缓冲区大小。默认:3*thread_num - - **pass_num** (int)-用于运行的传递数量 - - **is_test** (bool|None)-open_files是否用于测试。如果用于测试,生成的数据顺序和文件顺序一致。反之,无法保证每一epoch之间的数据顺序是一致的 - -返回:一个Reader变量,通过该变量获取文件数据 - -返回类型:变量(Variable) - -**代码示例**: - -.. code-block:: python - - import paddle.fluid as fluid - reader = fluid.layers.io.open_files(filenames=['./data1.recordio', - './data2.recordio'], - shapes=[(3,224,224), (1,)], - lod_levels=[0, 0], - dtypes=['float32', 'int64']) - - # 通过reader, 可使用''read_file''层获取数据: - image, label = fluid.layers.io.read_file(reader) - - - - - - - - - diff --git a/doc/fluid/api_cn/layers_cn/random_data_generator_cn.rst b/doc/fluid/api_cn/layers_cn/random_data_generator_cn.rst deleted file mode 100644 index ffd91283d..000000000 --- a/doc/fluid/api_cn/layers_cn/random_data_generator_cn.rst +++ /dev/null @@ -1,43 +0,0 @@ -.. _cn_api_fluid_layers_random_data_generator: - -random_data_generator -------------------------------- - -.. py:function:: paddle.fluid.layers.random_data_generator(low, high, shapes, lod_levels, for_parallel=True) - -创建一个均匀分布随机数据生成器. - -该层返回一个Reader变量。该Reader变量不是用于打开文件读取数据,而是自生成float类型的均匀分布随机数。该变量可作为一个虚拟reader来测试网络,而不需要打开一个真实的文件。 - -参数: - - **low** (float)--数据均匀分布的下界 - - **high** (float)-数据均匀分布的上界 - - **shapes** (list)-元组数列表,声明数据维度 - - **lod_levels** (list)-整形数列表,声明数据 - - **for_parallel** (Bool)-若要运行一系列操作命令则将其设置为True - -返回:Reader变量,可从中获取随机数据 - -返回类型:变量(Variable) - -**代码示例**: - -.. code-block:: python - - import paddle.fluid as fluid - reader = fluid.layers.random_data_generator( - low=0.0, - high=1.0, - shapes=[[3,224,224], [1]], - lod_levels=[0, 0]) - # 通过reader, 可以用'read_file'层获取数据: - image, label = fluid.layers.read_file(reader) - - - - - - - - - diff --git a/doc/fluid/api_cn/layers_cn/shard_index_cn.rst b/doc/fluid/api_cn/layers_cn/shard_index_cn.rst new file mode 100644 index 000000000..26b7b1bed --- /dev/null +++ b/doc/fluid/api_cn/layers_cn/shard_index_cn.rst @@ -0,0 +1,67 @@ +.. _cn_api_fluid_layers_shard_index: + +shard_index +------------------------------- + +.. py:function:: paddle.fluid.layers.shard_index(input, index_num, nshards, shard_id, ignore_value=-1) + +该层为输入创建碎片化索引,通常在模型和数据并行混合训练时使用,索引数据(通常是标签)应该在每一个trainer里面被计算,通过 +:: + + assert index_num % nshards == 0 + + shard_size = index_num / nshards + + 如果 x / shard_size == shard_id + + y = x % shard_size + + 否则 + + y = ignore_value + +我们使用分布式 ``one-hot`` 表示来展示该层如何使用, 分布式的 ``one-hot`` 表示被分割为多个碎片, 碎片索引里不为1的都使用0来填充。为了在每一个trainer里面创建碎片化的表示,原始的索引应该先进行计算(i.e. sharded)。我们来看个例子: + +.. code-block:: text + + X 是一个整形张量 + X.shape = [4, 1] + X.data = [[1], [6], [12], [19]] + + 假设 index_num = 20 并且 nshards = 2, 我们可以得到 shard_size = 10 + + 如果 shard_id == 0, 我们得到输出: + Out.shape = [4, 1] + Out.data = [[1], [6], [-1], [-1]] + 如果 shard_id == 1, 我们得到输出: + Out.shape = [4, 1] + Out.data = [[-1], [-1], [2], [9]] + + 上面的例子中默认 ignore_value = -1 + +参数: + - **input** (Variable)- 输入的索引,最后的维度应该为1 + - **index_num** (scalar) - 定义索引长度的整形参数 + - **nshards** (scalar) - shards数量 + - **shard_id** (scalar) - 当前碎片的索引 + - **ignore_value** (scalar) - 超出碎片索引范围的整型值 + +返回: 输入的碎片索引 + +返回类型: Variable + +**代码示例:** + +.. code-block:: python + + import paddle.fluid as fluid + label = fluid.layers.data(name="label", shape=[1], dtype="int64") + shard_label = fluid.layers.shard_index(input=label, + index_num=20, + nshards=2, + shard_id=0) + + + + + diff --git a/doc/fluid/api_guides/low_level/layers/math.rst b/doc/fluid/api_guides/low_level/layers/math.rst index 1379077d2..e00df723d 100644 --- a/doc/fluid/api_guides/low_level/layers/math.rst +++ b/doc/fluid/api_guides/low_level/layers/math.rst @@ -55,14 +55,14 @@ API Reference 请参考 :ref:`cn_api_fluid_layers_floor` sin ------------------ -对输入 :code:`Tensor` 逐元素取正玄。 +对输入 :code:`Tensor` 逐元素取正弦。 API Reference 请参考 :ref:`cn_api_fluid_layers_sin` cos ------------------ -对输入 :code:`Tensor` 逐元素取余玄。 +对输入 :code:`Tensor` 逐元素取余弦。 API Reference 请参考 :ref:`cn_api_fluid_layers_cos` -- GitLab