update torch_utils.py to FP16 EMA
This commit is contained in:
parent
8b38e6f429
commit
41ff83a98d
|
|
@ -195,6 +195,8 @@ class ModelEMA:
|
|||
def __init__(self, model, decay=0.9999, updates=0):
|
||||
# Create EMA
|
||||
self.ema = deepcopy(model.module if is_parallel(model) else model).eval() # FP32 EMA
|
||||
if next(model.parameters()).device.type != 'cpu':
|
||||
self.ema.half() # FP16 EMA
|
||||
self.updates = updates # number of EMA updates
|
||||
self.decay = lambda x: decay * (1 - math.exp(-x / 2000)) # decay exponential ramp (to help early epochs)
|
||||
for p in self.ema.parameters():
|
||||
|
|
|
|||
Loading…
Reference in New Issue