Skip to content

Commit

Permalink
fix image attention layernorm
Browse files Browse the repository at this point in the history
  • Loading branch information
lucidrains committed Aug 5, 2021
1 parent b7c34d5 commit 7a8838f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lightweight_gan/lightweight_gan.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,17 @@ def forward(self, x):
fn = self.fn if random() < self.prob else self.fn_else
return fn(x)

ChanNorm = partial(nn.InstanceNorm2d, affine = True)
class ChanNorm(nn.Module):
def __init__(self, dim, eps = 1e-5):
super().__init__()
self.eps = eps
self.g = nn.Parameter(torch.ones(1, dim, 1, 1))
self.b = nn.Parameter(torch.zeros(1, dim, 1, 1))

def forward(self, x):
std = torch.var(x, dim = 1, unbiased = False, keepdim = True).sqrt()
mean = torch.mean(x, dim = 1, keepdim = True)
return (x - mean) / (std + self.eps) * self.g + self.b

class PreNorm(nn.Module):
def __init__(self, dim, fn):
Expand Down
2 changes: 1 addition & 1 deletion lightweight_gan/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.20.3'
__version__ = '0.20.4'

0 comments on commit 7a8838f

Please sign in to comment.