代码拉取完成,页面将自动刷新
class torch.nn.Softmax(dim=None)(input) -> Tensor
For more information, see [torch.nn.Softmax](https://pytorch.org/docs/1.8.1/generated/torch.nn.Softmax.html.
class mindspore.nn.Softmax(axis=-1)(x) -> Tensor
For more information, see mindspore.nn.Softmax.
PyTorch: a generalization of the binary classification function on multiclassification, which aims to present the results of multiclassification in the form of probabilities.
MindSpore: MindSpore API implements the same function as PyTorch, but the parameter names are different.
Categories | Subcategories | PyTorch | MindSpore | Difference |
---|---|---|---|---|
Parameters | Parameter 1 | dim | axis | Same function, different parameter names, different default values |
Input | Single input | input | x | Same function, different parameter names |
The two APIs achieve the same function and have the same usage.
# PyTorch
import torch
import numpy
from torch import tensor
import torch.nn as nn
x = torch.FloatTensor([1, 1])
softmax = nn.Softmax(dim=-1)(x)
print(softmax.numpy())
# [0.5 0.5]
# MindSpore
import mindspore
import numpy as np
from mindspore import Tensor
x = Tensor(np.array([1, 1]), mindspore.float16)
softmax = mindspore.nn.Softmax()
output = softmax(x)
print(output)
# [0.5 0.5]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。