From 274fe576015efab420a9f7c02cc9f1da3926b8c6 Mon Sep 17 00:00:00 2001 From: wawltor Date: Thu, 20 Aug 2020 22:40:35 +0800 Subject: [PATCH] add the activation of sigmoid and layer of Sigmoid (#2380) * Udpate the doc format for the paddle, test=develop --- doc/fluid/api/nn.rst | 2 + .../api/nn/functional/activation/sigmoid.rst | 11 +++ doc/fluid/api/nn/layer/activation/Sigmoid.rst | 13 ++++ doc/fluid/api_cn/nn_cn.rst | 1 + .../api_cn/nn_cn/activation_cn/Sigmoid_cn.rst | 3 - doc/fluid/api_cn/nn_cn/functional_cn.rst | 1 + .../api_cn/nn_cn/functional_cn/sigmoid_cn.rst | 39 +++++----- doc/fluid/api_cn/nn_cn/layer_cn.rst | 11 +++ .../api_cn/nn_cn/layer_cn/Sigmoid_cn.rst | 40 +++++++++++ gen_index.py | 72 ------------------- 10 files changed, 98 insertions(+), 95 deletions(-) create mode 100644 doc/fluid/api/nn/functional/activation/sigmoid.rst create mode 100644 doc/fluid/api/nn/layer/activation/Sigmoid.rst delete mode 100644 doc/fluid/api_cn/nn_cn/activation_cn/Sigmoid_cn.rst create mode 100644 doc/fluid/api_cn/nn_cn/layer_cn.rst create mode 100644 doc/fluid/api_cn/nn_cn/layer_cn/Sigmoid_cn.rst delete mode 100644 gen_index.py diff --git a/doc/fluid/api/nn.rst b/doc/fluid/api/nn.rst index cfea0bdde..f88d8a291 100644 --- a/doc/fluid/api/nn.rst +++ b/doc/fluid/api/nn.rst @@ -152,4 +152,6 @@ paddle.nn nn/yolo_box.rst nn/yolov3_loss.rst nn/functional/loss/margin_ranking_loss.rst + nn/functional/activation/sigmoid.rst nn/layer/loss/MarginRankingLoss.rst + nn/layer/activation/Sigmoid.rst diff --git a/doc/fluid/api/nn/functional/activation/sigmoid.rst b/doc/fluid/api/nn/functional/activation/sigmoid.rst new file mode 100644 index 000000000..3ed969b9d --- /dev/null +++ b/doc/fluid/api/nn/functional/activation/sigmoid.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_nn_functional_activation_sigmoid: + +sigmoid +------- + +.. autofunction:: paddle.nn.functional.activation.sigmoid + :noindex: + diff --git a/doc/fluid/api/nn/layer/activation/Sigmoid.rst b/doc/fluid/api/nn/layer/activation/Sigmoid.rst new file mode 100644 index 000000000..46a0c2d26 --- /dev/null +++ b/doc/fluid/api/nn/layer/activation/Sigmoid.rst @@ -0,0 +1,13 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_nn_layer_activation_Sigmoid: + +Sigmoid +------- + +.. autoclass:: paddle.nn.layer.activation.Sigmoid + :members: + :inherited-members: + :noindex: + diff --git a/doc/fluid/api_cn/nn_cn.rst b/doc/fluid/api_cn/nn_cn.rst index f7e47d72f..fccb477ac 100644 --- a/doc/fluid/api_cn/nn_cn.rst +++ b/doc/fluid/api_cn/nn_cn.rst @@ -19,6 +19,7 @@ paddle.nn nn_cn/activation_cn.rst nn_cn/loss_cn.rst nn_cn/functional_cn.rst + nn_cn/layer_cn.rst nn_cn/adaptive_pool2d_cn.rst nn_cn/adaptive_pool3d_cn.rst nn_cn/add_position_encoding_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/activation_cn/Sigmoid_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn/Sigmoid_cn.rst deleted file mode 100644 index 0754265b2..000000000 --- a/doc/fluid/api_cn/nn_cn/activation_cn/Sigmoid_cn.rst +++ /dev/null @@ -1,3 +0,0 @@ -Sigmoid -------------------------------- -**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/nn_cn/functional_cn.rst b/doc/fluid/api_cn/nn_cn/functional_cn.rst index b64001598..d3c9b813b 100644 --- a/doc/fluid/api_cn/nn_cn/functional_cn.rst +++ b/doc/fluid/api_cn/nn_cn/functional_cn.rst @@ -12,5 +12,6 @@ functional functional_cn/nll_loss_cn.rst functional_cn/normalize_cn.rst functional_cn/margin_ranking_loss_cn.rst + functional_cn/sigmoid_cn.rst functional_cn/mse_loss_cn.rst functional_cn/sigmoid_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/functional_cn/sigmoid_cn.rst b/doc/fluid/api_cn/nn_cn/functional_cn/sigmoid_cn.rst index 0de495bc5..d5db5aa06 100644 --- a/doc/fluid/api_cn/nn_cn/functional_cn/sigmoid_cn.rst +++ b/doc/fluid/api_cn/nn_cn/functional_cn/sigmoid_cn.rst @@ -1,36 +1,35 @@ .. _cn_api_nn_functional_sigmoid: -sigmoid +sigmoid ------------------------------- .. py:function:: paddle.nn.functional.sigmoid(x, name=None) +sigmoid 激活函数。 + .. math:: -sigmoid激活函数 + output = \frac{1}{1 + e^{-x}} -.. math:: - out = \frac{1}{1 + e^{-x}} +参数 +:::::::: + **x** (Tensor) - 输入的 ``Tensor`` ,数据类型为:float32、float64、int32、int64。 + **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 +返回 +:::::::: + ``Tensor``, 经过 ``sigmoid`` 计算后的结果, 和输入 `x` 有一样的shape和数据类型。 -参数: - - **x** (Tensor) - 输入的 `Tensor` ,数据类型为:float32、float64。 - - **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 - -返回: - - Tensor,对输入x进行sigmoid激活后的Tensor,形状、数据类型与输入x一致。 - - -**代码示例**: - +代码示例 +::::::::: .. code-block:: python import numpy as np import paddle - import paddle.nn.functional as F + import paddle.nn.functional as F + paddle.disable_static() - x_data = np.array([-0.4, -0.2, 0.1, 0.3]) - x = paddle.to_tensor(x_data) - out = F.sigmoid(x) - print(out.numpy()) - # [0.40131234 0.450166 0.52497919 0.57444252] + input_data = np.array([1.0, 2.0, 3.0, 4.0]).astype('float32') + x = paddle.to_variable(input_data) + output = F.sigmoid(x) + print(output.numpy()) # [0.7310586, 0.880797, 0.95257413, 0.98201376] diff --git a/doc/fluid/api_cn/nn_cn/layer_cn.rst b/doc/fluid/api_cn/nn_cn/layer_cn.rst new file mode 100644 index 000000000..af4ec612d --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/layer_cn.rst @@ -0,0 +1,11 @@ +======================= +layer +======================= + + + + +.. toctree:: + :maxdepth: 1 + + layer_cn/Sigmoid_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/layer_cn/Sigmoid_cn.rst b/doc/fluid/api_cn/nn_cn/layer_cn/Sigmoid_cn.rst new file mode 100644 index 000000000..560bc22dd --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/layer_cn/Sigmoid_cn.rst @@ -0,0 +1,40 @@ +.. _cn_api_nn_layer_Sigmoid: + +Sigmoid +------------------------------- + +.. py:class:: paddle.nn.layer.Sigmoid(name=None) + +该接口用于创建一个 ``Sigmoid`` 的可调用类。 这个类可以计算输入 `x` 经过激活函数 `sigmoid` 之后的值。 + + .. math:: + + output = \frac{1}{1 + e^{-x}} + +参数 +:::::::: + - **name** (str,可选)- 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +形状 +:::::::: + - **x** (Tensor)- N-D tensor, 可以支持的数据类型是float16,float32,float64。 + +返回 +:::::::: + 返回计算 ``Sigmoid`` 的可调用对象。 + + +代码示例 +:::::::: + +.. code-block:: python + + import numpy as np + import paddle + + paddle.disable_static() + input_data = np.array([1.0, 2.0, 3.0, 4.0]).astype('float32') + m = paddle.nn.Sigmoid() + x = paddle.to_variable(input_data) + output = m(x) + print(output.numpy()) # [0.7310586, 0.880797, 0.95257413, 0.98201376 diff --git a/gen_index.py b/gen_index.py deleted file mode 100644 index e2817e3ab..000000000 --- a/gen_index.py +++ /dev/null @@ -1,72 +0,0 @@ -import argparse -import sys -import types -import os -import contextlib - - -def parse_arg(): - parser = argparse.ArgumentParser() - parser.add_argument( - '--api_path', - type=str, - default='paddle.nn.functional.l1_loss', - help='the function/class path') - parser.add_argument( - '--is_class', - type=str, - default='False', - help='whether function or class, False means function') - return parser.parse_args() - - -def add_index(en_doc_review_dir, api_name): - - stream = open(en_doc_review_dir + '.rst', 'a') - stream.write(' review_tmp/' + api_name + '.rst\n') - stream.close() - print('add index to ' + en_doc_review_dir + '.rst success') - - -def add_file(en_doc_review_dir, api_path, is_class=False): - - api_path_list = api_path.split('.') - api_name = api_path_list[-1] - api_title = '_'.join(api_path_list[1:]) - - stream = open(en_doc_review_dir + '/' + api_name + '.rst', 'w') - stream.write('.. _api_' + api_title + ':\n') - stream.write('\n') - stream.write(api_name + '\n') - for i in range(max(9, len(api_name))): - stream.write('-') - stream.write('\n') - stream.write('\n') - - if is_class == 'True': - stream.write('.. autoclass:: ' + api_path + '\n') - stream.write(' :members:\n') - stream.write(' :inherited-members:\n') - else: - stream.write('.. autofunction:: ' + api_path + '\n') - - stream.write(' :noindex:\n') - stream.close() - print('add' + en_doc_review_dir + '/' + api_name + '.rst success') - - -def main(): - args = parse_arg() - api_path = args.api_path - is_class = args.is_class - api_name = api_path.split('.')[-1] - - fluid_doc_path = os.getcwd() - en_doc_review_dir = fluid_doc_path + '/doc/fluid/api/review_tmp' - - add_index(en_doc_review_dir, api_name) - add_file(en_doc_review_dir, api_path, is_class) - - -if __name__ == '__main__': - main() -- GitLab