From b25e612eab0df2cb8c3a1110d207ce38a8455c6c Mon Sep 17 00:00:00 2001 From: JesseyXujin Date: Sat, 21 Sep 2019 19:47:59 +0800 Subject: [PATCH] fix API docs, test=document_preview (#1190) * fix APIS,stanh,accuracy,auc,smooth_l1,linear_chain_crf,sigmoid,softmax, test=document_preview * fix notification, test=document_preview --- doc/fluid/api_cn/layers_cn/accuracy_cn.rst | 54 +++++---- doc/fluid/api_cn/layers_cn/auc_cn.rst | 53 ++++++--- .../api_cn/layers_cn/linear_chain_crf_cn.rst | 104 +++++++++++++----- doc/fluid/api_cn/layers_cn/sigmoid_cn.rst | 27 +++-- doc/fluid/api_cn/layers_cn/smooth_l1_cn.rst | 39 ++++--- doc/fluid/api_cn/layers_cn/softmax_cn.rst | 41 ++++--- doc/fluid/api_cn/layers_cn/stanh_cn.rst | 37 ++++--- 7 files changed, 235 insertions(+), 120 deletions(-) mode change 100644 => 100755 doc/fluid/api_cn/layers_cn/accuracy_cn.rst mode change 100644 => 100755 doc/fluid/api_cn/layers_cn/auc_cn.rst mode change 100644 => 100755 doc/fluid/api_cn/layers_cn/linear_chain_crf_cn.rst mode change 100644 => 100755 doc/fluid/api_cn/layers_cn/sigmoid_cn.rst mode change 100644 => 100755 doc/fluid/api_cn/layers_cn/smooth_l1_cn.rst mode change 100644 => 100755 doc/fluid/api_cn/layers_cn/softmax_cn.rst diff --git a/doc/fluid/api_cn/layers_cn/accuracy_cn.rst b/doc/fluid/api_cn/layers_cn/accuracy_cn.rst old mode 100644 new mode 100755 index 181f9327e..c607d770d --- a/doc/fluid/api_cn/layers_cn/accuracy_cn.rst +++ b/doc/fluid/api_cn/layers_cn/accuracy_cn.rst @@ -7,37 +7,43 @@ accuracy accuracy layer。 参考 https://en.wikipedia.org/wiki/Precision_and_recall -使用输入和标签计算准确率。 每个类别中top k 中正确预测的个数。注意:准确率的 dtype 由输入决定。 输入和标签 dtype 可以不同。 +使用输入和标签计算准确率。 如果正确的标签在topk个预测值里,则计算结果加1。注意:输出正确率的类型由input类型决定,input和lable的类型可以不一样。 参数: - - **input** (Variable)-该层的输入,即网络的预测。支持 Carry LoD。 - - **label** (Variable)-数据集的标签。 - - **k** (int) - 每个类别的 top k - - **correct** (Variable)-正确的预测个数。 - - **total** (Variable)-总共的样本数。 + - **input** (Tensor|LoDTensor)-数据类型为float32,float64。输入为网络的预测值。 + - **label** (Tensor|LoDTensor)-数据类型为int64,int32。输入为数据集的标签。 + - **k** (int64|int32) - 取每个类别中k个预测值用于计算。 + - **correct** (int64|int32)-正确预测值的个数。 + - **total** (int64|int32)-总共的预测值。 -返回: 正确率 +返回: 计算出来的正确率。 -返回类型: 变量(Variable) +返回类型: Variable(Tensor),数据类型为float32的Tensor **代码示例** .. code-block:: python import paddle.fluid as fluid - data = fluid.layers.data(name="data", shape=[-1, 32, 32], dtype="float32") - label = fluid.layers.data(name="label", shape=[-1,1], dtype="int32") - predict = fluid.layers.fc(input=data, size=10) - accuracy_out = fluid.layers.accuracy(input=predict, label=label, k=5) - - - - - - - - - - - - + import numpy as np + + data = fluid.layers.data(name="input", shape=[-1, 32, 32], dtype="float32") + label = fluid.layers.data(name="label", shape=[-1,1], dtype="int") + fc_out = fluid.layers.fc(input=data, size=10) + predict = fluid.layers.softmax(input=fc_out) + result = fluid.layers.accuracy(input=predict, label=label, k=5) + + place = fluid.CPUPlace() + exe = fluid.Executor(place) + + exe.run(fluid.default_startup_program()) + x = np.random.rand(3, 32, 32).astype("float32") + y = np.array([[1],[0],[1]]) + output= exe.run(feed={"input": x,"label": y}, + fetch_list=[result[0]]) + print(output) + + """ + Output: + [array([0.6666667], dtype=float32)] + """ \ No newline at end of file diff --git a/doc/fluid/api_cn/layers_cn/auc_cn.rst b/doc/fluid/api_cn/layers_cn/auc_cn.rst old mode 100644 new mode 100755 index 076b684fe..f276b1290 --- a/doc/fluid/api_cn/layers_cn/auc_cn.rst +++ b/doc/fluid/api_cn/layers_cn/auc_cn.rst @@ -3,7 +3,7 @@ auc ------------------------------- -.. py:function:: paddle.fluid.layers.auc(input, label, curve='ROC', num_thresholds=4095, topk=1, slide_steps=1) +.. py:function:: paddle.fluid.layers.auc(input, label, curve='ROC', num_thresholds=200, topk=1, slide_steps=1) **Area Under the Curve(AUC) Layer** @@ -18,32 +18,49 @@ auc 2. PR:准确率召回率曲线 参数: - - **input** (Variable) - 浮点二维变量,值的范围为[0,1]。每一行降序排列。输入应为topk的输出。该变量显示了每个标签的概率。 - - **label** (Variable) - 二维整型变量,表示训练数据的标注。批尺寸的高度和宽度始终为1. + - **input** (Tensor|LoDTensor) - 数据类型为float32,float64。浮点二维变量,值的范围为[0,1]。每一行降序排列。该输入为网络预测值的输入。 + - **label** (Tensor|LoDTensor) - 数据类型为int32,int64。二维整型变量,为训练数据的标签。 - **curve** (str) - 曲线类型,可以为 ``ROC`` 或 ``PR``,默认 ``ROC``。 - - **num_thresholds** (int) - 将roc曲线离散化时使用的临界值数。默认200 - - **topk** (int) - 只有预测输出的topk数才被用于auc - - **slide_steps** - 计算批auc时,不仅用当前步也用先前步。slide_steps=1,表示用当前步;slide_steps = 3表示用当前步和前两步;slide_steps = 0,则用所有步 + - **num_thresholds** (int) - 将roc曲线离散化时使用的临界值数。默认200。 + - **topk** (int) - 取topk的输出值用于计算。 + - **slide_steps** (int) - 当计算batch auc时,不仅用当前步也用于先前步。slide_steps=1,表示用当前步;slide_steps = 3表示用当前步和前两步;slide_steps = 0,则用所有步。 -返回:代表当前AUC的一个元组 +返回:代表当前AUC的一个元组。 返回的元组为auc_out, batch_auc_out, [batch_stat_pos, batch_stat_neg, stat_pos, stat_neg]。 +auc_out为准确率的结果。 +batch_auc_out为batch准确率的结果。 +batch_stat_pos为batch计算时label=1的统计值 +batch_stat_neg为batch计算时label=0的统计值 +stat_pos计算时label=1的统计值 +stat_neg为计算时label=0的统计值 -返回类型:变量(Variable) +返回类型: Variable(Tensor),数据类型为float32或float64的Tensor。 **代码示例**: .. code-block:: python import paddle.fluid as fluid - data = fluid.layers.data(name="data", shape=[32, 32], dtype="float32") - label = fluid.layers.data(name="label", shape=[1], dtype="int32") - predict = fluid.layers.fc(input=data, size=2) - auc_out=fluid.layers.auc(input=predict, label=label) - - - - - - + import numpy as np + + data = fluid.layers.data(name="input", shape=[-1, 32,32], dtype="float32") + label = fluid.layers.data(name="label", shape=[1], dtype="int") + fc_out = fluid.layers.fc(input=data, size=2) + predict = fluid.layers.softmax(input=fc_out) + result=fluid.layers.auc(input=predict, label=label) + + place = fluid.CPUPlace() + exe = fluid.Executor(place) + + exe.run(fluid.default_startup_program()) + x = np.random.rand(3,32,32).astype("float32") + y = np.array([1,0,1]) + output= exe.run(feed={"input": x,"label": y}, + fetch_list=[result[0]]) + print(output) + """ + output: + [array([0.5])] + """ diff --git a/doc/fluid/api_cn/layers_cn/linear_chain_crf_cn.rst b/doc/fluid/api_cn/layers_cn/linear_chain_crf_cn.rst old mode 100644 new mode 100755 index beb594079..4e4c48e48 --- a/doc/fluid/api_cn/layers_cn/linear_chain_crf_cn.rst +++ b/doc/fluid/api_cn/layers_cn/linear_chain_crf_cn.rst @@ -3,7 +3,7 @@ linear_chain_crf ------------------------------- -.. py:function:: paddle.fluid.layers.linear_chain_crf(input, label, param_attr=None) +.. py:function:: paddle.fluid.layers.linear_chain_crf(input, label, param_attr=None, length=None) 线性链条件随机场(Linear Chain CRF) @@ -23,7 +23,7 @@ linear_chain_crf 其中Z是归一化值,所有可能序列的P(s)之和为1,x是线性链条件随机场(linear chain CRF)的发射(emission)特征权重。 -线性链条件随机场最终输出mini-batch每个训练样本的条件概率的对数 +线性链条件随机场最终输出每个batch训练样本的条件概率的对数 1.这里 :math:`x` 代表Emission @@ -48,41 +48,89 @@ linear_chain_crf 3.Emission的第二维度必须和标记数字(tag number)相同。 参数: - - **input** (Variable,LoDTensor,默认float类型LoDTensor) - 一个二维LoDTensor,shape为[N*D],N是mini-batch的大小,D是总标记数。线性链条件随机场的未缩放发射权重矩阵 - - **input** (Tensor,默认float类型LoDTensor) - 一个二维张量,shape为[(D+2)*D]。linear_chain_crf操作符的可学习参数。更多详情见operator注释 - - **label** (Variable,LoDTensor,默认int64类型LoDTensor) - shape为[N*10的LoDTensor,N是mini-batch的总元素数 - - **param_attr** (ParamAttr) - 可学习参数的属性 + - **input** (LoDTensor|Tensor) - 数据类型为float32, float64的Tensor或者LoDTensor。线性链条件随机场的发射矩阵emission。输入为LoDTensor时,是一个shape为[N*D]的2-D LoDTensor,N是每一个batch中batch对应的长度数想加的总数,D是维度。当输入为Tensor时,应该是一个shape为[N x S x D]的Tensor,N是batch_size,S为序列的最大长度,D是维度。 + - **label** (Tensor|LoDTensor) - 数据类型为int64类型Tensor或者LoDTensor。该值为标签值。输入为LoDTensor时[N x 1],N是mini-batch的总数;输入为Tensor时,[N x S],N为batch数量,S为序列的最大长度。 + - **Length** (Tensor) - 数据类型为int64类型的Tensor。 shape为[M x 1]的Tensor,M为mini_batch中序列的数量。 + - **param_attr** (ParamAttr) - 可学习参数的属性,为transition矩阵。详见代码示例。 返回: - output(Variable,Tensor,默认float类型Tensor):shape为[N*D]的二维张量。Emission的指数。这是前向计算中的中间计算结果,在后向计算中还会复用 + Emission的指数形式。shape与Emission相同。这是前向计算中的中间计算结果,在反向计算中还会复用。 - output(Variable,Tensor,默认float类型Tensor):shape为[(D+2)*D]的二维张量。Transition的指数。这是前向计算中的中间计算结果,在后向计算中还会复用 + Transition的指数形式。shape为[(D+2)*D]的二维张量。这是前向计算中的中间计算结果,在反向计算中还会复用。 - output(Variable,Tensor,默认float类型Tensor):mini-batch每个训练样本的条件概率的对数。这是一个shape为[S*1]的二维张量,S是mini-batch的序列数。注:S等同于mini-batch的序列数。输出不再是LoDTensor + 条件概率的对数形式。每个batch训练样本的条件概率的对数。这是一个shape为[S*1]的二维张量,S是mini-batch的序列数。注:S等于mini-batch的序列数。输出不再是LoDTensor。 + +返回类型: + Emission的指数形式。Variable(Tensor|LoDTensor):数据类型为float32, float64的Tensor或者LoDTensor。 + + Transition的指数形式。Variable(Tensor|LoDTensor):数据类型为float32, float64的Tensor或者LoDTensor。 + + 条件概率的对数形式。Variable(Tensor):数据类型为float32, float64的Tensor。 -返回类型:output(Variable) **代码示例:** .. code-block:: python import paddle.fluid as fluid - emission = fluid.layers.data(name='emission', shape=[1000], dtype='float32') - target = fluid.layers.data(name='target', shape=[1], dtype='int32') - crf_cost = fluid.layers.linear_chain_crf( - input=emission, - label=target, - param_attr=fluid.ParamAttr( + import numpy as np + + train_program = fluid.Program() + startup_program = fluid.Program() + with fluid.program_guard(train_program, startup_program): + input_data = fluid.layers.data(name='input_data', shape=[10], dtype='float32', lod_level=1) + label = fluid.layers.data(name='label', shape=[1], dtype='int', lod_level=1) + emission= fluid.layers.fc(input=input_data, size=10, act="tanh") + crf_cost = fluid.layers.linear_chain_crf( + input=emission, + label=label, + param_attr=fluid.ParamAttr( name='crfw', - learning_rate=0.2)) - - - - - - - - - - - + learning_rate=0.01)) + use_cuda = False + place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() + exe = fluid.Executor(place) + exe.run(startup_program) + #using LoDTensor, define network + a = fluid.create_lod_tensor(np.random.rand(12,10).astype('float32'), [[3,3,4,2]], place) + b = fluid.create_lod_tensor(np.array([[1],[1],[2],[3],[1],[1],[1],[3],[1],[1],[1],[1]]),[[3,3,4,2]] , place) + feed1 = {'input_data':a,'label':b} + loss= exe.run(train_program,feed=feed1, fetch_list=[crf_cost]) + print(loss) + + #using padding, define network + train_program = fluid.Program() + startup_program = fluid.Program() + with fluid.program_guard(train_program, startup_program): + input_data2 = fluid.layers.data(name='input_data2', shape=[10,10], dtype='float32') + label2 = fluid.layers.data(name='label2', shape=[10,1], dtype='int') + label_length = fluid.layers.data(name='length', shape=[1], dtype='int') + emission2= fluid.layers.fc(input=input_data2, size=10, act="tanh", num_flatten_dims=2) + crf_cost2 = fluid.layers.linear_chain_crf( + input=emission2, + label=label2, + length=label_length, + param_attr=fluid.ParamAttr( + name='crfw', + learning_rate=0.01)) + + use_cuda = False + place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() + exe = fluid.Executor(place) + exe.run(startup_program) + + #define input data + cc=np.random.rand(4,10,10).astype('float32') + dd=np.random.rand(4,10,1).astype('int64') + ll=np.array([[3,3,4,2]]) + feed2 = {'input_data2':cc,'label2':dd,'length':ll} + + loss2= exe.run(train_program,feed=feed2, fetch_list=[crf_cost2]) + print(loss2) + """ + output: + [array([[ 7.8902354], + [ 7.3602567], + [ 10.004011], + [ 5.86721 ]], dtype=float32)] + """ \ No newline at end of file diff --git a/doc/fluid/api_cn/layers_cn/sigmoid_cn.rst b/doc/fluid/api_cn/layers_cn/sigmoid_cn.rst old mode 100644 new mode 100755 index ac516da10..f510edc7e --- a/doc/fluid/api_cn/layers_cn/sigmoid_cn.rst +++ b/doc/fluid/api_cn/layers_cn/sigmoid_cn.rst @@ -11,22 +11,35 @@ sigmoid激活函数 out = \frac{1}{1 + e^{-x}} -参数: +参数: - - **x** - Sigmoid算子的输入 - - **use_cudnn** (BOOLEAN) – (bool,默认为false)是否仅用于cudnn核,需要安装cudnn + - **x** (Tensor|LoDTensor)- 数据类型为float32,float64。激活函数的输入值。 + - **name** (str|None) - 该层名称(可选)。若为空,则自动为该层命名。默认:None -返回: Sigmoid运算输出. +返回:激活函数的输出值 + +返回类型:Variable(Tensor),数据类型为float32的Tensor。 **代码示例**: .. code-block:: python import paddle.fluid as fluid - data = fluid.layers.data(name="input", shape=[32, 784]) - result = fluid.layers.sigmoid(data) - + import numpy as np + data = fluid.layers.data(name="input", shape=[-1, 3]) + result = fluid.layers.sigmoid(data) + place = fluid.CPUPlace() + exe = fluid.Executor(place) + exe.run(fluid.default_startup_program()) + x = np.random.rand(3, 3) + output= exe.run(feed={"input": x}, + fetch_list=[result[0]]) + print(output) + """ + output: + [array([0.50797188, 0.71353652, 0.5452265 ])] + """ diff --git a/doc/fluid/api_cn/layers_cn/smooth_l1_cn.rst b/doc/fluid/api_cn/layers_cn/smooth_l1_cn.rst old mode 100644 new mode 100755 index c2efa2489..522ccd607 --- a/doc/fluid/api_cn/layers_cn/smooth_l1_cn.rst +++ b/doc/fluid/api_cn/layers_cn/smooth_l1_cn.rst @@ -9,26 +9,39 @@ smooth_l1 参数: - - **x** (Variable) - rank至少为2的张量。输入x的smmoth L1 loss 的op,shape为[batch_size, dim1,…],dimN]。 - - **y** (Variable) - rank至少为2的张量。与 ``x`` 形状一致的的smooth L1 loss op目标值。 - - **inside_weight** (Variable|None) - rank至少为2的张量。这个输入是可选的,与x的形状应该相同。如果给定, ``(x - y)`` 的结果将乘以这个张量元素。 - - **outside_weight** (变量|None) - 一个rank至少为2的张量。这个输入是可选的,它的形状应该与 ``x`` 相同。如果给定,那么 smooth L1 loss 就会乘以这个张量元素。 - - **sigma** (float|None) - smooth L1 loss layer的超参数。标量,默认值为1.0。 + - **x** (Tensor|LoDTensor) - 数据类型为float32,rank至少为2的张量。smooth L1损失函数的输入,shape为[batch_size, dim1,…,dimN]。 + - **y** (Tensor|LoDTensor) - 数据类型为float32,rank至少为2的张量。与 ``x`` shape相同的目标值。 + - **inside_weight** (Tensor|None) - 数据类型为float32,rank至少为2的张量。这个输入是可选的,与x的shape应该相同。如果给定, ``(x - y)`` 的结果将乘以这个张量元素。 + - **outside_weight** (Tensor|None) - 数据类型为float32,一个rank至少为2的张量。这个输入是可选的,它的shape应该与 ``x`` 相同。 smooth L1 loss的输出会乘以这个张量。 + - **sigma** (float|NoneType) - smooth L1 loss layer的超参数。标量,默认值为1.0。 -返回: smooth L1 loss, shape为 [batch_size, 1] +返回: smooth L1损失的输出值, shape为 [batch_size, 1] -返回类型: Variable +返回类型:Variable(Tensor),数据类型为float32的Tensor。 **代码示例** .. code-block:: python - + import paddle.fluid as fluid - data = fluid.layers.data(name='data', shape=[128], dtype='float32') - label = fluid.layers.data( - name='label', shape=[100], dtype='float32') - fc = fluid.layers.fc(input=data, size=100) - out = fluid.layers.smooth_l1(x=fc, y=label) + import numpy as np + data = fluid.layers.data(name="x", shape=[-1, 3], dtype="float32") + label = fluid.layers.data(name="y", shape=[-1, 3], dtype="float32") + result = fluid.layers.smooth_l1(data,label) + place = fluid.CPUPlace() + exe = fluid.Executor(place) + exe.run(fluid.default_startup_program()) + x = np.random.rand(3,3).astype("float32") + y = np.random.rand(3,3).astype("float32") + output= exe.run(feed={"x":x, "y":y}, + fetch_list=[result]) + print(output) + """ + output: + [array([[0.08220536], + [0.36652038], + [0.20541131]], dtype=float32)] + """ diff --git a/doc/fluid/api_cn/layers_cn/softmax_cn.rst b/doc/fluid/api_cn/layers_cn/softmax_cn.rst old mode 100644 new mode 100755 index 24fb8061e..b9e708e21 --- a/doc/fluid/api_cn/layers_cn/softmax_cn.rst +++ b/doc/fluid/api_cn/layers_cn/softmax_cn.rst @@ -5,41 +5,50 @@ softmax .. py:function:: paddle.fluid.layers.softmax(input, use_cudnn=False, name=None, axis=-1) -softmax操作符的输入是任意阶的张量,输出张量和输入张量的维度相同。 +softmax输出张量和输入张量的维度相同。 -输入变量的 ``axis`` 维会被排列到最后一维。然后逻辑上将输入张量压平至二维矩阵。矩阵的第二维(行数)和输入张量的 ``axis`` 维相同。第一维(列数) -是输入张量除最后一维之外的所有维长度乘积。对矩阵的每一行来说,softmax操作将含有任意实数值的K维向量(K是矩阵的宽度,也就是输入张量 ``axis`` 维度的大小)压缩成K维含有取值为[0,1]中实数的向量,并且这些值和为1。 +输入变量的 ``axis`` 维会被排列到最后一维。在OP底层计算上将输入张量resize成二维矩阵。矩阵的第二维(行数)和输入张量的 ``axis`` 维相同。第一维(列数) +是输入张量除最后一维之外的所有维长度乘积。对矩阵的每一行来说,softmax函数将含有任意实数值的K维向量(K是矩阵的宽度,也就是输入张量 ``axis`` 维度的大小),resize成K维含有取值为[0,1]的向量,并且这些值和为1。 - -softmax操作符计算k维向量输入中所有其他维的指数和指数值的累加和。维的指数比例和所有其他维的指数值之和作为softmax操作符的输出。 +softmax函数计算k维向量输入中所有其他维的指数指数值的累加和。该维的指数比例和所有其他维的指数值之和作为softmax函数的输出。 对矩阵中的每行i和每列j有: .. math:: + Out[i,j] = \frac{exp(X[i,j])}{\sum_j exp(X[i,j])} 参数: - - **input** (Variable) - 输入变量 - - **use_cudnn** (bool) - 是否用cudnn核,只有在cudnn库安装时有效。为了数学稳定性,默认该项为False。 + - **input** (Tensor|LoDTensor)- 数据类型为float32,float64。激活函数softmax的输入。 + - **use_cudnn** (bool) - 是否使用cudnn,只有cudnn库安装时该参数才有效。为了底层数学计算的稳定性,默认该项为False。 - **name** (str|None) - 该层名称(可选)。若为空,则自动为该层命名。默认:None - - **axis** (int) - 执行softmax计算的维度索引,应该在 :math:`[-1,rank-1]` 范围内,其中rank是输入变量的秩。 默认值:-1。 + - **axis** (int) - 指定softmax计算的轴,应该在 :math:`[-1,rank-1]` 范围内,其中rank是输入变量的秩。 默认值:-1。-1为最后一维。 -返回: softmax输出 +返回: softmax函数的输出。 -返回类型:变量(Variable) +返回类型:Variable(Tensor),数据类型为float32或float64的Tensor。 **代码示例** .. code-block:: python import paddle.fluid as fluid - x = fluid.layers.data(name='x', shape=[2], dtype='float32') - fc = fluid.layers.fc(input=x, size=10) - # 在第二维执行softmax - softmax = fluid.layers.softmax(input=fc, axis=1) - # 在最后一维执行softmax - softmax = fluid.layers.softmax(input=fc, axis=-1) + import numpy as np + + data = fluid.layers.data(name="input", shape=[-1, 3],dtype="float32") + result = fluid.layers.softmax(data,axis=1) + place = fluid.CPUPlace() + exe = fluid.Executor(place) + exe.run(fluid.default_startup_program()) + x = np.random.rand(3, 3).astype("float32") + output= exe.run(feed={"input": x}, + fetch_list=[result[0]]) + print(output) + """ + output: + array([0.22595254, 0.39276356, 0.38128382], dtype=float32)] + """ diff --git a/doc/fluid/api_cn/layers_cn/stanh_cn.rst b/doc/fluid/api_cn/layers_cn/stanh_cn.rst index 9c051f25a..156c9058d 100644 --- a/doc/fluid/api_cn/layers_cn/stanh_cn.rst +++ b/doc/fluid/api_cn/layers_cn/stanh_cn.rst @@ -3,7 +3,7 @@ stanh ------------------------------- -.. py:function:: paddle.fluid.layers.stanh(x, scale_a=0.6666666666666666, scale_b=1.7159, name=None) +.. py:function:: paddle.fluid.layers.stanh(x, scale_a=0.67, scale_b=1.7159, name=None) STanh 激活算子(STanh Activation Operator.) @@ -11,26 +11,35 @@ STanh 激活算子(STanh Activation Operator.) \\out=b*\frac{e^{a*x}-e^{-a*x}}{e^{a*x}+e^{-a*x}}\\ 参数: - - **x** (Variable) - STanh operator的输入 - - **scale_a** (FLOAT|2.0 / 3.0) - 输入的a的缩放参数 - - **scale_b** (FLOAT|1.7159) - b的缩放参数 - - **name** (str|None) - 这个层的名称(可选)。如果设置为None,该层将被自动命名。 + - **x** (Tensor|LoDTensor) - 数据类型为float32,float64。STanh operator的输入 + - **scale_a** (float) - 输入的a的缩放参数 + - **scale_b** (float) - b的缩放参数 + - **name** (str|None) - 这个层的名称(可选)。如果设置为None,该层将被自动命名 -返回: STanh操作符的输出 +返回: 与输入shape相同的张量 -返回类型: 输出(Variable) +返回类型: Variable(Tensor),数据类型为float32的Tensor。 **代码示例:** .. code-block:: python import paddle.fluid as fluid - x = fluid.layers.data(name="x", shape=[3,10,32,32], dtype="float32") - y = fluid.layers.stanh(x, scale_a=0.67, scale_b=1.72) - - - - - + import numpy as np + data = fluid.layers.data(name="input", shape=[-1, 3]) + result = fluid.layers.stanh(data,scale_a=0.67, scale_b=1.72) + place = fluid.CPUPlace() + exe = fluid.Executor(place) + exe.run(fluid.default_startup_program()) + x = np.random.random(size=(3, 3)).astype('float32') + output= exe.run(feed={"input": x}, + fetch_list=[result]) + print(output) + """ + output: + [array([[0.626466 , 0.89842904, 0.7501062 ], + [0.25147712, 0.7484996 , 0.22902708], + [0.62705994, 0.23110689, 0.56902856]], dtype=float32)] + """ -- GitLab