在本教程中,我们将了解 timm 库中的 PlateauLRScheduler

from timm.scheduler.plateau_lr import PlateauLRScheduler
from nbdev.showdoc import show_doc

class PlateauLRScheduler[源码]

PlateauLRScheduler(optimizer, decay_rate=0.1, patience_t=10, verbose=True, threshold=0.0001, cooldown_t=0, warmup_t=0, warmup_lr_init=0, lr_min=0, mode='max', noise_range_t=None, noise_type='normal', noise_pct=0.67, noise_std=1.0, noise_seed=None, initialize=True) :: Scheduler

每当验证损失趋于稳定时,按一定因子衰减学习率(LR)。

如上所示,PlateauLRScheduler 接受一个 optimizer 以及一些超参数,我们将在下面详细介绍。我们将首先通过使用 timm 训练文档来了解如何使用 PlateauLRScheduler 训练模型,然后了解如何将此调度器作为独立调度器用于自定义训练脚本。

timm 训练脚本中使用 PlateauLRScheduler 调度器

要使用 PlateauLRScheduler 训练模型,只需在传递训练脚本参数时添加 --sched plateau 参数以及必要的超参数。在本节中,我们还将了解每个超参数如何更新 plateau 调度器。

使用 cosine 调度器的训练命令大致如下:

python train.py ../imagenette2-320/ --sched plateau

PlateauLRScheduler 默认跟踪 eval-metric,在 timm 训练脚本中,该指标默认为 top-1。如果性能趋于稳定,则在一定数量的 epoch(默认为 10)后,新的学习率将设置为 lr * decay_rate。此调度器底层使用 PyTorch 的 ReduceLROnPlateau

参数

传递给此调度器的所有参数与 PyTorch 的 ReduceLROnPlateau 相同,只是重命名如下:

TIMM PyTorch
patience_t patience
decay_rate factor
verbose verbose
threshold threshold
cooldown_t cooldown
mode mode
lr_min min_lr

其功能与 ReduceLROnPlateau 非常相似,只是增加了噪声(Noise)功能。