目录

  • 一、前言
  • 二、Pytorch中自动调整学习率的几种方式
    •  2.1 ExponentialLR-指数衰减方式
    •  2.2 ExponentialLR方式对网络训练的影响
    •  2.3 MultiStepLR-按给定间隔调整学习率
    •  2.4 MultiStepLR调整学习率对网络训练的影响
    •  2.5 -CosineAnnealingLR-余弦周期调整学习率
    •  2.6 CosineAnnealingLR调整学习率对网络训练的影响
    •  2.7 -ReduceLRonPlateau-监控某种特定的指标(如,校验损失)
    •  2.8 ReduceLRonPlateau调整学习率对网络训练的影响
    •  2.9 LambdaLR-自定义函数调整学习率
    •  2.10 LambdaLR学习率调整结果展示
    •  2.11 StepLR学习率调整结果展示
    •  2.12 StepLR学习率调整结果展示
  • 三、参考链接

一、前言

  学习率要在收敛和收敛速度中做出权衡,合适的学习率能以最快速度逼近最优解同时使得损失不断下降。在复杂网络中,固定的学习率一般无法得到网络的最优解,动态调整学习率或对模型不同部分设置不同的学习率已成为一种训练模型的趋势趋势。

二、Pytorch中自动调整学习率的几种方式

 2.1 ExponentialLR-指数衰减方式

torch.optim.lr_scheduler.ExponentialLR(optimizer, gamma,last_epoch=-1)

    其中,optimizer为指定的优化器,γ\gammaγ为指数的底数,通常将γ\gammaγ设置为接近于1的数。
    学习率更新公式如下所示:
lrnew=lrinit∗γepochlr_{new}=lr_{init}*\gamma^{epoch}lrnew​=lrinit​∗γepoch    其中,lrinitlr_{init}lrinit​为初始学习率,lrnewlr_newlrn​ew为更新后的学习率,epochepochepoch为当前训练迭代次数。

import torch
import torch.nn as nn
import matplotlib.pyplot as plt
from torch.optim.lr_scheduler import ExponentialLR
DEVICE = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
plt.rcParams['font.sans-serif'] = 'SimHei'         # 显示中文
plt.rcParams['axes.unicode_minus'] = False         # 显示负号
SEED = 40                                          # 设置随机种子,使得每次运行时产生的随机数一致# 构建网络
class Net(torch.nn.Module):def __init__(self):super(Net, self).__init__()self.linear = nn.Linear(50, 100)self.leakrelu = nn.LeakyReLU(0.001)self.linear1 = nn.Linear(100, 50)# 前向传播def forward(self, input):x = self.leakrelu(self.linear(input))output = self.leakrelu(self.linear1(x))return outputlr = []                              # 保存每个epoch的学习率
epochTrainLoss = []                  # 保存每个epoch的训练损失
epochValLoss = []                    # 保存每个epoch的校验损失
maxepoch = 50
torch.manual_seed(SEED)
if torch.cuda.is_available():torch.cuda.manual_seed(SEED)# 产生训练所需数据
input_train = torch.randn(10, 50)      # 训练输入数据
target_train = torch.randn(10, 50)     # 训练标签
input_val = torch.randn(10, 50)        # 校验输入数据
target_val = torch.randn(10, 50)       # 校验所用标签net = Net()                          # 初始化网络
optimizer = torch.optim.Adam(net.parameters(), lr=0.01)   # 初始化优化器-Adam
scheduler = ExponentialLR(optimizer, gamma=0.9)          # 以指数方式调整学习率
loss_fn = torch.nn.MSELoss()         # 初始化损失函数
loss_fn.to(DEVICE)# 训练模型
for epoch in range(maxepoch):lr.append(scheduler.get_last_lr()[0])print(epoch, scheduler.get_last_lr()[0])# 将训和校验数据和模型加载到device中net = net.to(DEVICE)input_train = input_train.to(DEVICE)target_train = target_train.to(DEVICE)input_val = input_val.to(DEVICE)target_val = target_val.to(DEVICE)net.train()                 # 进入训练模式net.zero_grad()             # 将上一次训练保存的梯度清零output = net(input_train)   # 将输入数据输入到模型中trainLoss = loss_fn(output, target_train)         # 计算训练损失trainLoss.backward()        # 反向传播epochTrainLoss.append(trainLoss.cpu().detach().numpy())optimizer.step()            # 更新模型参数scheduler.step()            # 更新学习率net.eval()                  # 进入测试模式with torch.no_grad():       # 不考虑梯度output_val = net(input_val)valLoss = loss_fn(output_val, target_val)     # 校验损失epochValLoss.append(valLoss.cpu().detach().numpy())print("epoch = %02d  trainLoss = %.4f valLoss = %.4f" % (epoch, trainLoss, valLoss))# 绘制学习率变化曲线图
plt.figure()
x = list(range(maxepoch))
plt.plot(x, lr)
plt.xlabel('epochs')
plt.ylabel('lr')
plt.show()# 绘制损失曲线图
plt.figure()
plt.plot(x, epochTrainLoss)
plt.plot(x, epochValLoss)
plt.legend(['trainLoss','valLoss'])
plt.xlabel('epochs')
plt.ylabel('Loss')
plt.show()

 2.2 ExponentialLR方式对网络训练的影响

   (1) 学习率按照ExponentialLR方式衰减,初始参数如下所示:
     1) 初始学习率lrinit=0.1lr_{init}=0.1lrinit​=0.1
     2) ExponentialLR参数γ=0.9\gamma=0.9γ=0.9

   (2) 学习率为固定常数
     1) 初始学习率lrinit=0.01lr_{init}=0.01lrinit​=0.01
     2) ExponentialLR参数γ=1\gamma=1γ=1

 2.3 MultiStepLR-按给定间隔调整学习率

torch.optim.lr_scheduler.MultiStepLR(optimizer,milestones,gamma,last_epoch=-1)

    其中,optimizer为指定的优化器,milestones为指定衰减区间,γ\gammaγ为指数的底数,通常将γ\gammaγ设置为接近于1的数。当milestones=[x1,x2]milestones=[x_{1}, x_{2}]milestones=[x1​,x2​], 且满足x1<x2<maxEpoch=50x_{1}<x_{2}<maxEpoch=50x1​<x2​<maxEpoch=50时,更新公式如下所示:
lrnew ={lrinit ∗γepoch ∈[0,x1)lrinit ∗γepoch ∈[x1,x2)lrinit∗γepoch ∈[x2,50)l r_{\text {new }}= \begin{cases}l r_{\text {init }} * \gamma & \text { epoch } \in\left[0, x_{1}\right) \\ l r_{\text {init }} * \gamma & \text { epoch } \in\left[x_{1}, x_{2}\right) \\ l r_{i n i t} * \gamma & \text { epoch } \in\left[x_{2}, 50\right)\end{cases} lrnew ​=⎩⎪⎨⎪⎧​lrinit ​∗γlrinit ​∗γlrinit​∗γ​ epoch ∈[0,x1​) epoch ∈[x1​,x2​) epoch ∈[x2​,50)​    其中,lrinitlr_{init}lrinit​为初始学习率,lrnewlr_{new}lrnew​为更新后的学习率,epochepochepoch为当前训练迭代次数,maxEpoch=50maxEpoch=50maxEpoch=50为最大训练次数。

import torch
import torch.nn as nn
import matplotlib.pyplot as plt
from torch.optim.lr_scheduler import ExponentialLR, MultiStepLR
DEVICE = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
plt.rcParams['font.sans-serif'] = 'SimHei'         # 显示中文
plt.rcParams['axes.unicode_minus'] = False         # 显示负号
SEED = 40                                          # 设置随机种子,使得每次运行时产生的随机数一致# 构建网络
class Net(torch.nn.Module):def __init__(self):super(Net, self).__init__()self.linear = nn.Linear(50, 100)self.leakrelu = nn.LeakyReLU(0.001)self.linear1 = nn.Linear(100, 50)# 获取模型权重和偏置参数,并封装未params_group格式def get_params(self, weight_decay=0.0):weights, biases = [], []for name, param in self.named_parameters():if 'bias' in name:biases += [param]else:weights += [param]params = [{'params': weights,'weight_decay': weight_decay,}, {'params': biases,'weight_decay': 0.0,}]return params# 前向传播def forward(self, input):x = self.leakrelu(self.linear(input))output = self.leakrelu(self.linear1(x))return outputlr = []                              # 保存每个epoch的学习率
epochTrainLoss = []                  # 保存每个epoch的训练损失
epochValLoss = []                    # 保存每个epoch的校验损失
maxepoch = 50
torch.manual_seed(SEED)
if torch.cuda.is_available():torch.cuda.manual_seed(SEED)# 产生训练所需数据
input_train = torch.randn(10, 50)      # 训练输入数据
target_train = torch.randn(10, 50)     # 训练标签
input_val = torch.randn(10, 50)        # 校验输入数据
target_val = torch.randn(10, 50)       # 校验所用标签net = Net()                          # 初始化网络
optimizer = torch.optim.Adam(net.parameters(), lr=0.1)   # 初始化优化器-Adam
scheduler = MultiStepLR(optimizer, milestones=[4, 20, 40, 50], gamma=0.9)          # 以指数方式调整学习率loss_fn = torch.nn.MSELoss()         # 初始化损失函数
loss_fn.to(DEVICE)# ================================== 训练 ===================================#
for epoch in range(maxepoch):lr.append(scheduler.get_last_lr()[0])print(epoch, scheduler.get_last_lr()[0])# 将训和校验数据和模型加载到device中net = net.to(DEVICE)input_train = input_train.to(DEVICE)target_train = target_train.to(DEVICE)input_val = input_val.to(DEVICE)target_val = target_val.to(DEVICE)net.train()                 # 进入训练模式net.zero_grad()             # 将上一次训练保存的梯度清零output = net(input_train)   # 将输入数据输入到模型中trainLoss = loss_fn(output, target_train)         # 计算训练损失trainLoss.backward()        # 反向传播epochTrainLoss.append(trainLoss.cpu().detach().numpy())optimizer.step()            # 更新模型参数scheduler.step()            # 更新学习率net.eval()                  # 进入测试模式with torch.no_grad():       # 不考虑梯度output_val = net(input_val)valLoss = loss_fn(output_val, target_val)     # 校验损失epochValLoss.append(valLoss.cpu().detach().numpy())print("epoch = %02d  trainLoss = %.4f valLoss = %.4f" % (epoch, trainLoss, valLoss))# 绘制损失曲线
plt.figure()
x = list(range(maxepoch))
plt.plot(x, lr)
plt.title('学习率变化曲线图')
plt.xlabel('epochs')
plt.ylabel('lr')
plt.show()# 绘制损失曲线图
plt.figure()
plt.plot(x, epochTrainLoss)
plt.plot(x, epochValLoss)
plt.title('损失曲线图')
plt.legend(['trainLoss','valLoss'])
plt.xlabel('epochs')
plt.ylabel('Loss')
plt.show()

 2.4 MultiStepLR调整学习率对网络训练的影响

   (1) 按照给定间隔调整学习率
     1) 初始学习率lrinit=0.1lr_{init}=0.1lrinit​=0.1
     2) MultiStepLR参数milestones=[4,20,40,50],γ=0.5milestones=[4, 20, 40, 50], \gamma=0.5milestones=[4,20,40,50],γ=0.5

   (1) 学习率为固定常数:
     1) 初始学习率lrinit=0.01lr_{init}=0.01lrinit​=0.01
     2) MultiStepLR参数milestones=[4,20,40,50],γ=1milestones=[4, 20, 40, 50], \gamma=1milestones=[4,20,40,50],γ=1

 2.5 -CosineAnnealingLR-余弦周期调整学习率

torch.optim.lr_scheduler.CosineAnnealingLR(optimizer,T_max,eta_min=0,last_epoch=-1)

    其中,optimizer为指定的优化器,TmaxT_{max}Tmax​为学习率下降到最低值所需次数,eta_mineta\_mineta_min为为学习率下降下限。
    更新公式如下所示:
ηt=ηmin⁡+12(ηmax⁡−ηmin⁡)(1+cos⁡(Tcur Tmax⁡π))\eta_{t}=\eta_{\min }+\frac{1}{2}\left(\eta_{\max }-\eta_{\min }\right)\left(1+\cos \left(\frac{T_{\text {cur }}}{T_{\max }} \pi\right)\right) ηt​=ηmin​+21​(ηmax​−ηmin​)(1+cos(Tmax​Tcur ​​π))    其中,ηmin⁡=eta_min\eta_{\min }=eta\_minηmin​=eta_min为设置的最低学习率,ηt\eta_{t}ηt​为更新后的学习率,ηmax⁡\eta_{\max }ηmax​为初始学习率,Tcur T_{\text {cur }}Tcur ​为当前训练迭代次数,Tmax=T_maxT_{max}=T\_maxTmax​=T_max为学习率下降到最低值所需次数。

 2.6 CosineAnnealingLR调整学习率对网络训练的影响

   (1) 余弦周期调整学习率
     1) 初始学习率ηmax⁡=0.1\eta_{\max }=0.1ηmax​=0.1
     2) CosineAnnealingLR参数eta_min=0.0001,Tmax⁡=20eta\_min=0.0001, T_{\max }=20eta_min=0.0001,Tmax​=20,TmaxT_{\text{max}}Tmax​表示下降到最小学习率eta_mineta\_mineta_min所需迭代次数。

   (1) 学习率为固定常数:

     1) 初始学习率ηmax⁡=0.01\eta_{\max }=0.01ηmax​=0.01

 2.7 -ReduceLRonPlateau-监控某种特定的指标(如,校验损失)

torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='min', factor=0.1, patience=10, threshold=0.0001, threshold_mode='rel', cooldown=0, min_lr=0, eps=1e-08, verbose=False)

    参数:
      (1) optimizer为指定的优化器
      (2) modemodemode监控模式,min-指标不在下降时更新学习率,max-指标不在增大时更新学习率
      (3) factor为学习率调整因子;patience-连续patience次指标不下降或不上升(取决于mode)时,就更新学习率
      (4) cooldown:每更新一次学习率后停止监控一段时间(cooldown=5,更新学习率后间隔5个epoch再继续监控相应指标
      (5) verbose:是否打印日志-布尔变量,默认False
      (6) min_lr:学习率下限
      (7) eps:学习率衰减最小值
    满足条件后,更新公式如下所示:
lrnew=lrinit∗factorlr_{new}=lr_{init}*factorlrnew​=lrinit​∗factor    其中,lrinitlr_{init}lrinit​为初始学习率,lrnewlr_{new}lrnew​为更新后的学习率,epochepochepoch为当前训练迭代次数。

import torch
import torch.nn as nn
import matplotlib.pyplot as plt
from torch.optim.lr_scheduler import ExponentialLR, MultiStepLR, CosineAnnealingLR, ReduceLROnPlateau
DEVICE = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
plt.rcParams['font.sans-serif'] = 'SimHei'         # 显示中文
plt.rcParams['axes.unicode_minus'] = False         # 显示负号
SEED = 40                                          # 设置随机种子,使得每次运行时产生的随机数一致# 构建网络
class Net(torch.nn.Module):def __init__(self):super(Net, self).__init__()self.linear = nn.Linear(50, 100)self.leakrelu = nn.LeakyReLU(0.001)self.linear1 = nn.Linear(100, 50)self.elu = nn.ELU()# 获取模型权重和偏置参数,并封装未params_group格式def get_params(self, weight_decay=0.0):weights, biases = [], []for name, param in self.named_parameters():if 'bias' in name:biases += [param]else:weights += [param]params = [{'params': weights,'weight_decay': weight_decay,}, {'params': biases,'weight_decay': 0.0,}]return params# 前向传播def forward(self, input):x = self.leakrelu(self.linear(input))output = self.leakrelu(self.linear1(x))return outputlr = []                              # 保存每个epoch的学习率
epochTrainLoss = []                  # 保存每个epoch的训练损失
epochValLoss = []                    # 保存每个epoch的校验损失
maxepoch = 50
torch.manual_seed(SEED)
if torch.cuda.is_available():torch.cuda.manual_seed(SEED)# 产生训练所需数据
input_train = torch.randn(10, 50)      # 训练输入数据
target_train = torch.randn(10, 50)     # 训练标签
input_val = torch.randn(10, 50)        # 校验输入数据
target_val = torch.randn(10, 50)       # 校验所用标签net = Net()                          # 初始化网络
optimizer = torch.optim.Adam(net.parameters(), lr=0.1)   # 初始化优化器-Adam
scheduler = ReduceLROnPlateau(optimizer, factor=0.5, patience=1, verbose=True)loss_fn = torch.nn.MSELoss()         # 初始化损失函数
loss_fn.to(DEVICE)# ================================== 训练 ===================================#
for epoch in range(maxepoch):lr.append(optimizer.param_groups[0]["lr"])        # 获取当前优化器中使用的学习率print(epoch, optimizer.param_groups[0]["lr"])# 将训和校验数据和模型加载到device中net = net.to(DEVICE)input_train = input_train.to(DEVICE)target_train = target_train.to(DEVICE)input_val = input_val.to(DEVICE)target_val = target_val.to(DEVICE)net.train()                 # 进入训练模式net.zero_grad()             # 将上一次训练保存的梯度清零output = net(input_train)   # 将输入数据输入到模型中trainLoss = loss_fn(output, target_train)         # 计算训练损失trainLoss.backward()        # 反向传播epochTrainLoss.append(trainLoss.cpu().detach().numpy())optimizer.step()            # 更新模型参数net.eval()                  # 进入测试模式with torch.no_grad():       # 不考虑梯度output_val = net(input_val)valLoss = loss_fn(output_val, target_val)     # 校验损失epochValLoss.append(valLoss.cpu().detach().numpy())scheduler.step(valLoss)     # 更新学习率print("epoch = %02d  trainLoss = %.4f valLoss = %.4f" % (epoch, trainLoss, valLoss))# 绘制损失曲线
plt.figure()
x = list(range(maxepoch))
plt.plot(x, lr)
plt.title('学习率变化曲线图')
plt.xlabel('epochs')
plt.ylabel('lr')
plt.show()# 绘制损失曲线图
plt.figure()
plt.plot(x, epochTrainLoss)
plt.plot(x, epochValLoss)
plt.title('损失曲线图')
plt.legend(['trainLoss','valLoss'])
plt.xlabel('epochs')
plt.ylabel('Loss')
plt.show()

注意:(1) ReduceLRonPlateau中无get_last_lr()方法
   (2) scheduler.best 保存着当前模型中的指标(如,valLossvalLossvalLoss)最小模型

 2.8 ReduceLRonPlateau调整学习率对网络训练的影响

   (1) 按特定指标调整学习率
     1) 初始学习率ηmax⁡=0.1\eta_{\max }=0.1ηmax​=0.1
     2) CosineAnnealingLR参数eta_min=0.0001,Tmax⁡=20eta\_min=0.0001, T_{\max }=20eta_min=0.0001,Tmax​=20

   (2) 学习率为固定常数:
     1) 初始学习率ηmax⁡=0.01\eta_{\max }=0.01ηmax​=0.01

 2.9 LambdaLR-自定义函数调整学习率

torch.optim.lr_scheduler.LambdaLR(optimizer, lr_lambda, last_epoch=- 1, verbose=False)

   参数:
     (1) optimizer封装好的优化器
     (2) lr_lambda (function or list) –为函数或此类函数的列表,列表的长度由optimator.param_groups中的参数组决定。
     (3) verbose-是否将更改学习的信息输出至控制台,默认False。
     (4) last_epoch (int) – 最后一个迭代epoch的索引. Default: -1.

# ====================== 一、当lr_lambda=lambda1时============================== #
import torch
import matplotlib.pyplot as plt
from torch.optim.lr_scheduler import LambdaLR
plt.rcParams['font.sans-serif'] = 'SimHei'         # 显示中文
plt.rcParams['axes.unicode_minus'] = False         # 显示负号lr = []  # 保存每个epoch的学习率
maxepoch = 50
params = [torch.nn.Parameter(torch.randn(4, 4, requires_grad=True))]
# params = [torch.nn.parameter.Parameter(torch.randn(4, 4, requires_grad=True))]
optimizer = torch.optim.Adam(params, lr=0.1)  # 初始化优化器-Adam# 自定义学习率调整函数
lambda1 = lambda epoch: epoch // 10
lambda2 = lambda epoch: 0.2 ** epoch
scheduler = LambdaLR(optimizer, lr_lambda=lambda2, verbose=True)# 训练
for epoch in range(maxepoch):optimizer.zero_grad()lr.append(scheduler.get_last_lr()[0])print(epoch, scheduler.get_last_lr()[0])optimizer.step()scheduler.step()# 绘制学习率变化曲线
plt.figure()
x = list(range(maxepoch))
plt.plot(x, lr)
plt.title('学习率变化曲线图')
plt.xlabel('epochs')
plt.ylabel('lr')
plt.show()# ====================== 二、当lr_lambda=[lambda1, lambda2]时============================== #
import torch
import matplotlib.pyplot as plt
from torch.optim.lr_scheduler import ExponentialLR, MultiStepLR, CosineAnnealingLR, ReduceLROnPlateau, LambdaLR
plt.rcParams['font.sans-serif'] = 'SimHei'         # 显示中文
plt.rcParams['axes.unicode_minus'] = False         # 显示负号lr1 = []  # 保存每个epoch的学习率
lr2 = []
maxepoch = 50
# 构造模型参数
params1 = [torch.nn.Parameter(torch.randn(4, 4, requires_grad=True))]
params2 = [torch.nn.Parameter(torch.randn(4, 4, requires_grad=True))]
# params = [torch.nn.parameter.Parameter(torch.randn(4, 4, requires_grad=True))]
optimizer = torch.optim.Adam([{'params': params1},{'params': params2}], lr=0.1)  # 初始化优化器-Adam# 自定义学习率调整函数
lambda1 = lambda epoch: 1/(epoch+1)
lambda2 = lambda epoch: 0.2 ** epoch
scheduler = LambdaLR(optimizer, lr_lambda=[lambda1, lambda2], verbose=True)# 训练
for epoch in range(maxepoch):optimizer.zero_grad()lr1.append(scheduler.get_last_lr()[0])lr2.append(scheduler.get_last_lr()[1])print(epoch, scheduler.get_last_lr()[0])print(epoch, scheduler.get_last_lr()[1])optimizer.step()scheduler.step()print(scheduler.state_dict())# 绘制学习率变化曲线
plt.figure()
plt.subplot(121)
x = list(range(maxepoch))
plt.plot(x, lr1)
plt.title('学习率变化曲线图')
plt.xlabel('epochs')
plt.ylabel('lr')
plt.legend(['lambda1'])
plt.subplot(122)
plt.plot(x, lr2)
plt.title('学习率变化曲线图')
plt.legend(['lambda2'])
plt.xlabel('epochs')
plt.ylabel('lr')
plt.show()

 2.10 LambdaLR学习率调整结果展示

   (1) 使用单一自定义函数改变学习率

   (2) 使用多给自定义函数更改学习率

 2.11 StepLR学习率调整结果展示

# scheduler = StepLR(optimizer, step_size=20, gamma=0.1)
# Assuming optimizer uses lr = 0.1 for all groups
# lr = 0.05     if epoch < 20
# lr = 0.005    if 20 <= epoch < 40
# lr = 0.0005   if 40 <= epoch < 50    maxepoch=50
import torch
import matplotlib.pyplot as plt
from torch.optim.lr_scheduler import StepLR
plt.rcParams['font.sans-serif'] = 'SimHei'         # 显示中文
plt.rcParams['axes.unicode_minus'] = False         # 显示负号lr = []  # 保存每个epoch的学习率
maxepoch = 50
params = [torch.nn.Parameter(torch.randn(4, 4, requires_grad=True))]
# params = [torch.nn.parameter.Parameter(torch.randn(4, 4, requires_grad=True))]
optimizer = torch.optim.Adam(params, lr=0.1)  # 初始化优化器-Adam# 自定义学习率调整函数
scheduler = StepLR(optimizer, step_size=20, gamma=0.1)for epoch in range(maxepoch):optimizer.zero_grad()lr.append(scheduler.get_last_lr()[0])print(epoch, scheduler.get_last_lr()[0])optimizer.step()scheduler.step()
print(scheduler.state_dict())

 2.12 StepLR学习率调整结果展示

三、参考链接

  1、学习率调整策略
  2、自动调整学习率
  3、CyclicLR
  4、pytorch官方手册
  5、可能是深度学习中最重要的超参数:学习率
  6、pytorch优化器与学习率设置详解

pytorch框架自动调整学习率的几种方式相关推荐

  1. php框架中什么是渲染,thinkPHP5框架渲染模板的3种方式简述

    本文实例讲述了thinkPHP5框架渲染模板的3种方式.分享给大家供大家参考,具体如下: 默认情况下,控制器的输出全部采用return的方式,无需进行任何的手动输出,系统会自动完成渲染内容的输出. 在 ...

  2. Mybatis(持久层的框架),注入的三种方式

    MyBatis 是一款优秀的持久层框架,它支持定制化 SQL(灵活).存储过程(PLSQL模块化的组件,数据库的一部分)以及高级映射(表映射为Bean也可以将Bean映射为表).MyBatis 避免了 ...

  3. J2EE高级开发框架小课程之Spring框架1——Spring创建三种方式:使用无参构造器创建对象(bean标签的方式),使用静态方法创建对象,使用实例方法创建对象(非静态方法)

    Spring是什么? 是一个开源的.用于简化企业级应用开发的应用开发框架. a.简化开发: Spring框架对很多常用的api做了简化,比如,使用Spring jdbc (Spring jdbc是Sp ...

  4. PyTorch 学习之Ubuntu16.04 下安装 PyTorch(conda与pip两种方式安装)

    一.pip安装Pytorch 这里已经默认已经安装好了显卡驱动,cuda等.我这里安装的是cuda9与cudnn7,显卡驱动号:Driver Version: 384.130 : 1.进入PyTorc ...

  5. 使用pytorch构建LSTM_AE模型的两种方式

    目录 1.LSTM-Encoder-Decoder模型结构及简要解析 2.general LSTM Unit--使用pytorch nn.LSTM组件构建LSTM_AE 1.定义Encoder: 2. ...

  6. Android实现资源动态加载的两种方式

    这是Android Apk源加载机制原理分析以及动态加载实现系列文章 的最后一篇.经过前两篇的介绍之后,相关基础都讲的差不多了,现在要实现自己项目中的资源加载框架,这里提供两种方式,区别在于由谁来加载 ...

  7. PyTorch框架学习十四——学习率调整策略

    PyTorch框架学习十四--学习率调整策略 一._LRScheduler类 二.六种常见的学习率调整策略 1.StepLR 2.MultiStepLR 3.ExponentialLR 4.Cosin ...

  8. 干货|pytorch必须掌握的的4种学习率衰减策略

    点击上方"视学算法",选择加"星标"或"置顶" 重磅干货,第一时间送达 作者丨机器学习入坑者@知乎(已授权) 来源丨https://zhua ...

  9. pytorch必须掌握的的4种学习率衰减策略

    原文: pytorch必须掌握的的4种学习率衰减策略 1.指数衰减 2. 固定步长衰减 3. 多步长衰减 4. 余弦退火衰减 5. 上述4种学习率动态更新策略的说明 梯度下降算法需要我们指定一个学习率 ...

最新文章

  1. Sigo全面适合交易新手以及专业交易者
  2. DataTables怎样取消黑白行
  3. 使用maven整合SSH框架详细步骤
  4. VC++2010中的GetWindowText与GetWindowTextW的区别
  5. java自动获取时间 月代码_【java代码获取系统时间和执行定时任务】
  6. 二维凸包 Graham's Scan
  7. centos下使用yum命令安装php mcrypt扩展
  8. 组合数学之排列组合(Permutations and Combinations)(四种情况)
  9. 省级国土空间基础信息平台建设方案分析
  10. 线性代数学习笔记——第三十二讲——向量混合积的概念与性质
  11. 三国志·魏书·牵招传
  12. 管理科学与工程 国内核心期刊 国外a刊及SCI
  13. 【科普】中医药治疗重症肌无力的独特优势
  14. 基于微信小程序开发的我最在行的小游戏
  15. android 酷狗demo_在Android上使用酷狗歌词API
  16. 妙用自定义注解,一行代码搞定大功能(文末赠书)
  17. 详细介绍NLP对话系统
  18. 手机天猫将全面升级,成为天猫新零售入口丨对话天猫总裁靖捷
  19. java Socket长连接
  20. 机器学习模型管理平台_如何管理机器学习模型

热门文章

  1. $.cookie( ) 用法详细解析
  2. nginx配置负载均衡(史上最详细)
  3. Spring boot 连接MySQL,使用数据源hikaricp
  4. IPGeo从捕捉的网络流量文件中快速提取IP地址
  5. android 开源UI库
  6. html影院选座模板,jQuery在线选座(影院版)
  7. 使用JAVA流操作(POI)将Excel表中数据取出,并直接生成完整SQL语句
  8. 2018河南对口升学计算机专业试题,河南省2018年计算机类基础课对口升学考试题...
  9. ArcGIS处理NetCDF(.nc)的多维科学数据
  10. QT实现屏幕亮度调节