未验证 提交 65d4ff75 编写于 作者: Z zhupengyang 提交者: GitHub

hardsigmoid add attr slope and offset (#29999)

上级 c053bf2a
...@@ -252,7 +252,7 @@ def hardtanh(x, min=-1.0, max=1.0, name=None): ...@@ -252,7 +252,7 @@ def hardtanh(x, min=-1.0, max=1.0, name=None):
return out return out
def hardsigmoid(x, name=None): def hardsigmoid(x, slope=0.1666667, offset=0.5, name=None):
r""" r"""
hardsigmoid activation. hardsigmoid activation.
...@@ -266,12 +266,14 @@ def hardsigmoid(x, name=None): ...@@ -266,12 +266,14 @@ def hardsigmoid(x, name=None):
\\begin{aligned} \\begin{aligned}
&0, & & \\text{if } x \\leq -3 \\\\ &0, & & \\text{if } x \\leq -3 \\\\
&1, & & \\text{if } x \\geq 3 \\\\ &1, & & \\text{if } x \\geq 3 \\\\
&x/6 + 1/2, & & \\text{otherwise} &slope * x + offset, & & \\text{otherwise}
\\end{aligned} \\end{aligned}
\\right. \\right.
Parameters: Parameters:
x (Tensor): The input Tensor with data type float32, float64. x (Tensor): The input Tensor with data type float32, float64.
slope (float, optional): The slope of hardsigmoid function. Default is 0.1666667.
offset (float, optional): The offset of hardsigmoid function. Default is 0.5.
name (str, optional): Name for the operation (optional, default is None). name (str, optional): Name for the operation (optional, default is None).
For more information, please refer to :ref:`api_guide_Name`. For more information, please refer to :ref:`api_guide_Name`.
...@@ -289,8 +291,7 @@ def hardsigmoid(x, name=None): ...@@ -289,8 +291,7 @@ def hardsigmoid(x, name=None):
""" """
if in_dygraph_mode(): if in_dygraph_mode():
return core.ops.hard_sigmoid(x, 'slope', 0.1666666666666667, 'offset', return core.ops.hard_sigmoid(x, 'slope', slope, 'offset', offset)
0.5)
check_variable_and_dtype(x, 'x', ['float16', 'float32', 'float64'], check_variable_and_dtype(x, 'x', ['float16', 'float32', 'float64'],
'hardsigmoid') 'hardsigmoid')
...@@ -301,8 +302,8 @@ def hardsigmoid(x, name=None): ...@@ -301,8 +302,8 @@ def hardsigmoid(x, name=None):
type='hard_sigmoid', type='hard_sigmoid',
inputs={'X': x}, inputs={'X': x},
outputs={'Out': out}, outputs={'Out': out},
attrs={'slope': 0.1666666666666667, attrs={'slope': slope,
'offset': 0.5}) 'offset': offset})
return out return out
......
...@@ -611,7 +611,7 @@ class Hardsigmoid(layers.Layer): ...@@ -611,7 +611,7 @@ class Hardsigmoid(layers.Layer):
self.name = name self.name = name
def forward(self, x): def forward(self, x):
return F.hardsigmoid(x, self.name) return F.hardsigmoid(x, name=self.name)
class Softplus(layers.Layer): class Softplus(layers.Layer):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册