Первый коммит: код классификатора наручных знаков (Naruto)
This commit is contained in:
14
src/train/opt/opt_modules/ema.py
Normal file
14
src/train/opt/opt_modules/ema.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import torch
|
||||
|
||||
class ExponentialMovingAverage(torch.optim.swa_utils.AveragedModel):
|
||||
"""Maintains moving averages of model parameters using an exponential decay.
|
||||
``ema_avg = decay * avg_model_param + (1 - decay) * model_param``
|
||||
`torch.optim.swa_utils.AveragedModel <https://pytorch.org/docs/stable/optim.html#custom-averaging-strategies>`_
|
||||
is used to compute the EMA.
|
||||
"""
|
||||
|
||||
def __init__(self, model, decay, device="cpu"):
|
||||
def ema_avg(avg_model_param, model_param, num_averaged):
|
||||
return decay * avg_model_param + (1 - decay) * model_param
|
||||
|
||||
super().__init__(model, device, ema_avg, use_buffers=True)
|
||||
Reference in New Issue
Block a user