Skip to content

Instantly share code, notes, and snippets.

View arunmallya's full-sized avatar

Arun Mallya arunmallya

View GitHub Profile
@jojonki
jojonki / ema.py
Last active March 13, 2020 05:18
Apply exponential moving average decay for variables in PyTorch
# How to apply exponential moving average decay for variables?
# https://discuss.pytorch.org/t/how-to-apply-exponential-moving-average-decay-for-variables/10856/2
class EMA(nn.Module):
def __init__(self, mu):
super(EMA, self).__init__()
self.mu = mu
def forward(self,x, last_average):
new_average = self.mu*x + (1-self.mu)*last_average
return new_average
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@farrajota
farrajota / convert_module.lua
Last active April 15, 2017 00:10
Convert a cudnn batchnorm module to nn backend (cycles all modules of a network).
local function ConvertBNcudnn2nn(net)
local function ConvertModule(net)
return net:replace(function(x)
if torch.type(x) == 'cudnn.BatchNormalization' then
return cudnn.convert(x, nn)
else
return x
end
end)
end