torch.nn和torch.nn.function的区别

torch.nn一般作为class提供,需要实例化后使用

torch.nn.functional一般作为函数提供,无需实例化可直接使用

例:

python 复制代码
import torch
import torch.nn.functional as F

x = torch.tensor([[1,2,3], [1,2,3], [1,2,3], [1,2,3]], dtype = torch.double)
nn_softmax = torch.nn.Softmax(dim=0)

out_nn = nn_softmax(x)
out_F = F.softmax(x, dim=0)

参考内容

1torch.nn.functional.softmax

https://pytorch.org/docs/2.6/generated/torch.nn.functional.softmax.html#torch.nn.functional.softmax

2torch.nn.Softmax

https://pytorch.org/docs/stable/generated/torch.nn.Softmax.html

相关推荐
不可求~36 分钟前
用 AI 读论文别只看摘要:建立可追溯的证据链
人工智能·深度学习·机器学习
今天AI了吗1 小时前
Python 基础语法(一):常量、变量、输入输出与运算符
开发语言·数据库·人工智能·python·sql·深度学习·机器学习
空堂与归1 小时前
用户分群找不到规律?用K-Means聚类算法自动发现数据模式
算法·机器学习·kmeans·聚类
wen_zhufeng5 小时前
IndexTTS 2.5 技术报告
人工智能·算法·机器学习
CODER03046 小时前
Anaconda和Mamba创建环境管理包常用命令合集
python·深度学习·conda·虚拟环境·mamba·常用命令大全
FL16238631299 小时前
人员聚集人群拥挤密度检测数据集VOC+YOLO格式163张2类别
人工智能·yolo·机器学习
智购科技自动售货机厂家9 小时前
2026自动售货机AI视觉识别优化:从YOLOv11n模型量化到RKNN部署的端侧推理工程实践~YH
javascript·人工智能·yolo·机器学习·计算机视觉·目标跟踪·perl
Tasiorh10 小时前
《随机森林》知识点总结
算法·随机森林·机器学习
pjj1985411 小时前
机器学习-NumPy2
人工智能·python·机器学习
AR-26710-12 小时前
机器学习复习Day1——线性回归编程作业
人工智能·机器学习