当前位置:网站首页>PyTorch 10. 学习率
PyTorch 10. 学习率
2022-04-23 06:11:00 【DCGJ666】
PyTorch 10. 学习率
scheduler
scheduler:必须关联一个优化器去调整其学习率
class _LRScheduler(object):
def __init__(self, optimizer, last_epoch=-1):
pass
def get_lr(self):
return [base_lr * self.gamma ** (self.last_epoch//self.step_size) for base_lr in self.base_lrs]
def step(self):
if epoch is None:
epoch = self.last_epoch + 1
self.last_epoch = epoch
for param_group, lr in zip(self.optimizer.param_groups, self.get_lr()):
param_group['lr'] = lr
optimizer:关联的优化器
last_epoch: 记录epoch数
base_lrs: 记录初始学习率
主要方法:
step():更新下一个epoch的学习率
get_lr(): 计算下一个epoch的学习率
StepLR
lr_scheduler.StepLR(optimizer, step_size, gamma=0.1,last_epoch=-1)
功能:等间隔调整学习率
主要参数:
step_size:调整间隔数
gamma:调整系数
调整方式: lr = lr * gamma

MultiStepLR
lr_scheduler.MultiStepLR(optimizer, milestones, gamma=0.1, last_epoch=-1)
功能:按给定间隔调整学习率
主要参数:
milestones:设定调整时刻数 ,milestones = [50, 125, 160]
gamma: 调整系数
调整方式: lr = lr *gamma

ExponentialLR
lr_scheduler.ExponentialLR(optimizer, gamma, last-epoch=-1)
功能:按指数衰减调整学习率
主要参数:
gamma:指数的底

CosineAnnealingLR
lr_scheduler.CosineAnnealingLR(optimizer, T_max, eta_min=0, last_epoch=-1)
功能:余弦周期调整学习率
主要参数:
T_max: 下降周期
eta_min: 学习率下限
调整方式:
l r t = l r m i n + 1 2 ( l r m a x − l r m i n ) ( 1 + c o s ( T c u r T m a x π ) ) lr_t = lr_{min}+\frac{1}{2}(lr_{max}-lr_{min})(1+cos(\frac{T_{cur}}{T_{max}}\pi)) lrt=lrmin+21(lrmax−lrmin)(1+cos(TmaxTcurπ))

ReduceLRonPlateau
lr_scheduler.ReduceLROnPlateau(optimizer, mode='min', factor=0.1, patience=10, verbose=False, threshold=0.0001, threshold_mode='rel',cooldown=0, min_lr=0, eps=1e-08)
功能:监控指标,当指标不再变化则调整
主要参数:
mode: min/max 两种模式
factor: 调整系数
patience: “耐心”,接受几次不变化
cooldown: “冷却时间”,停止监控一段时间
verbose: 是否打印日志
min_lr: 学习率下限
eps: 学习率衰减最小值
版权声明
本文为[DCGJ666]所创,转载请带上原文链接,感谢
https://blog.csdn.net/DCGJ666/article/details/121589443
边栏推荐
- [2021 book recommendation] Red Hat Certified Engineer (RHCE) Study Guide
- GEE配置本地开发环境
- Thanos.sh灭霸脚本,轻松随机删除系统一半的文件
- 机器学习笔记 一:学习思路
- 【2021年新书推荐】Learn WinUI 3.0
- torch.mm() torch.sparse.mm() torch.bmm() torch.mul() torch.matmul()的区别
- [3D shape reconstruction series] implicit functions in feature space for 3D shape reconstruction and completion
- Gobang games
- Visual studio 2019 installation and use
- Some common data type conversion methods in pytorch are similar to list and NP Conversion method of ndarray
猜你喜欢

C# EF mysql更新datetime字段报错Modifying a column with the ‘Identity‘ pattern is not supported
Raspberry Pie: two color LED lamp experiment

机器学习笔记 一:学习思路

Chapter 3 pytoch neural network toolbox

Machine learning III: classification prediction based on logistic regression
![Gephi tutorial [1] installation](/img/f7/a37be7ac1af3216b7491e500760ad6.png)
Gephi tutorial [1] installation

【点云系列】SG-GAN: Adversarial Self-Attention GCN for Point Cloud Topological Parts Generation

WebView displays a blank due to a certificate problem

【2021年新书推荐】Artificial Intelligence for IoT Cookbook

Google AdMob advertising learning
随机推荐
Use originpro express for free
常见的正则表达式
机器学习 三: 基于逻辑回归的分类预测
机器学习笔记 一:学习思路
[recommendation of new books in 2021] enterprise application development with C 9 and NET 5
GEE配置本地开发环境
Miscellaneous learning
【点云系列】 A Rotation-Invariant Framework for Deep Point Cloud Analysis
[recommendation of new books in 2021] practical IOT hacking
Compression and acceleration technology of deep learning model (I): parameter pruning
Chapter 5 fundamentals of machine learning
Reading notes - activity
扫雷小游戏
【动态规划】不同路径2
深度学习模型压缩与加速技术(一):参数剪枝
图像分类白盒对抗攻击技术总结
【3D形状重建系列】Implicit Functions in Feature Space for 3D Shape Reconstruction and Completion
1.2 初试PyTorch神经网络
Pymysql connection database
Three methods to realize the rotation of ImageView with its own center as the origin