When training a model, it is often beneficial to maintain moving averages of the trained parameters. Evaluations that use averaged parameters sometimes produce significantly better results than the final trained values.
ema = EMA(model,0.999)
ema.register()
Update the value of shadow parameters after the change of trainable parameters (This is usually used in the training loop of the model).
ema.update()
ema.apply_shadow()
ema.restore()