问题描述:
【功能模块】
我想实现一个GAN相关网络,但目前的问题是Discriminator初始时每经过一层卷积,图像像素值会小一个数量级,经过多层卷积后,像素值会无限解禁0,再去进行sigmoid运算得到0.5,也就说无论什么图片进入Dsicriminator评分都是0.5,导致整个网络无法训练。请问遇到这种问题应该以什么样的思路解决呢?
【操作步骤&问题现象】
图片大小[64,3,88,88]
网络结构
class Discriminator(nn.Cell):
def __init__(self):
super(Discriminator, self).__init__()
self.net = nn.SequentialCell(
nn.Conv2d(3, 64, kernel_size=3, padding=1,pad_mode='pad'),
nn.LeakyReLU(0.2),
nn.Conv2d(64, 64, kernel_size=3, stride=2, padding=1,pad_mode='pad'),
nn.BatchNorm2d(64,1e-05, momentum=0.1),
nn.LeakyReLU(0.2),
nn.Conv2d(64, 128, kernel_size=3, padding=1,pad_mode='pad'),
nn.BatchNorm2d(128,eps=1e-05, momentum=0.1),
nn.LeakyReLU(0.2),
nn.Conv2d(128, 128, kernel_size=3, stride=2, padding=1,pad_mode='pad'),
nn.BatchNorm2d(128,eps=1e-05, momentum=0.1),
nn.LeakyReLU(0.2),
nn.Conv2d(128, 256, kernel_size=3, padding=1,pad_mode='pad'),
nn.BatchNorm2d(256,eps=1e-05, momentum=0.1),
nn.LeakyReLU(0.2),
nn.Conv2d(256, 256, kernel_size=3, stride=2, padding=1,pad_mode='pad'),
nn.BatchNorm2d(256,eps=1e-05, momentum=0.1),
nn.LeakyReLU(0.2),
nn.Conv2d(256, 512, kernel_size=3, padding=1,pad_mode='pad'),
nn.BatchNorm2d(512,eps=1e-05, momentum=0.1),
nn.LeakyReLU(0.2),
nn.Conv2d(512, 512, kernel_size=3, stride=2, padding=1,pad_mode='pad'),
nn.BatchNorm2d(512,eps=1e-05, momentum=0.1),
nn.LeakyReLU(0.2),
nn.AvgPool2d(kernel_size=6, stride=1),
nn.Conv2d(512, 1024, kernel_size=1),
nn.LeakyReLU(0.2),
nn.Conv2d(1024, 1, kernel_size=1)
)
def construct(self, x):
y=self.net(x)
batch_size = x.shape[0]
sigmoid = nn.Sigmoid()
output=sigmoid(y.view(batch_size))
return output
输出:0.5
【截图信息】
【日志信息】(可选,上传日志内容或者附件)
解决方案:
增大输入图像size
减少判别器下采样次数或者Conv2d的stride>1次数,