Update 1: When removing the batch normalisation layers it works well. Apparently the way batch normalisation works was changed between iterations. Still investigating.
Update 2: Questions below report two possible remedies; changing the momentum value in batchnormalisation (this didn't work for me) and simply commenting out the batchnorm in the discriminator. Commenting out BN in the discriminator seems to work for me. No idea why yet.
Questions/links reporting similar problems:
Poor Result with BatchNormalization
https://datascience.stackexchange.com/questions/56860/dc-gan-with-batch-normalization-not-working
Keras train partial model issue (about GAN model)
Question Starts:
I'm trying to run a DCGAN from "GANs in Action". The GAN generates images from the MNIST dataset.
The source code can be found here GANs in action github page
The code performs well and the generated images are good.
When I change the source code so that it becomes compatible with tf.keras
rather than keras
, the DCGAN model's ability to generate images becomes useless.
The following is the only bit of the code I've changed. From:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from keras.datasets import mnist
from keras.layers import Activation, BatchNormalization, Dense, Dropout, Flatten, Reshape
from keras.layers import LeakyReLU
from keras.layers import Conv2D, Conv2DTranspose
from keras.models import Sequential
from keras.optimizers import Adam
to:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from tensorflow.keras.datasets import mnist
from tensorflow.keras.layers import Activation, BatchNormalization, Dense, Dropout, Flatten, Reshape
from tensorflow.keras.layers import LeakyReLU
from tensorflow.keras.layers import Conv2D, Conv2DTranspose
from tensorflow.keras.models import Sequential
from tensorflow.keras.optimizers import Adam
I've even tried to enforce tf_1 compatability with
tf.compat.v1.disable_v2_behavior()
-performance remains poor.
Why is this? Have I missed something obvious?