| 43 | return out |
| 44 | |
| 45 | class Discriminator(torch.nn.Module): |
| 46 | def __init__(self,W = 28,H = 28,out_features = 1): |
| 47 | super(Discriminator, self).__init__() |
| 48 | self.fc_layer_1 = torch.nn.Sequential( |
| 49 | torch.nn.Linear(in_features=W * H,out_features=1024), |
| 50 | torch.nn.LeakyReLU(negative_slope=0.2,inplace=True) |
| 51 | ) |
| 52 | self.fc_layer_2 = torch.nn.Sequential( |
| 53 | torch.nn.Linear(in_features=10,out_features=1024), |
| 54 | torch.nn.LeakyReLU(negative_slope=0.2,inplace=True) |
| 55 | ) |
| 56 | self.fc_layer_3 = torch.nn.Sequential( |
| 57 | torch.nn.Linear(in_features=2048,out_features=512), |
| 58 | torch.nn.BatchNorm1d(num_features=512), |
| 59 | torch.nn.LeakyReLU(negative_slope=0.2,inplace=True) |
| 60 | ) |
| 61 | self.fc_layer_4 = torch.nn.Sequential( |
| 62 | torch.nn.Linear(in_features=512,out_features=256), |
| 63 | torch.nn.BatchNorm1d(num_features=256), |
| 64 | torch.nn.LeakyReLU(negative_slope=0.2,inplace=True) |
| 65 | ) |
| 66 | self.fc_final_layer = torch.nn.Sequential( |
| 67 | torch.nn.Linear(in_features=256, out_features=1), |
| 68 | torch.nn.Sigmoid() |
| 69 | ) |
| 70 | |
| 71 | def forward(self,input,label): |
| 72 | x = self.fc_layer_1(input.view(input.size(0),-1)) |
| 73 | y = self.fc_layer_2(label) |
| 74 | x = torch.cat([x,y],dim = 1) |
| 75 | x = self.fc_layer_3(x) |
| 76 | x = self.fc_layer_4(x) |
| 77 | out = self.fc_final_layer(x) |
| 78 | return out |
| 79 | |
| 80 | |
| 81 | def weights_init_normal(m): |