Deep Generative Image Models using a Laplacian Pyramid of Adversarial Networks
lass GeneratorTop(nn.Module):
def __init__(self, z_dim=100, out_width=8):
super().__init__()
self.out_width = out_width
self.layers = nn.Sequential(nn.Linear(z_dim, z_dim*10),
nn.Linear(z_dim*10, z_dim*20),
nn.Linear(z_dim*20, self.out_width*self.out_width*3))
def forward(self, x):
return self.layers(x).view(-1, self.out_width, self.out_width, 3)
class G2(nn.Module):
def __init__(self, in_dim=4, out_width=16):
super().__init__()
self.layers = nn.Sequential(nn.Conv2d(in_dim, 128, 3, 1, 1),
nn.ReLU(),
nn.Conv2d(128, 128, 3, 1, 1),
nn.ReLU(),
nn.Conv2d(128, 3, 3, 1, 1))
def forward(self, x):
return self.layers(x)
class D2(nn.Module):
def __init__(self, in_dim=3, in_width=16):
super().__init__()
self.front_layers = nn.Sequential(nn.Conv2d(in_dim, 128, 3, 2, 1),
nn.ReLU(),
nn.Conv2d(128, 128, 3, 2, 1),
nn.ReLU())
# 卷积以后的特征图长宽
current_width = int(in_width/4)
# 定义最后用于分类的全连接层
self.last_layer = nn.Linear(128*current_width*current_width, 1)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
temp = self.front_layers(x)
# 全连接层的输入需要是2D的
temp = temp.view(temp.size(0), -1)
out = self.sigmoid(self.last_layer(temp))
return out