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

Class Generator

Code/net/Generator.py:36–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34 return x + self.block(x)
35
36class Generator(torch.nn.Module):
37 def __init__(self,img_channels,num_features = 64,num_residual=9):
38 super(Generator, self).__init__()
39 self.initial = torch.nn.Sequential(
40 torch.nn.Conv2d(in_channels=img_channels,out_channels=num_features,kernel_size=(7,7),stride=(1,1),padding=3,padding_mode='reflect'),
41 torch.nn.ReLU(inplace=True)
42 )
43 self.down_blocks = torch.nn.ModuleList(
44 [
45 ConvBlock(in_channels=num_features,out_channels=num_features*2,kernel_size=(3,3),stride=(2,2),padding=1),
46 ConvBlock(in_channels=num_features*2, out_channels=num_features * 4, kernel_size=(3, 3), stride=(2, 2), padding=1)
47 ]
48 )
49 self.residual_blocks = torch.nn.Sequential(
50 *[ResidualBlock(num_features*4) for _ in range(num_residual)]
51 )
52 self.up_blocks = torch.nn.ModuleList(
53 [
54 ConvBlock(in_channels=num_features*4,out_channels=num_features*2,down=False,kernel_size=3,stride = 2,padding=1,output_padding=1),
55 ConvBlock(in_channels=num_features * 2, out_channels=num_features * 1, down=False, kernel_size=3, stride=2, padding=1,output_padding=1)
56 ]
57 )
58 self.last = torch.nn.Sequential(
59 torch.nn.Conv2d(in_channels=num_features, out_channels=img_channels, kernel_size=(7, 7), stride=(1, 1),
60 padding=3, padding_mode='reflect'),
61 torch.nn.Tanh()
62 )
63 def forward(self,x):
64 x = self.initial(x)
65 for layer in self.down_blocks:
66 x = layer(x)
67 x = self.residual_blocks(x)
68 for layer in self.up_blocks:
69 x = layer(x)
70 out = self.last(x)
71 return out
72
73if __name__ == '__main__':
74 img_channels = 3

Callers 3

main_Function · 0.90
mainWindows.pyFile · 0.90
Generator.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected