chainer.training.extensions.LinearShift¶
- class chainer.training.extensions.LinearShift(attr, value_range, time_range, optimizer=None)[source]¶
Trainer extension to change an optimizer attribute linearly.
This extension changes an optimizer attribute from the first value to the last value linearly within a specified duration. The typical use case is warming up of the momentum coefficient.
For example, suppose that this extension is called at every iteration, and
value_range == (x, y)
andtime_range == (i, j)
. Then, this extension keeps the attribute to bex
up to thei
-th iteration, linearly shifts the value toy
by thej
-th iteration, and then keeps the value to bey
after thej
-th iteration.This extension is also called before the training loop starts by default.
- Parameters
attr (str) – Name of the optimizer attribute to adjust.
value_range (tuple of float) – The first and the last values of the attribute.
time_range (tuple of ints) – The first and last counts of calls in which the attribute is adjusted.
optimizer (Optimizer) – Target optimizer object. If it is None, the main optimizer of the trainer is used.
Methods
- __call__(trainer)[source]¶
Invokes the extension.
Implementations should override this operator. This method is called at iterations which the corresponding trigger accepts.
- Parameters
trainer (Trainer) – Trainer object that calls this operator.
- initialize(trainer)[source]¶
Initializes up the trainer state.
This method is called before entering the training loop. An extension that modifies the state of
Trainer
can 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.
For example,
ExponentialShift
extension 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. TheExponentialShift
extension recovers it in itsinitialize
method if it has been loaded from a snapshot, or just setting the initial value otherwise.- Parameters
trainer (Trainer) – Trainer object that runs the training loop.
- on_error(trainer, exc, tb)[source]¶
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.
- serialize(serializer)[source]¶
Serializes the extension state.
It is called when a trainer that owns this extension is serialized. It serializes nothing by default.
- __eq__(value, /)¶
Return self==value.
- __ne__(value, /)¶
Return self!=value.
- __lt__(value, /)¶
Return self<value.
- __le__(value, /)¶
Return self<=value.
- __gt__(value, /)¶
Return self>value.
- __ge__(value, /)¶
Return self>=value.
Attributes
- default_name¶
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')¶