我在Keras中实现了一个通用的对抗网络。我的训练数据大小约为16,000,其中每个图像的大小为32*32。我的所有训练图像都是imagenet数据集中关于对象检测任务的图像的调整大小版本。我直接将图像矩阵输入网络,而不进行中心裁剪。我使用学习率为1e-4的AdamOptimizer,beta1为0.5,我还将dropout rate设置为0.1。我首先在3000张真实图像和3000张假图像上训练描述者,它达到了93%的准确率。然后,我训练了500个时期,批处理大小为32。然而,我的模型似乎只在几个时期内收敛(<10),并且它生成的图像很难看。
Random Samples Generated by the Generator
我想知道我的训练数据集是否太小(与DCGAN论文中的数据相比,超过300,000),或者我的模型配置不正确。更重要的是,我是不是应该像伊恩·古德费罗在原始论文中建议的那样,在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()发布于 2021-12-25 01:40:29
我认为问题出在loss函数Try上
loss='categorical_crossentropy',发布于 2017-09-19 20:54:21
我怀疑你的发电机在你训练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://stackoverflow.com/questions/41874096
复制相似问题