335 Star 1.5K Fork 861

MindSpore / docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
leaky_relu.md 1.93 KB
一键复制 编辑 原始数据 按行查看 历史
TingWang 提交于 2023-09-18 10:08 . update link logo

比较与torch.nn.functional.leaky_relu的差异

查看源文件

torch.nn.functional.leaky_relu

torch.nn.functional.leaky_relu(input, negative_slope=0.01, inplace=False) -> Tensor

更多内容详见torch.nn.functional.leaky_relu

mindspore.ops.leaky_relu

mindspore.ops.leaky_relu(input, alpha=0.2) -> Tensor

更多内容详见mindspore.ops.leaky_relu

差异对比

PyTorch:leaky_relu激活函数。input 中小于0的元素乘以 negative_slope

MindSpore:MindSpore此API实现功能与PyTorch基本一致。不同的是,MindSpore中 alpha 的初始值是0.2,PyTorch中对应的 negative_slope 初始值是0.01。

分类 子类 PyTorch MindSpore 差异
参数 参数1 input input 一致
参数2 negative_slope alpha 功能一致,参数名不同,默认值不同
参数3 inplace - 是否对入参进行原地修改,MindSpore无此功能

代码示例

# PyTorch
import torch

input = torch.tensor([-2, -1, 0, 1, 2], dtype=torch.float32)
output = torch.nn.functional.leaky_relu(input, negative_slope=0.5, inplace=False)
print(output)
# tensor([-1.0000, -0.5000,  0.0000,  1.0000,  2.0000])

# MindSpore
import mindspore

input = mindspore.Tensor([-2, -1, 0, 1, 2], dtype=mindspore.float32)
output = mindspore.ops.leaky_relu(input, alpha=0.5)
print(output)
# [-1.  -0.5  0.   1.   2. ]
1
https://gitee.com/mindspore/docs.git
git@gitee.com:mindspore/docs.git
mindspore
docs
docs
master

搜索帮助