I took a look at your model. It seems you have incorrect architecture. The Conv2D
layers in your D should have following params: (n_filters, kernel=3, padding='same')
, where n_filters
is the number of filters and it usually should be doubled as per DCGAN architecture. You can also use strides
but since your images are small it won't make any sense.
The D network also should not include UpSampling2D
layer. This layer can be used in G network instead of Conv2DTranspose
.
Your images should be normalized to the range of [-1, 1]
and the activation function of G should be tanh
.
You also included m.add(keras.layers.Reshape((8, 8, 3)))
to your G network which is the final size of your data. Since you have the final size in the first layers you don't have to include upsampling Conv2DTranspose
layers.
Your final model should look like
def make_discriminator_model():
model = tf.keras.Sequential()
model.add(layers.Conv2D(8, kernel=3, strides=1, padding='same',
input_shape=[8, 8, 1]))
model.add(layers.LeakyReLU())
model.add(layers.Dropout(0.3))
model.add(layers.Conv2D(16, kernel=3, strides=1, padding='same'))
model.add(layers.LeakyReLU())
model.add(layers.Dropout(0.3))
model.add(layers.Flatten())
model.add(layers.Dense(1))
return model
def make_generator_model():
model = tf.keras.Sequential()
model.add(layers.Dense(8*8*16, use_bias=False, input_shape=(100,)))
model.add(layers.BatchNormalization())
model.add(layers.LeakyReLU())
model.add(layers.Reshape((8, 8, 16)))
model.add(layers.Conv2D(8, kernel=3, strides=1, padding='same'))
model.add(layers.BatchNormalization())
model.add(layers.LeakyReLU())
model.add(layers.Conv2D(1, kernel=3, strides=1, padding='same', activation='tanh'))
return model
Note that I did not test the model, so you should adapt it to the shape of your data.
I encourage you to follow this tutorial.
Update regarding overfitting
GANs do not have overfitting problem in the classical sense. Instead, vanilla GAN have other problems like vanishing gradient. It happens when the D becomes overconfident regarding fake samples. In that case, D stops providing useful information to the G, since its error becomes 0. To find out if training fell into this problem, you should plot D and G loss. It will look as follows:
Another problem is the mode collapse. In that case, the G tricks the D by producing only one type of samples which looks realistic but G won't represent the real data distribution. Therefore, the generated samples will be homogeneous.
For more information, see Improved Techniques for Training GANs and Wasserstein GAN.
1.0
. Next, I feed fake images (the one that is generated by the generator) into the discriminator model, and it outputs values close to0.5
. These happens too often, and it is very predictable. $\endgroup$