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

Class Discriminator

DCGAN/DCDis.py:13–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11from torch.utils.data import DataLoader
12
13class Discriminator(torch.nn.Module):
14 def __init__(self,features = 64):
15 super(Discriminator, self).__init__()
16 self.in_features = features
17 self.conv = torch.nn.Sequential(
18 torch.nn.Conv2d(in_channels = 3,out_channels = features,kernel_size = (4,4),
19 stride=(2,2),padding = (1,1),bias = False),
20 torch.nn.BatchNorm2d(num_features= features),
21 torch.nn.LeakyReLU(negative_slope = 0.2,inplace = True),#inplace,其作用是:该nn.Relu() 函数计算得到的输出是否更新传入的输出。
22
23 torch.nn.Conv2d(in_channels=features , out_channels=features * 2, kernel_size=(4, 4),
24 stride=(2, 2), padding=(1,1), bias=False),
25 torch.nn.BatchNorm2d(num_features=features * 2),
26 torch.nn.LeakyReLU(negative_slope = 0.2,inplace = True),
27
28 torch.nn.Conv2d(in_channels=features * 2, out_channels=features * 4, kernel_size=(4, 4),
29 stride=(2, 2), padding=(1,1), bias=False),
30 torch.nn.BatchNorm2d(num_features=features * 4),
31 torch.nn.LeakyReLU(negative_slope = 0.2,inplace = True),
32
33 torch.nn.Conv2d(in_channels=features * 4, out_channels=features * 8, kernel_size=(4, 4),
34 stride=(2, 2), padding=(1,1), bias=False),
35 torch.nn.BatchNorm2d(num_features=features * 8),
36 torch.nn.LeakyReLU(negative_slope = 0.2,inplace = True),
37
38 torch.nn.Conv2d(in_channels=features * 8, out_channels=1, kernel_size=(4, 4),
39 stride=(1,1), padding=(0,0), bias=False),
40 torch.nn.Sigmoid()
41 )
42 def forward(self,input):
43 x = self.conv(input)
44 return x
45
46if __name__ == '__main__':
47 dis = Discriminator()

Callers 1

DCDis.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected