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

相关推荐
龙腾AI白云9 小时前
具身智能的空间导航与未知环境探索
大数据·数据库·人工智能·机器学习·知识图谱
汤姆宝库12 小时前
RoPE旋转位置编码的实现与长上下文外推
python·深度学习·机器学习
tellmewhoisi13 小时前
深度学习0:数学知识:(L1正则化和L2正则化)
人工智能·深度学习
回眸&啤酒鸭14 小时前
【回眸】Hy4 模型效果展示与能力评测大纲
大数据·人工智能·机器学习
AI小怪兽14 小时前
你的视觉基础模型会说“植物语“吗?面向目标检测的视觉基础模型植物语法
人工智能·深度学习·机器学习
峯58014 小时前
机器学习05,用 scikit-learn 做加州房价预测的完整入门工程
人工智能·机器学习·scikit-learn
伞伞悦读14 小时前
【第86期】分类指标与错误成本对照的实验与排查
大数据·人工智能·机器学习
AI源码15 小时前
基于机器学习的优衣库销售预测与决策系统
人工智能·机器学习
罗西的思考1 天前
【轻量化复现大模型 / KIMI K3】MTP / EAGLE‑3 模块交互式演示
人工智能·深度学习·算法