未验证 提交 209f684c 编写于 作者: 傅剑寒 提交者: GitHub

remove stanh in nn.py under fluid (#47889)

上级 3f480af2
...@@ -133,7 +133,6 @@ __all__ = [ ...@@ -133,7 +133,6 @@ __all__ = [
'crop_tensor', 'crop_tensor',
'relu6', 'relu6',
'pow', 'pow',
'stanh',
'hard_sigmoid', 'hard_sigmoid',
'swish', 'swish',
'prelu', 'prelu',
...@@ -9936,51 +9935,6 @@ def pow(x, factor=1.0, name=None): ...@@ -9936,51 +9935,6 @@ def pow(x, factor=1.0, name=None):
return out return out
@templatedoc()
def stanh(x, scale_a=0.67, scale_b=1.7159, name=None):
"""
stanh activation.
.. math::
out = b * \\frac{e^{a * x} - e^{-a * x}}{e^{a * x} + e^{-a * x}}
Parameters:
x (Tensor): The input Tensor with data type float32, float64.
scale_a (float, optional): The scale factor a of the input. Default is 0.67.
scale_b (float, optional): The scale factor b of the output. Default is 1.7159.
name (str, optional): Name for the operation (optional, default is None).
For more information, please refer to :ref:`api_guide_Name`.
Returns:
A Tensor with the same data type and shape as ``x`` .
Examples:
.. code-block:: python
import paddle
x = paddle.to_tensor([1.0, 2.0, 3.0, 4.0])
out = paddle.stanh(x, scale_a=0.67, scale_b=1.72) # [1.00616539, 1.49927628, 1.65933108, 1.70390463]
"""
if _non_static_mode():
return _legacy_C_ops.stanh(x, 'scale_a', scale_a, 'scale_b', scale_b)
check_variable_and_dtype(x, 'x', ['float16', 'float32', 'float64'], 'stanh')
helper = LayerHelper('stanh', **locals())
out = helper.create_variable_for_type_inference(dtype=x.dtype)
helper.append_op(
type='stanh',
inputs={'X': x},
outputs={'Out': out},
attrs={'scale_a': scale_a, 'scale_b': scale_b},
)
return out
@templatedoc() @templatedoc()
def hard_sigmoid(x, slope=0.2, offset=0.5, name=None): def hard_sigmoid(x, slope=0.2, offset=0.5, name=None):
""" """
......
...@@ -2989,7 +2989,7 @@ class TestSTanhAPI(unittest.TestCase): ...@@ -2989,7 +2989,7 @@ class TestSTanhAPI(unittest.TestCase):
paddle.enable_static() paddle.enable_static()
with fluid.program_guard(fluid.Program()): with fluid.program_guard(fluid.Program()):
x = fluid.data('X', [10, 12]) x = fluid.data('X', [10, 12])
out = fluid.layers.stanh(x, self.scale_a, self.scale_b) out = paddle.stanh(x, self.scale_a, self.scale_b)
exe = fluid.Executor(self.place) exe = fluid.Executor(self.place)
res = exe.run(feed={'X': self.x_np}, fetch_list=[out]) res = exe.run(feed={'X': self.x_np}, fetch_list=[out])
out_ref = ref_stanh(self.x_np, self.scale_a, self.scale_b) out_ref = ref_stanh(self.x_np, self.scale_a, self.scale_b)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册