335 Star 1.5K Fork 861

MindSpore / docs

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

比较与torch.nn.Hardshrink的差异

查看源文件

torch.nn.Hardshrink

torch.nn.Hardshrink(lambd=0.5)(input) -> Tensor

更多内容详见torch.nn.Hardshrink

mindspore.nn.HShrink

mindspore.nn.HShrink(lambd=0.5)(input_x) -> Tensor

更多内容详见mindspore.nn.HShrink

差异对比

PyTorch:激活函数,按输入元素计算输出。

MindSpore:MindSpore此API实现功能与PyTorch一致,仅参数名不同。

分类 子类 PyTorch MindSpore 差异
参数 参数1 lambd lambd -
输入 单输入 input input_x 功能一致,参数名不同

代码示例

两API功能一致,用法相同。

# PyTorch
import torch
import torch.nn as nn

m = nn.Hardshrink()
input = torch.tensor([[0.5, 1, 2.0], [0.0533, 0.0776, -2.1233]], dtype=torch.float32)
output = m(input)
output = output.detach().numpy()
print(output)
# [[ 0.      1.      2.    ]
#  [ 0.      0.     -2.1233]]

# MindSpore
import mindspore
from mindspore import Tensor, nn
import numpy as np

input_x = Tensor(np.array([[0.5, 1, 2.0], [0.0533, 0.0776, -2.1233]]), mindspore.float32)
hshrink = nn.HShrink()
output = hshrink(input_x)
print(output)
# [[ 0.      1.      2.    ]
#  [ 0.      0.     -2.1233]]
1
https://gitee.com/mindspore/docs.git
git@gitee.com:mindspore/docs.git
mindspore
docs
docs
master

搜索帮助