- class chainer.training.extensions.InverseShift(attr, gamma, power, init=None, target=None, optimizer=None)¶
Trainer extension to shift an optimizer attribute.
The new value is computed according to the fomula below: new_attr = init_attr * (1 + gamma * iter) ^ (- power), which is compatible to the
invlearning rate policy in Caffe.
The typical use is to decrease the learning rate during the training.
This extension is also called before the training loop starts by default.
attr (str) – Name of the attribute to shift.
gamma (float) – Parameter used to compute the new value. Refer to the fomula above. Note that gamma is assumed to be nonegative.
power (float) – Parameter used to compute the new value. Refer to the fomula above.
init (float) – Initial value of the attribute. If it is
None, the extension extracts the attribute at the first call and uses it as the initial value.
target (float) – Target value of the attribute. If the attribute reaches this value, the shift stops.
optimizer (Optimizer) – Target optimizer to adjust the attribute. If it is
None, the main optimizer of the updater is used.
Invokes the extension.
Implementations should override this operator. This method is called at iterations which the corresponding trigger accepts.
trainer (Trainer) – Trainer object that calls this operator.
Finalizes the extension.
This method is called at the end of the training loop.
Initializes up the trainer state.
This method is called before entering the training loop. An extension that modifies the state of
Trainercan override this method to initialize it.
When the trainer has been restored from a snapshot, this method has to recover an appropriate part of the state of the trainer.
ExponentialShiftextension changes the optimizer’s hyperparameter at each invocation. Note that the hyperparameter is not saved to the snapshot; it is the responsibility of the extension to recover the hyperparameter. The
ExponentialShiftextension recovers it in its
initializemethod if it has been loaded from a snapshot, or just setting the initial value otherwise.
trainer (Trainer) – Trainer object that runs the training loop.
- on_error(trainer, exc, tb)¶
Handles the error raised during training before finalization.
This method is called when an exception is thrown during the training loop, before finalize. An extension that needs different error handling from finalize, can override this method to handle errors.
Serializes the extension state.
It is called when a trainer that owns this extension is serialized. It serializes nothing by default.
- __eq__(value, /)¶
- __ne__(value, /)¶
- __lt__(value, /)¶
- __le__(value, /)¶
- __gt__(value, /)¶
- __ge__(value, /)¶
Default name of the extension.
It is the name of the class by default. Implementation can override this property, or provide a class attribute to hide it.
- name = None¶
- priority = 100¶
- trigger = (1, 'iteration')¶