StepStateScheduler#
- class ignite.handlers.state_param_scheduler.StepStateScheduler(initial_value, gamma, step_size, param_name, save_history=False, create_new=False)[source]#
Update a parameter during training by using a step function. This function decays the parameter value by gamma every step_size. Based on StepLR from PyTorch. https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.StepLR.html
- Parameters
initial_value (float) – Starting value of the parameter.
gamma (float) – Multiplicative factor of parameter value decay.
step_size (int) – Period of parameter value decay.
param_name (str) – name of parameter to update.
save_history (bool) – whether to log the parameter values to engine.state.param_history, (default=False).
create_new (bool) – whether to create
param_name
onengine.state
taking into account whetherparam_name
attribute already exists or not. Overrides existing attribute by default, (default=False).
Examples
param_scheduler = StepStateScheduler( param_name="param", initial_value=1, gamma=0.9, step_size=5, create_new=True ) # parameter is param, initial_value sets param to 1, gamma is set as 0.9 # Epoch 1 to 4, param does not change as step size is 5, # Epoch 5, param changes from 1 to 1*0.9, param = 0.9 # Epoch 5 to 9, param = 0.9 as step size is 5, # Epoch 10, param changes from 0.9 to 0.9*0.9, param = 0.81 # Epoch 10 to 14, param = 0.81, as step size is 5 # Epoch 15, param changes from 0.81 to 0.81*0.9, param = 0.729 # and so on ... the param change at Epoch = 5, 10, 15, 20, . . . param_scheduler.attach(default_trainer, Events.EPOCH_COMPLETED) @default_trainer.on(Events.EPOCH_COMPLETED(every=5)) def print_param(): print(default_trainer.state.param) default_trainer.run([0], max_epochs=25)
0.9 0.81 0.7290... 0.6561 0.5904...
New in version 0.4.7.
Methods
Method to get current parameter values