当前位置:网站首页>The difference between torch.nn and torch.nn.functional in pytorch
The difference between torch.nn and torch.nn.functional in pytorch
2022-07-26 14:45:00 【The way of code】
torch.nn
pytorch Chinese document links :torch.nn
stay __init__() The function defines , It defines a class :
torch.nn.functional
pytorch Chinese document links :torch.nn.functional
stay __forward()__ The function defines , What is defined is a function :
The difference between the two
torch.nn Is a defined class , With class xx To define the , You can extract varying learning parameters .
torch.nn.functional It's a function , from def function( ) Definition , Is a fixed formula .
In the deep learning, there will be many weights that are constantly updated , So we need to adopt the method of class , To ensure that we can still use the operation steps we set before when the parameters change . So if the model has learnable parameters , You should use nn.Module, Otherwise there is no difference between the two . But simple calculation does not need to create a new class to do , So use nn.functional Define a function .
namely : Within the layer variable For nn Definition , Otherwise, use nn.functional Definition .
Learn more about programming , Please pay attention to my official account :

边栏推荐
- C # use shift > > and operation and & to judge whether the two binary numbers have changed
- SiamRPN++:深层网络连体视觉跟踪的演变
- 保证接口数据安全的10种方案
- Annotation and reflection
- Maya imports the model into unity
- 14. Bridge-Based Active Domain Adaptation for Aspect Term Extraction 阅读笔记
- Siamrpn++: evolution of deep network connected visual tracking
- 基于CAS的SSO单点服务端配置
- TransC知识表示模型
- WPF common function integration
猜你喜欢

Flask send_ Absolute path traversal caused by file function
![[ostep] 04 virtualized CPU - process scheduling strategy](/img/42/7ffb9745ef21a8db35861119dd70bf.png)
[ostep] 04 virtualized CPU - process scheduling strategy

OpenCV中图像算术操作与逻辑操作

Wechat applet - "do you really understand the use of applet components?
![[1.2. return and risk of investment]](/img/61/0135c429225e1c18705749a20e2a96.png)
[1.2. return and risk of investment]

Arithmetic operation and logic operation of image in opencv

Use of LINGO software

Seata的部署与微服务集成

VP视频结构化框架

Mlx90640 infrared thermal imager temperature sensor module development notes (6)
随机推荐
Keyboard shortcut to operate the computer (I won't encounter it myself)
Annotation and reflection
win10安装Dexdump并脱壳
Stacked noise reducing auto encoder (sdae)
【愚公系列】2022年7月 Go教学课程 017-分支结构之IF
保证接口数据安全的10种方案
[ostep] 03 virtualized CPU - restricted direct execution mechanism
Summary of target tracking related knowledge
[integer programming]
TDengine 助力西门子轻量级数字化解决方案 SIMICAS 简化数据处理流程
VP视频结构化框架
Multithreading - thread pool
c# 用移位 >> 和运算与 &判断两个 二进制数 是否发生过改变
JS wave animation effect menu style
填问卷,领奖品 | 诚邀您填写 Google Play Academy 活动调研问卷
[ostep] 04 virtualized CPU - process scheduling strategy
Tdengine helps Siemens' lightweight digital solution simicas simplify data processing process
中值滤波器
Mysql-03 database operation
SSH that must be read on cloud native