当前位置: 首页 > article >正文

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

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

例:

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


http://www.kler.cn/a/600337.html

相关文章:

  • 探索Google Test(gtest):C++单元测试的强大工具
  • ES聚合学习(三)
  • 常见CMS漏洞(一):WordPress
  • 【中间件】Rabbit离线部署操作
  • 初识R语言饼状图
  • 使用 langchain_deepseek 实现自然语言转数据库查询SQL
  • PRC框架(以Dubbo为例),分布式事务解决方案
  • Debug-037-table列表勾选回显方案
  • 网络爬虫-4:jsonpath+实战
  • epoll:Linux 高性能 I/O 多路复用技术
  • 计算机工具基础(七)——Git
  • SpringBootAdmin-clinet自定义监控CPU、内存、磁盘等health
  • 【web3】
  • GB 18401《国家纺织产品基本安全技术规范》
  • unity动效扫光教程
  • 20250317-vue-Prop4
  • 常见中间件漏洞攻略-Tomcat篇
  • 【Android Studio开发】生命周期、Activity和组件通信(上)
  • JavaScript实现一个函数,找出两个数组的交集(共同元素)的原理及思路。
  • 项目总结:GetX + Kotlin 协程实现(依赖注入补充)