diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index d81e513f49170d32fd65000535918d49938380f6..a2dc5d2c157f286ec7115cf05653a3ab18da681e 100644 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -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.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.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.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')) diff --git a/paddle/fluid/operators/activation_op.cc b/paddle/fluid/operators/activation_op.cc index 5b1bc9f4193950be91b697875ae3ca7460a588d3..150ce231ec90b28c11496191f773eee037049d52 100644 --- a/paddle/fluid/operators/activation_op.cc +++ b/paddle/fluid/operators/activation_op.cc @@ -572,23 +572,23 @@ class ThresholdedReluOpMaker : public framework::OpProtoAndCheckerMaker { class HardSigmoidOpMaker : public framework::OpProtoAndCheckerMaker { public: void Make() override { - AddInput("X", "Input of HardSigmoid operator"); - AddOutput("Out", "Output of HardSigmoid operator"); - AddAttr("slope", "Slope for linear approximation of sigmoid") + AddInput("X", "An N-D Tensor with data type float32, float64. "); + AddOutput("Out", "A Tensor with the same shape as input. "); + AddAttr("slope", + "The slope of the linear approximation of sigmoid. Its " + "value MUST BE positive. Default is 0.2. ") .SetDefault(0.2f); - AddAttr("offset", "Offset for linear approximation of sigmoid") + AddAttr( + "offset", + "The offset of the linear approximation of sigmoid. Default is 0.5. ") .SetDefault(0.5f); AddComment(R"DOC( 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. -$out = \max(0, \min(1, slope * x + shift))$ - -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. +$out = \max(0, \min(1, slope * x + offset))$ )DOC"); } diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 3d95a76fa345c55eee713bea6036b630d52468e2..001a186d7a75bf14eee410a8a59fd3355d5f9ab0 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -11751,23 +11751,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): """ ${comment} - Args: - x(${x_type}): ${x_comment} - slope(${slope_type}|0.2): ${slope_comment} - offset(${offset_type}|0.5): ${offset_comment} - name(str|None): A name for this layer(optional). If set None, the layer - will be named automatically. + Parameters: + x (${x_type}): ${x_comment} + slope (float, optional): ${slope_comment} + offset (float, optional): ${offset_comment} + name (str, optional): The default value is None. Normally there is no + need for user to set this property. For more information, please + refer to :ref:`api_guide_Name` Returns: - output(${out_type}): ${out_comment} + ${out_type}: ${out_comment} Examples: .. code-block:: python import paddle.fluid as fluid - x = fluid.layers.data(name="x", shape=[3,10,32,32], dtype="float32") - y = fluid.layers.hard_sigmoid(x, slope=0.3, offset=0.8) + 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]] + result = fluid.layers.hard_sigmoid(data) # [[0.6, 0.6], [0.6, 0.6], [0.6, 0.6]] """ helper = LayerHelper('hard_sigmoid', **locals()) out = helper.create_variable_for_type_inference(dtype=x.dtype)