当前位置:网站首页>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
边栏推荐
- 【点云系列】Relationship-based Point Cloud Completion
- 红外传感器控制开关
- 【2021年新书推荐】Red Hat RHCSA 8 Cert Guide: EX200
- PyMySQL连接数据库
- 【動態規劃】不同路徑2
- MySQL notes 3_ Restraint_ Primary key constraint
- 给女朋友写个微信双开小工具
- Recyclerview batch update view: notifyitemrangeinserted, notifyitemrangeremoved, notifyitemrangechanged
- 电脑关机程序
- “Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated
猜你喜欢

【2021年新书推荐】Practical Node-RED Programming

c语言编写一个猜数字游戏编写

Fill the network gap

【点云系列】Learning Representations and Generative Models for 3D pointclouds

【2021年新书推荐】Learn WinUI 3.0

Pymysql connection database

Summary of image classification white box anti attack technology
![[point cloud series] a rotation invariant framework for deep point cloud analysis](/img/43/065d552d216b3e253d25dcfdfaaff4.png)
[point cloud series] a rotation invariant framework for deep point cloud analysis
![[2021 book recommendation] artistic intelligence for IOT Cookbook](/img/8a/3ff45a911becb895e6dd9e061ac252.png)
[2021 book recommendation] artistic intelligence for IOT Cookbook

【2021年新书推荐】Red Hat Certified Engineer (RHCE) Study Guide
随机推荐
Raspberry Pie: two color LED lamp experiment
[point cloud series] pnp-3d: a plug and play for 3D point clouds
PyMySQL连接数据库
Android exposed components - ignored component security
1.1 pytorch and neural network
Miscellaneous learning
Chapter 8 generative deep learning
ThreadLocal,看我就够了!
第5 章 机器学习基础
MySQL notes 1_ database
torch_geometric学习一,MessagePassing
第1章 NumPy基础
【点云系列】Multi-view Neural Human Rendering (NHR)
Bottom navigation bar based on bottomnavigationview
【2021年新书推荐】Artificial Intelligence for IoT Cookbook
MySQL notes 3_ Restraint_ Primary key constraint
利用官方torch版GCN训练并测试cora数据集
Markdown basic grammar notes
“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated
C connection of new world Internet of things cloud platform (simple understanding version)