leaky_relu

paddle.sparse.nn.functional. leaky_relu ( x, negative_slope=0.01, name=None ) [源代码]

稀疏 leaky_relu 激活函数,要求 输入 xSparseCooTensorSparseCsrTensor

\[\begin{split}leaky_relu(x)= \left\{ \begin{array}{rcl} x, & & if \ x >= 0 \\ negative\_slope * x, & & otherwise \\ \end{array} \right.\end{split}\]

其中,\(x\) 为输入的 Tensor。

参数

  • x (Tensor) - 输入的稀疏 Tensor,可以是 SparseCooTensor 或 SparseCsrTensor,数据类型为 float32、float64。

  • negative_slope (float,可选) - \(x < 0\) 时的斜率。默认值为 0.01。

  • name (str,可选) - 具体用法请参见 Name,一般无需设置,默认值为 None。

返回

多维稀疏 Tensor, 数据类型和稀疏格式与 x 相同。

代码示例

>>> import paddle

>>> dense_x = paddle.to_tensor([-2., 0., 5.])
>>> sparse_x = dense_x.to_sparse_coo(1)
>>> out = paddle.sparse.nn.functional.leaky_relu(sparse_x, 0.5)