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

相关推荐
小飞猪。。35 分钟前
笔记十四:从零开始搞懂 DPO——大模型偏好对齐的“直球”方案
人工智能·深度学习·机器学习
mingo_敏8 小时前
DeepAgents : 权限(Permissions)
人工智能·深度学习·langchain
江畔柳前堤8 小时前
信号的本质——从模拟波形到AI中的数据张量
人工智能·深度学习·机器学习·计算机视觉·数据挖掘·语音识别
HyperAI超神经9 小时前
15亿参数挑战机器人控制,MiniCPM-RobotManip正式开源;覆盖文本/图/视频/动作序列,英伟达发布全模态模型Cosmos3-Edge
人工智能·深度学习·机器人·多模态·图像生成·具身智能·智能体
江畔柳前堤10 小时前
系统的本质——从LTI系统到神经网络
人工智能·深度学习·神经网络·机器学习·计算机视觉·数据挖掘·语音识别
databook12 小时前
用相关性分析消除“冗余特征”
python·机器学习·scikit-learn
SomeB1oody12 小时前
【RustyML入门】1.0. 快速上手
开发语言·后端·机器学习·rust·教程
sponge'14 小时前
《以场景为中心的无监督视频全景分割》论文框架讲解
人工智能·深度学习
布鲁飞丝14 小时前
彩笔运维勇闯机器学习--cpu与qps的线性关系
运维·人工智能·机器学习
2501_9269783314 小时前
提示工程的实战报告(二):模型的失败模式与边界行为
人工智能·深度学习·算法