hard_sigmoid¶
- paddle.fluid.layers.nn. hard_sigmoid ( x, slope=0.2, offset=0.5, name=None ) [source]
-
HardSigmoid Activation Operator.
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 + offset))\)
- Parameters
-
x (Variable) – An N-D Tensor with data type float32, float64.
slope (float, optional) – The slope of the linear approximation of sigmoid. Its value MUST BE positive. Default is 0.2.
offset (float, optional) – The offset of the linear approximation of sigmoid. Default is 0.5.
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 Name
- Returns
-
A Tensor with the same shape as input.
- Return type
-
Variable
Examples
import paddle.fluid as fluid import paddle paddle.enable_static() 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]]