| 9 | from torchinfo import summary |
| 10 | |
| 11 | class Block(torch.nn.Module): |
| 12 | def __init__(self,in_channels, out_channels, down=True, act="relu", use_dropout=False): |
| 13 | super(Block, self).__init__() |
| 14 | self.conv = torch.nn.Sequential( |
| 15 | torch.nn.Conv2d(in_channels=in_channels,out_channels=out_channels,kernel_size=(4,4), |
| 16 | stride=(2,2),padding=(1,1),bias=False,padding_mode='reflect') |
| 17 | if down |
| 18 | else torch.nn.ConvTranspose2d(in_channels=in_channels,out_channels=out_channels, |
| 19 | kernel_size=(4,4),stride=(2,2),padding=(1,1),bias=False), |
| 20 | torch.nn.BatchNorm2d(num_features=out_channels), |
| 21 | torch.nn.ReLU() if act == "relu" else torch.nn.LeakyReLU(negative_slope=0.2) |
| 22 | ) |
| 23 | self.use_dropout = use_dropout |
| 24 | self.dropout = torch.nn.Dropout(p=0.5) |
| 25 | def forward(self,x): |
| 26 | x = self.conv(x) |
| 27 | x = self.dropout(x) if self.use_dropout else x |
| 28 | return x |
| 29 | |
| 30 | class Generator(torch.nn.Module): |
| 31 | def __init__(self,in_channles=3,features=64): |