训练的CGAN,采用cifar10数据集,经过20次训练后已经能出现图像,但是图像不清晰,而且图像看不出是什么东西。
如图所示,请问是训练次数不够还是说训练方法有错?
这是生成器和判别器的代码
class DCDiscriminator(nn.Module)
https://img-mid.csdnimg.cn/release/static/image/mid/ask/855452777176119.png "#left")
def __init__(self)
super(DCDiscriminator, self).__init__()
self.dis=nn.Sequential(
nn.Conv2d(3+10,64,4,2,1,bias=False),
nn.LeakyReLU(0.2,inplace=True),
nn.Conv2d(64,64*2,4,2,1,bias=False),
nn.BatchNorm2d(64 * 2),
nn.LeakyReLU(0.2, inplace=True),
nn.Conv2d(64 * 2, 64 * 4, 4, 2, 1, bias=False),
nn.BatchNorm2d(64 * 4),
nn.LeakyReLU(0.2, inplace=True),
nn.Conv2d(64 * 4, 64 * 8, 4, 2, 1, bias=False),
nn.BatchNorm2d(64 * 8),
nn.LeakyReLU(0.2, inplace=True),
nn.Conv2d(64 * 8, 1, 4, 1, 0, bias=False),
nn.Sigmoid()
)
def forward(self, x)
return self.dis(x).view(-1, 1).squeeze(1)
class DCGenerator(nn.Module)
def __init__(self)
super(DCGenerator, self).__init__()
self.gen=nn.Sequential(
nn.ConvTranspose2d(100+10, 64 * 8, 4, 1, 0, bias=False),
nn.BatchNorm2d(64 * 8),
nn.ReLU(True),
# state size. (ngf*8) x 4 x 4
nn.ConvTranspose2d(64 * 8, 64 * 4, 4, 2, 1, bias=False),
nn.BatchNorm2d(64 * 4),
nn.ReLU(True),
nn.ConvTranspose2d(64 * 4, 64 * 2, 4, 2, 1, bias=False),
nn.BatchNorm2d(64 * 2),
nn.ReLU(True),
nn.ConvTranspose2d(64 * 2, 64, 4, 2, 1, bias=False),
nn.BatchNorm2d(64),
nn.ReLU(True),
nn.ConvTranspose2d(64, 3, 4, 2, 1, bias=False),
nn.Tanh()
)
def forward(self,x)
return self.gen(x)
batch_size=128,learning_rate=0.0002