GANs-in-Action / gans-in-action

Companion repository to GANs in Action: Deep learning with Generative Adversarial Networks
1.01k stars 420 forks source link

Poor DCGAN (chapter 5) performance when upgrading from keras to tf.keras #14

Open FaizSayyid opened 3 years ago

FaizSayyid commented 3 years ago

I'm trying to run the DCGAN from chapter 5; the code performs well and the generated images are good.

But when I change the source code so that it becomes compatible with tf.keras rather than keras, the model produces useless images that are obviously just noise

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()

but performance remains poor. Any ideas?

Nevermetyou65 commented 2 years ago

I faced this too and there is really no answer anywhere but I found that there is a tutorial in tensorflow website.

https://www.tensorflow.org/tutorials/generative/dcgan