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)

参考内容

1\]torch.nn.functional.softmax https://pytorch.org/docs/2.6/generated/torch.nn.functional.softmax.html#torch.nn.functional.softmax \[2\]torch.nn.Softmax https://pytorch.org/docs/stable/generated/torch.nn.Softmax.html

相关推荐
James. 常德 student17 分钟前
深度学习之自动求导
人工智能·深度学习
船长@Quant29 分钟前
PyTorch量化技术教程:第三章 PyTorch模型构建与训练
pytorch·python·深度学习·机器学习·量化交易·ta-lib
神经星星32 分钟前
新加坡国立大学张阳团队开发第二代RNA结构预测算法,多项基准测试超越SOTA
人工智能·深度学习·机器学习
_painter1 小时前
【深度学习的数学】导数
人工智能·深度学习
Ronin-Lotus9 小时前
深度学习篇---卷积网络结构
人工智能·python·深度学习·cnn
机械心10 小时前
自动驾驶VLA模型技术解析与模型设计
人工智能·机器学习·自动驾驶·vla·端到端自动驾驶
Fansv58711 小时前
深度学习框架PyTorch——从入门到精通(10)PyTorch张量简介
人工智能·pytorch·经验分享·python·深度学习·机器学习
冰蓝蓝11 小时前
Pytorch :维度转化
人工智能·pytorch·python
Flash Bomb42212 小时前
自然语言处理(11:RNN(RNN的前置知识和引入)
人工智能·rnn·深度学习·神经网络·自然语言处理
赛卡13 小时前
“自动驾驶背后的数学” 专栏导读
人工智能·pytorch·python·学习·机器学习·自动驾驶·numpy