代码拉取完成,页面将自动刷新
torch.nn.Hardshrink(lambd=0.5)(input) -> Tensor
For more information, see torch.nn.Hardshrink.
mindspore.nn.HShrink(lambd=0.5)(input_x) -> Tensor
For more information, see mindspore.nn.HShrink.
PyTorch: Activation function, and calculate the output by the input elements.
MindSpore: MindSpore API implements the same function as PyTorch, and only the parameter names are different.
Categories | Subcategories | PyTorch | MindSpore | Difference |
---|---|---|---|---|
Parameter | Parameter 1 | lambd | lambd | - |
Input | Single input | input | input_x | Same function, different parameter names |
The two APIs achieve the same function and have the same usage.
# 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]]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。