当前位置:网站首页>Custom learning rate
Custom learning rate
2022-07-27 21:09:00 【jstzwjr】
warm up + Custom learning rate policy ( Such as cos)
from math import cos, pi
from torch.optim.lr_scheduler import _LRScheduler
class CustomScheduler(_LRScheduler):
def __init__(self, optimizer, base_lr, max_steps, warmup_steps, eta_min=0, last_epoch=-1):
self.base_lr = base_lr
self.warmup_lr_init = 0.0001
self.max_steps: int = max_steps
self.warmup_steps: int = warmup_steps
self.power = 2
self.eta_min = eta_min
super(CustomScheduler, self).__init__(optimizer, -1, False)
self.last_epoch = last_epoch
def get_warmup_lr(self):
alpha = float(self.last_epoch) / float(self.warmup_steps)
return [self.base_lr * alpha for _ in self.optimizer.param_groups]
def get_lr(self):
if self.last_epoch == -1:
return [self.warmup_lr_init for _ in self.optimizer.param_groups]
if self.last_epoch < self.warmup_steps:
return self.get_warmup_lr()
else:
alpha = self.func()
return [(self.base_lr-self.eta_min) * alpha + self.eta_min for _ in self.optimizer.param_groups]
def func(self):
alpha = (
1
- float(self.last_epoch - self.warmup_steps)
/ float(self.max_steps - self.warmup_steps))
return alpha
class PolyScheduler(CustomScheduler):
def __init__(self, optimizer, base_lr, max_steps, warmup_steps, eta_min=0, last_epoch=-1):
super().__init__(optimizer, base_lr, max_steps, warmup_steps, eta_min, last_epoch)
def func(self):
alpha = pow(
1
- float(self.last_epoch - self.warmup_steps)
/ float(self.max_steps - self.warmup_steps),
self.power,
)
return alpha
class CosineScheduler(CustomScheduler):
def __init__(self, optimizer, base_lr, max_steps, warmup_steps, eta_min=0, last_epoch=-1):
super().__init__(optimizer, base_lr, max_steps, warmup_steps, eta_min, last_epoch)
def func(self):
alpha = cos(
pi / 2
* float(self.last_epoch - self.warmup_steps)
/ float(self.max_steps - self.warmup_steps))
return alpha
边栏推荐
- QT link MSSQL
- Leetcode daily practice - 203. remove linked list elements
- MapGIS三维场景渲染技术与应用
- Rk3399 platform development series explanation (process part) 15.36, understanding process and collaboration process
- Global styles and icons
- Overview of understanding the physical layer of transmission media
- Vant component library
- Know the transmission medium, the medium of network communication
- LeetCode-136-只出现一次的数字
- Understanding network model TCPIP model
猜你喜欢

【历史上的今天】7 月 27 日:模型检测先驱出生;微软收购 QDOS;第一张激光照排的中文报纸

【R语言】【1】初学R语言语法使用Rstudio编辑

How to make personalized recommendations instantly accessible? Cloud native database gaussdb (for redis) to help

知识管理系统推动企业信息化发展

Arduino development (II)_ RGB light control method based on Arduino uno development board

Uncaught SyntaxError: redeclaration of let page

Zhongdi Digital: integrating innovative domestic GIS to boost the construction of real 3D China

IOU 目标跟踪其二:VIOU Tracker

PHP代码审计5—XSS漏洞

Source Insight 4.0使用介绍
随机推荐
PHP code audit 5 - XSS vulnerability
[numpy] array index and slice
[numpy] broadcast mechanism
Qt OPenGL 光的漫反射
A method of MCU log output
14天鸿蒙设备开发实战-第七章 设备联网上云 学习笔记
Repeated DNA sequence [hash determination repetition + sliding window + bit operation of binary coding]
LeetCode每日一练 —— CM11 链表分割
Sscanf caused the address to be out of bounds
如何对话CIO/CTO
坚持做一件事情
R语言使用epiDisplay包的lroc函数可视化logistic回归模型的ROC曲线并输出诊断表(diagnostic table)、可视化多条ROC曲线、使用legend函数为可视化图像添加图例
Hexagon_ V65_ Programmers_ Reference_ Manual(8)
Global styles and icons
Beijing / Shanghai / Guangzhou / Shenzhen dama-cdga/cdgp data governance certification registration conditions
[Numpy] 数组索引和切片
Face recognition 5.1- insightface face face detection model training practice notes
R语言使用lm函数构建多元回归模型(Multiple Linear Regression)、并根据模型系数写出回归方程、使用deviance函数计算出模型的残差平方和
Arduino development (II)_ RGB light control method based on Arduino uno development board
LeetCode-136-只出现一次的数字