LRScheduler#
-
class
ignite.handlers.param_scheduler.
LRScheduler
(lr_scheduler, save_history=False)[source]# A wrapper class to call torch.optim.lr_scheduler objects as ignite handlers.
- Parameters
lr_scheduler (torch.optim.lr_scheduler._LRScheduler) – lr_scheduler object to wrap.
save_history (bool) – whether to log the parameter values to engine.state.param_history, (default=False).
from ignite.handlers.param_scheduler import LRScheduler from torch.optim.lr_scheduler import StepLR step_scheduler = StepLR(optimizer, step_size=3, gamma=0.1) scheduler = LRScheduler(step_scheduler) # In this example, we assume to have installed PyTorch>=1.1.0 # (with new `torch.optim.lr_scheduler` behaviour) and # we attach scheduler to Events.ITERATION_COMPLETED # instead of Events.ITERATION_STARTED to make sure to use # the first lr value from the optimizer, otherwise it is will be skipped: trainer.add_event_handler(Events.ITERATION_COMPLETED, scheduler)
New in version 0.5.1.
Methods
Method to get current optimizer’s parameter value
Copies parameters from
state_dict
into this ParamScheduler.Method to plot simulated scheduled values during num_events events.
Method to simulate scheduled values during num_events events.
Returns a dictionary containing a whole state of ParamScheduler.
-
load_state_dict
(state_dict)# Copies parameters from
state_dict
into this ParamScheduler.- Parameters
state_dict (Mapping) – a dict containing parameters.
- Return type
-
classmethod
plot_values
(num_events, **scheduler_kwargs)# Method to plot simulated scheduled values during num_events events.
This class requires matplotlib package to be installed:
pip install matplotlib
- Parameters
num_events (int) – number of events during the simulation.
scheduler_kwargs (Mapping) – parameter scheduler configuration kwargs.
- Returns
matplotlib.lines.Line2D
- Return type
Any
Examples
import matplotlib.pylab as plt plt.figure(figsize=(10, 7)) LinearCyclicalScheduler.plot_values(num_events=50, param_name='lr', start_value=1e-1, end_value=1e-3, cycle_size=10))