未验证 提交 41d5c029 编写于 作者: H hong19860320 提交者: GitHub

[cherry-pick] refine eng doc for hard_sigmoid op (#20442) (#20543)

test=develop, test=release/1.6, test=document_fix

* refine eng doc for hard_sigmoid op
test=develop
test=document_fix

* refine the description of hard_sigmoid
 test=develop
test=document_fix

* update API.spec
test=document_fix

* Refine the decription of parameters of HardSigmoid op
test=develop, test=document_fix

* Update API.spec for hard_sigmoid op
test=develop, test=document_fix
上级 27a9d97c
...@@ -227,7 +227,7 @@ paddle.fluid.layers.elu (ArgSpec(args=['x', 'alpha', 'name'], varargs=None, keyw ...@@ -227,7 +227,7 @@ paddle.fluid.layers.elu (ArgSpec(args=['x', 'alpha', 'name'], varargs=None, keyw
paddle.fluid.layers.relu6 (ArgSpec(args=['x', 'threshold', 'name'], varargs=None, keywords=None, defaults=(6.0, None)), ('document', '56d3bb2e38cd4de769267c0ace5bbac2')) paddle.fluid.layers.relu6 (ArgSpec(args=['x', 'threshold', 'name'], varargs=None, keywords=None, defaults=(6.0, None)), ('document', '56d3bb2e38cd4de769267c0ace5bbac2'))
paddle.fluid.layers.pow (ArgSpec(args=['x', 'factor', 'name'], varargs=None, keywords=None, defaults=(1.0, None)), ('document', '00d437d1e0d9450ea75a0495b93b54a7')) paddle.fluid.layers.pow (ArgSpec(args=['x', 'factor', 'name'], varargs=None, keywords=None, defaults=(1.0, None)), ('document', '00d437d1e0d9450ea75a0495b93b54a7'))
paddle.fluid.layers.stanh (ArgSpec(args=['x', 'scale_a', 'scale_b', 'name'], varargs=None, keywords=None, defaults=(0.67, 1.7159, None)), ('document', 'd3f742178a7263adf5929153d104883d')) paddle.fluid.layers.stanh (ArgSpec(args=['x', 'scale_a', 'scale_b', 'name'], varargs=None, keywords=None, defaults=(0.67, 1.7159, None)), ('document', 'd3f742178a7263adf5929153d104883d'))
paddle.fluid.layers.hard_sigmoid (ArgSpec(args=['x', 'slope', 'offset', 'name'], varargs=None, keywords=None, defaults=(0.2, 0.5, None)), ('document', '607d79ca873bee40eed1c79a96611591')) paddle.fluid.layers.hard_sigmoid (ArgSpec(args=['x', 'slope', 'offset', 'name'], varargs=None, keywords=None, defaults=(0.2, 0.5, None)), ('document', '361e179a0b446ffce90176fae60545d6'))
paddle.fluid.layers.swish (ArgSpec(args=['x', 'beta', 'name'], varargs=None, keywords=None, defaults=(1.0, None)), ('document', '60b4dbe35f2b47f7290e79907a4eacec')) paddle.fluid.layers.swish (ArgSpec(args=['x', 'beta', 'name'], varargs=None, keywords=None, defaults=(1.0, None)), ('document', '60b4dbe35f2b47f7290e79907a4eacec'))
paddle.fluid.layers.prelu (ArgSpec(args=['x', 'mode', 'param_attr', 'name'], varargs=None, keywords=None, defaults=(None, None)), ('document', 'cb417a61f701c937f33d057fe85203ab')) paddle.fluid.layers.prelu (ArgSpec(args=['x', 'mode', 'param_attr', 'name'], varargs=None, keywords=None, defaults=(None, None)), ('document', 'cb417a61f701c937f33d057fe85203ab'))
paddle.fluid.layers.brelu (ArgSpec(args=['x', 't_min', 't_max', 'name'], varargs=None, keywords=None, defaults=(0.0, 24.0, None)), ('document', '35db66985af04bf6a91601aa4f73b54f')) paddle.fluid.layers.brelu (ArgSpec(args=['x', 't_min', 't_max', 'name'], varargs=None, keywords=None, defaults=(0.0, 24.0, None)), ('document', '35db66985af04bf6a91601aa4f73b54f'))
......
...@@ -572,23 +572,23 @@ class ThresholdedReluOpMaker : public framework::OpProtoAndCheckerMaker { ...@@ -572,23 +572,23 @@ class ThresholdedReluOpMaker : public framework::OpProtoAndCheckerMaker {
class HardSigmoidOpMaker : public framework::OpProtoAndCheckerMaker { class HardSigmoidOpMaker : public framework::OpProtoAndCheckerMaker {
public: public:
void Make() override { void Make() override {
AddInput("X", "Input of HardSigmoid operator"); AddInput("X", "An N-D Tensor with data type float32, float64. ");
AddOutput("Out", "Output of HardSigmoid operator"); AddOutput("Out", "A Tensor with the same shape as input. ");
AddAttr<float>("slope", "Slope for linear approximation of sigmoid") AddAttr<float>("slope",
"The slope of the linear approximation of sigmoid. Its "
"value MUST BE positive. Default is 0.2. ")
.SetDefault(0.2f); .SetDefault(0.2f);
AddAttr<float>("offset", "Offset for linear approximation of sigmoid") AddAttr<float>(
"offset",
"The offset of the linear approximation of sigmoid. Default is 0.5. ")
.SetDefault(0.5f); .SetDefault(0.5f);
AddComment(R"DOC( AddComment(R"DOC(
HardSigmoid Activation Operator. HardSigmoid Activation Operator.
Segment-wise linear approximation of sigmoid(https://arxiv.org/abs/1603.00391), A 3-part piecewise linear approximation of sigmoid(https://arxiv.org/abs/1603.00391),
which is much faster than sigmoid. which is much faster than sigmoid.
$out = \max(0, \min(1, slope * x + shift))$ $out = \max(0, \min(1, slope * x + offset))$
The slope should be positive. The offset can be either positive or negative.
The default slope and shift are set according to the above reference.
It is recommended to use the defaults for this activation.
)DOC"); )DOC");
} }
......
...@@ -11777,23 +11777,24 @@ def stanh(x, scale_a=0.67, scale_b=1.7159, name=None): ...@@ -11777,23 +11777,24 @@ def stanh(x, scale_a=0.67, scale_b=1.7159, name=None):
def hard_sigmoid(x, slope=0.2, offset=0.5, name=None): def hard_sigmoid(x, slope=0.2, offset=0.5, name=None):
""" """
${comment} ${comment}
Args: Parameters:
x(${x_type}): ${x_comment} x (${x_type}): ${x_comment}
slope(${slope_type}|0.2): ${slope_comment} slope (float, optional): ${slope_comment}
offset(${offset_type}|0.5): ${offset_comment} offset (float, optional): ${offset_comment}
name(str|None): A name for this layer(optional). If set None, the layer name (str, optional): The default value is None. Normally there is no
will be named automatically. need for user to set this property. For more information, please
refer to :ref:`api_guide_Name`
Returns: Returns:
output(${out_type}): ${out_comment} ${out_type}: ${out_comment}
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle.fluid as fluid
x = fluid.layers.data(name="x", shape=[3,10,32,32], dtype="float32") data = fluid.layers.fill_constant(shape=[3, 2], value=0.5, dtype='float32') # [[0.5, 0.5], [0.5, 0.5], [0.5, 0.5]]
y = fluid.layers.hard_sigmoid(x, slope=0.3, offset=0.8) result = fluid.layers.hard_sigmoid(data) # [[0.6, 0.6], [0.6, 0.6], [0.6, 0.6]]
""" """
helper = LayerHelper('hard_sigmoid', **locals()) helper = LayerHelper('hard_sigmoid', **locals())
out = helper.create_variable_for_type_inference(dtype=x.dtype) out = helper.create_variable_for_type_inference(dtype=x.dtype)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册