ParamScheduler¶
- 
class 
ignite.contrib.handlers.param_scheduler.ParamScheduler(optimizer, param_name, save_history=False, param_group_index=None)[source]¶ An abstract class for updating an optimizer’s parameter value during training.
- Parameters
 optimizer (torch.optim.optimizer.Optimizer) – torch optimizer or any object with attribute
param_groupsas a sequence.param_name (str) – name of optimizer’s parameter to update.
save_history (bool) – whether to log the parameter values to engine.state.param_history, (default=False).
param_group_index (Optional[int]) – optimizer’s parameters group to use
Note
Parameter scheduler works independently of the internal state of the attached optimizer. More precisely, whatever the state of the optimizer (newly created or used by another scheduler) the scheduler sets defined absolute values.
Methods
Method to get current optimizer’s parameter values
Copies parameters from
state_dictinto 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)[source]¶ Copies parameters from
state_dictinto this ParamScheduler.- Parameters
 state_dict (Mapping) – a dict containing parameters.
- Return type
 
- 
classmethod 
plot_values(num_events, **scheduler_kwargs)[source]¶ 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))
- 
classmethod 
simulate_values(num_events, **scheduler_kwargs)[source]¶ Method to simulate scheduled values during num_events events.
- Parameters
 num_events (int) – number of events during the simulation.
scheduler_kwargs (Any) – parameter scheduler configuration kwargs.
- Returns
 event_index, value
- Return type
 List[List[int]]
Examples:
lr_values = np.array(LinearCyclicalScheduler.simulate_values(num_events=50, param_name='lr', start_value=1e-1, end_value=1e-3, cycle_size=10)) plt.plot(lr_values[:, 0], lr_values[:, 1], label="learning rate") plt.xlabel("events") plt.ylabel("values") plt.legend()