| 28 | return x |
| 29 | |
| 30 | class Generator(torch.nn.Module): |
| 31 | def __init__(self,in_channles=3,features=64): |
| 32 | super(Generator, self).__init__() |
| 33 | self.initial_down = torch.nn.Sequential( |
| 34 | torch.nn.Conv2d(in_channels=in_channles,out_channels=features,kernel_size=(4,4), |
| 35 | stride=(2,2),padding=(1,1),padding_mode='reflect'), |
| 36 | torch.nn.LeakyReLU(negative_slope=0.2) |
| 37 | ) |
| 38 | self.down1 = Block(in_channels=features,out_channels=features*2,down=True,act='leaky',use_dropout=False) |
| 39 | self.down2 = Block(in_channels=features*2, out_channels=features * 4, down=True, act='leaky', use_dropout=False) |
| 40 | self.down3 = Block(in_channels=features*4, out_channels=features * 8, down=True, act='leaky', use_dropout=False) |
| 41 | self.down4 = Block(in_channels=features*8, out_channels=features * 8, down=True, act='leaky', use_dropout=False) |
| 42 | self.down5 = Block(in_channels=features*8, out_channels=features * 8, down=True, act='leaky', use_dropout=False) |
| 43 | self.down6 = Block(in_channels=features*8, out_channels=features * 8, down=True, act='leaky', use_dropout=False) |
| 44 | |
| 45 | self.bottleneck = torch.nn.Sequential( |
| 46 | torch.nn.Conv2d(in_channels=features*8,out_channels=features*8,kernel_size=(4,4), |
| 47 | stride=(2,2),padding=(1,1),padding_mode='reflect'), |
| 48 | torch.nn.ReLU() |
| 49 | ) |
| 50 | |
| 51 | self.up1 = Block(in_channels=features*8,out_channels=features*8,down=False,act="relu",use_dropout=True) |
| 52 | self.up2 = Block(in_channels=features * 8*2, out_channels=features * 8, down=False, act="relu", use_dropout=True) |
| 53 | self.up3 = Block(in_channels=features * 8*2, out_channels=features * 8, down=False, act="relu", use_dropout=True) |
| 54 | self.up4 = Block(in_channels=features * 8*2, out_channels=features * 8, down=False, act="relu", use_dropout=False) |
| 55 | self.up5 = Block(in_channels=features * 8*2, out_channels=features * 4, down=False, act="relu", use_dropout=False) |
| 56 | self.up6 = Block(in_channels=features * 4*2, out_channels=features * 2, down=False, act="relu", use_dropout=False) |
| 57 | self.up7 = Block(in_channels=features * 2*2, out_channels=features , down=False, act="relu", use_dropout=False) |
| 58 | |
| 59 | self.final_up = torch.nn.Sequential( |
| 60 | torch.nn.ConvTranspose2d(in_channels=features*2,out_channels=in_channles,kernel_size=(4,4), |
| 61 | stride=(2,2),padding=(1,1)), |
| 62 | torch.nn.Tanh() |
| 63 | ) |
| 64 | def forward(self,x): |
| 65 | d1 = self.initial_down(x) |
| 66 | d2 = self.down1(d1) |
| 67 | d3 = self.down2(d2) |
| 68 | d4 = self.down3(d3) |
| 69 | d5 = self.down4(d4) |
| 70 | d6 = self.down5(d5) |
| 71 | d7 = self.down6(d6) |
| 72 | |
| 73 | bottleneck = self.bottleneck(d7) |
| 74 | |
| 75 | u1 = self.up1(bottleneck) |
| 76 | u2 = self.up2(torch.cat([u1,d7],dim=1)) |
| 77 | u3 = self.up3(torch.cat([u2,d6],dim=1)) |
| 78 | u4 = self.up4(torch.cat([u3,d5],dim=1)) |
| 79 | u5 = self.up5(torch.cat([u4,d4],dim=1)) |
| 80 | u6 = self.up6(torch.cat([u5,d3],dim=1)) |
| 81 | u7 = self.up7(torch.cat([u6,d2],dim=1)) |
| 82 | |
| 83 | final_up = self.final_up(torch.cat([u7,d1],dim=1)) |
| 84 | return final_up |
| 85 | |
| 86 | |
| 87 | if __name__ == '__main__': |
no outgoing calls
no test coverage detected