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

相关推荐
月疯3 小时前
CNN卷积和反卷积输出的计算方法
深度学习·神经网络·cnn
能有时光4 小时前
PyTorch KernelAgent 源码解读 ---(4)--- ExtractorAgent
人工智能·pytorch·python
直接冲冲冲4 小时前
鱼书-PH4-类的作用
深度学习
EQUINOX17 小时前
【论文阅读】| MoCo精读
论文阅读·人工智能·python·深度学习·机器学习
程序喵大人8 小时前
【AI专栏】图解Transformer - 第05章:LLM 推理工程
人工智能·深度学习·llm·transformer
bing_feilong9 小时前
FAST_LIO2(2): 运行记录
机器学习·slam
Day(AKA Elin)10 小时前
【Day】MTP(Multi Token Prediction)技术学习
python·深度学习·学习·llama
卡梅德生物科技小能手10 小时前
卡美德生物科普IL25:2型免疫反应的核心调控靶点
经验分享·深度学习·生活
城事漫游Molly10 小时前
用AI提炼研究问题与假设的完整提示词——从模糊想法到精准RQ/Hypothesis,AI辅助精化全流程
人工智能·机器学习·prompt·ai for science·博士生必读·应用语言学·研究问题
workflower10 小时前
室内外配送机器人-应用路径
人工智能·机器学习·设计模式·矩阵·自动化