Extensions¶
make_shift¶
-
chainercv.chainer_experimental.training.extensions.
make_shift
(attr, optimizer=None)[source]¶ Decorator to make shift extensions.
This decorator wraps a function and makes a shift extension. Base function should take
trainer
and return a new value ofattr
.Here is an example.
>>> # define an extension that updates 'lr' attribute >>> @make_shift('lr') >>> def warmup(trainer): >>> base_lr = 0.01 >>> rate = 0.1 >>> >>> iteration = trainer.updater.iteration >>> if iteration < 1000: >>> return base_lr * (rate + (1 - rate) * iteraion / 1000) >>> else: >>> return base_lr >>> >>> # use the extension >>> trainer.extend(warmup)
- Parameters
attr (str) – Name of the attribute to shift.
optimizer (Optimizer) – Target optimizer to adjust the attribute. If it is
None
, the main optimizer of the updater is used.