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 fdb8903 commit fc22408
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion stylegan2_pytorch/stylegan2_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,17 @@ def __init__(self, fn):
def forward(self, x):
return self.fn(x) + 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 stylegan2_pytorch/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.8.4'
__version__ = '1.8.5'

0 comments on commit fc22408

Please sign in to comment.