当前位置:网站首页>Pytorch学习笔记--常用函数总结3
Pytorch学习笔记--常用函数总结3
2022-07-25 15:28:00 【whut_L】
1--torch.optim.SGD()函数拓展
import torch
LEARNING_RATE = 0.01 # 梯度下降学习率
MOMENTUM = 0.9 # 冲量大小
WEIGHT_DECAY = 0.0005 # 权重衰减系数
optimizer = torch.optim.SGD(
net.parameters(),
lr = LEARNING_RATE,
momentum = MOMENTUM,
weight_decay = WEIGHT_DECAY,
nesterov = True
)参数解释:lr表示学习率;momentum表示冲量因子;weight_decay表示权重衰减系数(将使用L2正则项);nesterov表示使用Nesterov冲量;
常规梯度下降算法:

l表示学习率; J(θ)表示损失函数;▽表示求梯度;
带momentum的梯度下降算法:

m表示冲量因子,l表示学习率;
基于Nesterov冲量的梯度下降算法:

带weight_decay的梯度下降算法:
主要作用是对损失函数增加L2正则项,强烈建议通过参考链接1了解L2正则化的作用,即如何避免过拟合,权重衰减通过参考链接2理解。
2--torch.manual_seed()函数和torch.cuda.manual_seed()函数
torch.manual_seed()函数:为CPU设置种子,确保每次实验生成的随机数固定,即初始化相同;
torch.cuda.manual_seed()函数:为当前GPU设置种子,作用与torch.manual_seed()函数相同;
torch.cuda.manual_seed_all()函数:为所有GPU设置种子。
在神经网络中,参数默认是进行随机初始化的。不同的初始化参数往往会导致不同的结果,当获得较好结果时我们通常希望这个结果是可以复现的。在pytorch中,通过设置随机数种子确保每次代码运行时初始化操作都相同,从而在相同的算法或神经网络程序中,确保运行的结果也相同。参考链接1参考链接2
边栏推荐
- Spark SQL UDF function
- Run redis on docker to start in the form of configuration file, and the connection client reports an error: server closed the connection
- The development summary of the function of fast playback of audio and video in any format on the web page.
- MySQL transactions and mvcc
- 2016CCPC网络选拔赛C-换根dp好题
- 分布式 | 实战:将业务从 MyCAT 平滑迁移到 dble
- Spark memory management mechanism new version
- 2019陕西省省赛K-变种Dijstra
- The difference between Apple buy in and apple pay
- Reflection - Notes
猜你喜欢

ML - 自然语言处理 - 自然语言处理简介

wait()和sleep()的区别理解

ML - 图像 - 深度学习和卷积神经网络

4PAM在高斯信道与瑞利信道下的基带仿真系统实验

matlab---错误使用 var 数据类型无效。第一个输入参数必须为单精度值或双精度值

Simulate setinterval timer with setTimeout

Remember that spark foreachpartition once led to oom

No tracked branch configured for branch xxx or the branch doesn‘t exist. To make your branch trac

NPM's nexus private server e401 E500 error handling record

How to solve the problem of scanf compilation error in Visual Studio
随机推荐
ML - natural language processing - Introduction to natural language processing
C # carefully sorting out key points of knowledge 11 entrustment and events (recommended Collection)
IOS interview questions
UIDocumentInteractionController UIDocumentPickerViewController
二进制补码
C#精挑整理知识要点10 泛型(建议收藏)
Overview of JS synchronous, asynchronous, macro task and micro task
Qtime定义(手工废物利用简单好看)
Submarine cable detector tss350 (I)
Flex 布局
本地缓存--Ehcache
2021上海市赛-D-卡特兰数变种,dp
GAMES101复习:三维变换
Redis elimination strategy list
Application of C language array in Sanzi chess -- prototype of Queen n problem
ML - 语音 - 传统语音模型
Week303 of leetcode
记一次Spark报错:Failed to allocate a page (67108864 bytes), try again.
matlab---错误使用 var 数据类型无效。第一个输入参数必须为单精度值或双精度值
异步fifo的实现