import torch import torch.nn as nn class Discriminator(nn.Module): def __init__(self, input_nc, norm_layer=nn.BatchNorm2d, use_sigmoid=False): super(Discriminator, self).__init__() kw = 4 padw = 1 self.down1 = nn.Sequential( nn.Conv2d(input_nc, 64, kernel_size=kw, stride=2, padding=padw), norm_layer(64), nn.LeakyReLU(0.2, True) ) self.down2 = nn.Sequential( nn.Conv2d(64, 128, kernel_size=kw, stride=2, padding=padw), norm_layer(128), nn.LeakyReLU(0.2, True) ) self.down3 = nn.Sequential( nn.Conv2d(128, 256, kernel_size=kw, stride=2, padding=padw), norm_layer(256), nn.LeakyReLU(0.2, True) ) self.down4 = nn.Sequential( nn.Conv2d(256, 512, kernel_size=kw, stride=2, padding=padw), norm_layer(512), nn.LeakyReLU(0.2, True) ) self.down5 = nn.Sequential( nn.Conv2d(512, 512, kernel_size=kw, stride=2, padding=padw), norm_layer(512), nn.LeakyReLU(0.2, True) ) self.conv1 = nn.Sequential( nn.Conv2d(512, 512, kernel_size=kw, stride=1, padding=padw), norm_layer(512), nn.LeakyReLU(0.2, True) ) if use_sigmoid: self.conv2 = nn.Sequential( nn.Conv2d(512, 1, kernel_size=kw, stride=1, padding=padw), nn.Sigmoid() ) else: self.conv2 = nn.Sequential( nn.Conv2d(512, 1, kernel_size=kw, stride=1, padding=padw) ) def forward(self, input): out = [] x = self.down1(input) #out.append(x) x = self.down2(x) #out.append(x) x = self.down3(x) #out.append(x) x = self.down4(x) x = self.down5(x) out.append(x) x = self.conv1(x) out.append(x) x = self.conv2(x) out.append(x) return out