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