如上两张图所示,在训练一个DCGAN模型时,梯度不稳定,波动很大。由于这个原因,模型无法绘制出完美的图像,甚至无法绘制出人眼可以识别的图像。有人能告诉我如何调整诸如 dropout 率或学习率之类的参数以使模型运行得更好吗?我将非常感谢你!这是我之前制作的模型(使用 Keras 构建):
鉴别器:
学习率为 0.0005
辍学率为0.6
batch_size 是 25
dis=Sequential()
dis.add(Conv2D(depth*1, 5, strides=2, input_shape=(56,56,3),padding='same',kernel_initializer='RandomNormal', bias_initializer='zeros'))
dis.add(LeakyReLU(alpha=alp))
dis.add(Dropout(dropout))
dis.add(Conv2D(depth*2, 5, strides=2, padding='same',kernel_initializer='RandomNormal', bias_initializer='zeros'))
dis.add(LeakyReLU(alpha=alp))
dis.add(Dropout(dropout))
dis.add(Conv2D(depth*4, 5, strides=2, padding='same',kernel_initializer='RandomNormal', bias_initializer='zeros'))
dis.add(LeakyReLU(alpha=alp))
dis.add(Dropout(dropout))
dis.add(Conv2D(depth*8,5,strides=1,padding='same',kernel_initializer='RandomUniform', bias_initializer='zeros'))
dis.add(LeakyReLU(alpha=alp))
dis.add(Dropout(dropout))
dis.add(Flatten())
dis.add(Dense(1))
dis.add(Activation('sigmoid'))
dis.summary()
dis.compile(loss='binary_crossentropy',optimizer=RMSprop(lr=d_lr))
生成器和 GAN 模型:
学习率为 0.0001
动量为 0.9
gen=Sequential()
gen.add(Dense(dim*dim*dep,input_dim=100))
gen.add(BatchNormalization(momentum=momentum))
gen.add(Activation('relu'))
gen.add(Reshape((dim,dim,dep)))
gen.add(Dropout(dropout))
gen.add(UpSampling2D())
gen.add(Conv2DTranspose(int(dep/2),5,padding='same',kernel_initializer='RandomNormal', bias_initializer='RandomNormal'))
gen.add(BatchNormalization(momentum=momentum))
gen.add(Activation('relu'))
gen.add(UpSampling2D())
gen.add(Conv2DTranspose(int(dep/4),5,padding='same',kernel_initializer='RandomNormal', bias_initializer='RandomNormal'))
gen.add(BatchNormalization(momentum=momentum))
gen.add(Activation('relu'))
gen.add(UpSampling2D())
gen.add(Conv2DTranspose(int(dep/8),5,padding='same',kernel_initializer='RandomNormal', bias_initializer='RandomNormal'))
gen.add(BatchNormalization(momentum=momentum))
gen.add(Activation('relu'))
gen.add(Conv2DTranspose(3,5,padding='same',kernel_initializer='RandomNormal', bias_initializer='RandomNormal'))
gen.add(Activation('sigmoid'))
gen.summary()
GAN=Sequential()
GAN.add(gen)
GAN.add(dis)
GAN.compile(loss='binary_crossentropy',optimizer=RMSprop(lr=g_lr))