GAN 在几个时期内收敛

Posted

技术标签:

【中文标题】GAN 在几个时期内收敛【英文标题】:GAN Converges in Just a Few Epochs 【发布时间】:2017-06-11 23:04:57 【问题描述】:

我在 Keras 中实现了一个生成对抗网络。我的训练数据大小约为 16,000,其中每张图像的大小为 32*32。我所有的训练图像都是来自 imagenet 数据集的图像在对象检测任务方面的调整大小版本。我将图像矩阵直接输入到网络中,而不进行中心裁剪。我使用了 AdamOptimizer,学习率为 1e-4,beta1 为 0.5,我还将 dropout 率设置为 0.1。我首先在 3000 张真实图像和 3000 张假图像上训练了判别器,它达到了 93% 的准确率。然后,我训练了 500 个 epoch,批量大小为 32。但是,我的模型似乎只在几个 epoch(

Plot of the Loss Function

Random Samples Generated by the Generator

我想知道我的训练数据集是否太小(与 DCGAN 论文中的那些超过 300,000 相比)或我的模型配置不正确。更重要的是,我是否应该按照 Ian Goodfellow 在原始论文中的建议在 D 上训练 SGD 进行 k 次迭代(其中 k 很小,可能是 1),然后在 G 上使用 SGD 进行一次迭代训练?(我刚刚尝试训练他们一次一个)

下面是生成器的配置。

g_input = Input(shape=[100])
H = Dense(1024*4*4, init='glorot_normal')(g_input)
H = BatchNormalization(mode=2)(H)
H = Activation('relu')(H)
H = Reshape( [4, 4,1024] )(H)
H = UpSampling2D(size=( 2, 2))(H)
H = Convolution2D(512, 3, 3, border_mode='same', init='glorot_uniform')(H)
H = BatchNormalization(mode=2)(H)
H = Activation('relu')(H)
H = UpSampling2D(size=( 2, 2))(H)
H = Convolution2D(256, 3, 3, border_mode='same', init='glorot_uniform')(H)
H = BatchNormalization(mode=2)(H)
H = Activation('relu')(H)
H = UpSampling2D(size=( 2, 2))(H)
H = Convolution2D(3, 3, 3, border_mode='same', init='glorot_uniform')(H)
g_V = Activation('tanh')(H)
generator = Model(g_input,g_V)
generator.compile(loss='binary_crossentropy', optimizer=opt)
generator.summary()

下面是判别器的配置:

d_input = Input(shape=shp)
H = Convolution2D(64, 5, 5, subsample=(2, 2), border_mode = 'same', init='glorot_normal')(d_input)
H = LeakyReLU(0.2)(H)
#H = Dropout(dropout_rate)(H)
H = Convolution2D(128, 5, 5, subsample=(2, 2), border_mode = 'same', init='glorot_normal')(H)
H = BatchNormalization(mode=2)(H)
H = LeakyReLU(0.2)(H)
#H = Dropout(dropout_rate)(H)
H = Flatten()(H)
H = Dense(256, init='glorot_normal')(H)
H = LeakyReLU(0.2)(H)
d_V = Dense(2,activation='softmax')(H)
discriminator = Model(d_input,d_V)
discriminator.compile(loss='categorical_crossentropy', optimizer=dopt)
discriminator.summary()

下面是GAN的整体配置:

gan_input = Input(shape=[100])
H = generator(gan_input)
gan_V = discriminator(H)
GAN = Model(gan_input, gan_V)
GAN.compile(loss='categorical_crossentropy', optimizer=opt)
GAN.summary()

【问题讨论】:

【参考方案1】:

我认为问题出在loss 函数上 试试

loss='categorical_crossentropy',

【讨论】:

您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center。【参考方案2】:

我怀疑你的生成器在你训练 gan 时是可训练的。可以通过generator.layers[-1].get_weights()进行验证,看看gan训练过程中参数是否发生变化。

您应该在将鉴别器组装到 gan 之前冻结它:

generator.trainnable = False
gan_input = Input(shape=[100])
H = generator(gan_input)
gan_V = discriminator(H)
GAN = Model(gan_input, gan_V)
GAN.compile(loss='categorical_crossentropy', optimizer=opt)
GAN.summary()

请参阅此讨论: https://github.com/fchollet/keras/issues/4674

【讨论】:

以上是关于GAN 在几个时期内收敛的主要内容,如果未能解决你的问题,请参考以下文章

GAN没有收敛。判别者损失不断增加

Azure Web 应用服务在几个小时内变得不可用

MongoDB - 在几个小时的时间范围内查询

是否有可能在几个时代内过度填充250,000个例子?

在多标签图像分类任务中,哪个损失函数会收敛得很好?

Kafka 连接器记录写入器因缺少要分配的内存而卡在 S3OutputStream 中,但在几个小时内保持空闲状态并没有失败