basicsr.models.lr_scheduler¶
- class basicsr.models.lr_scheduler.CosineAnnealingRestartLR(optimizer, periods, restart_weights=(1,), eta_min=0, last_epoch=-1)[source]¶
Bases:
_LRScheduler
Cosine annealing with restarts learning rate scheme.
An example of config: periods = [10, 10, 10, 10] restart_weights = [1, 0.5, 0.5, 0.5] eta_min=1e-7
It has four cycles, each has 10 iterations. At 10th, 20th, 30th, the scheduler will restart with the weights in restart_weights.
- Parameters:
optimizer (torch.nn.optimizer) – Torch optimizer.
periods (list) – Period for each cosine anneling cycle.
restart_weights (list) – Restart weights at each restart iteration. Default: [1].
eta_min (float) – The minimum lr. Default: 0.
last_epoch (int) – Used in _LRScheduler. Default: -1.
- class basicsr.models.lr_scheduler.MultiStepRestartLR(optimizer, milestones, gamma=0.1, restarts=(0,), restart_weights=(1,), last_epoch=-1)[source]¶
Bases:
_LRScheduler
MultiStep with restarts learning rate scheme.
- Parameters:
optimizer (torch.nn.optimizer) – Torch optimizer.
milestones (list) – Iterations that will decrease learning rate.
gamma (float) – Decrease ratio. Default: 0.1.
restarts (list) – Restart iterations. Default: [0].
restart_weights (list) – Restart weights at each restart iteration. Default: [1].
last_epoch (int) – Used in _LRScheduler. Default: -1.
- basicsr.models.lr_scheduler.get_position_from_periods(iteration, cumulative_period)[source]¶
Get the position from a period list.
It will return the index of the right-closest number in the period list. For example, the cumulative_period = [100, 200, 300, 400], if iteration == 50, return 0; if iteration == 210, return 2; if iteration == 300, return 2.
- Parameters:
iteration (int) – Current iteration.
cumulative_period (list[int]) – Cumulative period list.
- Returns:
The position of the right-closest number in the period list.
- Return type:
int