MCPcopy Create free account
hub / github.com/KeepTryingTo/Pytorch-GAN / WSConv2d

Class WSConv2d

ProGAN/model.py:38–62  ·  view source on GitHub ↗

Weight scaled Conv2d (Equalized Learning Rate) Note that input is multiplied rather than changing weights this will have the same result. Inspired and looked at: https://github.com/nvnbny/progressive_growing_of_gans/blob/master/modelUtils.py

Source from the content-addressed store, hash-verified

36factors = [1, 1, 1, 1, 1 / 2, 1 / 4, 1 / 8, 1 / 16, 1 / 32]
37
38class WSConv2d(nn.Module):
39 """
40 Weight scaled Conv2d (Equalized Learning Rate)
41 Note that input is multiplied rather than changing weights
42 this will have the same result.
43
44 Inspired and looked at:
45 https://github.com/nvnbny/progressive_growing_of_gans/blob/master/modelUtils.py
46 """
47
48 def __init__(
49 self, in_channels, out_channels, kernel_size=3, stride=1, padding=1, gain=2
50 ):
51 super(WSConv2d, self).__init__()
52 self.conv = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding)
53 self.scale = (gain / (in_channels * (kernel_size ** 2))) ** 0.5
54 self.bias = self.conv.bias
55 self.conv.bias = None
56
57 # initialize conv layer
58 nn.init.normal_(self.conv.weight)
59 nn.init.zeros_(self.bias)
60
61 def forward(self, x):
62 return self.conv(x * self.scale) + self.bias.view(1, self.bias.shape[0], 1, 1)
63
64
65class PixelNorm(nn.Module):

Callers 3

__init__Method · 0.70
__init__Method · 0.70
__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected