ElitesAI·动手学深度学习PyTorch版(第四次打卡Task10)

GANs(Generativeadversarial networks,对抗式生成网络)

Generative adversarial networks (GANs) composes of two deep networks, the generator and the discriminator.
The generator generates the image as much closer to the true image as possible to fool the discriminator, via maximizing the cross-entropy loss, i.e., maxlog⁡(D(x′)).
The discriminator tries to distinguish the generated images from the true images, via minimizing the cross-entropy loss, i.e., min−ylog⁡D(x)−(1−y)log⁡(1−D(x)).

对抗式生成网络由Generator和Discriminator两个深度网络组成:
生成器(Generator ):生成器努力使生成的图像更加真实,通过让交叉熵损失函数如log⁡(D(x′))最大,以骗过判别器。。
判别器(Discriminator) :判别器则需要努力对图片进行真假判别,通过让交叉熵损失函数如−ylog⁡D(x)−(1−y)log⁡(1−D(x))最小,以识别出真假。

生成器(Generator )

class net_G(nn.Module):
def init(self):
super(net_G,self).init()
self.model=nn.Sequential(
nn.Linear(2,2),
)
self.initialize_weights()
def forward(self,x):
x=self.model(x)
return x
def initialize_weights(self):
for m in self.modules():
if isinstance(m,nn.Linear):
m.weight.data.normal
(0,0.02)
m.bias.data.zero
()

判别器(Discriminator)

class net_D(nn.Module):
def init(self):
super(net_D,self).init()
self.model=nn.Sequential(
nn.Linear(2,5),
nn.Tanh(),
nn.Linear(5,3),
nn.Tanh(),
nn.Linear(3,1),
nn.Sigmoid()
)
self.initialize_weights()
def forward(self,x):
x=self.model(x)
return x
def initialize_weights(self):
for m in self.modules():
if isinstance(m,nn.Linear):
m.weight.data.normal
(0,0.02)
m.bias.data.zero
()

DCGANs(Deep Convolutional Generative Adversarial Networks深层卷积生成性对抗网络)

DCGAN architecture has four convolutional layers for the Discriminator and four “fractionally-strided” convolutional layers for the Generator.
The Discriminator is a 4-layer strided convolutions with batch normalization (except its input layer) and leaky ReLU activations.
Leaky ReLU is a nonlinear function that give a non-zero output for a negative input. It aims to fix the “dying ReLU” problem and helps the gradients flow easier through the architecture.

深层卷积生成性对抗网络中的生成器Generator具有四层卷积,;识别器Discriminator具有四层fractionally-strided 卷积层,其中使用了小批量归一化和leaky ReLU激活函数。

模型结构

模型结构上:

将pooling层convolutions替代,其中,在discriminator上用strided convolutions替代,在generator上用fractional-strided convolutions替代。
在generator和discriminator上都使用batchnorm。
解决初始化差的问题
帮助梯度传播到每一层
防止generator把所有的样本都收敛到同一个点。
直接将BN应用到所有层会导致样本震荡和模型不稳定,通过在generator输出层和discriminator输入层不采用BN可以防止这种现象。
移除全连接层
global pooling增加了模型的稳定性,但伤害了收敛速度。
在generator的除了输出层外的所有层使用ReLU,输出层采用tanh。
在discriminator的所有层上使用LeakyReLU。

DCGAN的generator网络结构:

在这里插入图片描述
其中,这里的conv层是four fractionally-strided convolution,在其他的paper中也可能被称为是deconvolution

图像分类案例2

这部分比较熟悉,就不做总结笔记了。

发布了5 篇原创文章 · 获赞 0 · 访问量 270

猜你喜欢

转载自blog.csdn.net/qingxiuhu/article/details/104505576