335 Star 1.5K Fork 861

MindSpore / docs

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

比较与torch.nn.Softmax的差异

查看源文件

torch.nn.Softmax

class torch.nn.Softmax(dim=None)(input) -> Tensor

更多内容详见torch.nn.Softmax

mindspore.nn.Softmax

class mindspore.nn.Softmax(axis=-1)(x) -> Tensor

更多内容详见mindspore.nn.Softmax

差异对比

PyTorch:它是二分类函数在多分类上的推广,目的是将多分类的结果以概率的形式展现出来。

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

分类 子类 PyTorch MindSpore 差异
参数 参数1 dim axis 功能一致,参数名不同,默认值不同
输入 单输入 input x 功能一致,参数名不同

代码示例

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

# 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]
1
https://gitee.com/mindspore/docs.git
git@gitee.com:mindspore/docs.git
mindspore
docs
docs
master

搜索帮助