tensorflowkerasneural-networkmnistdcgan

What's the difference between keras.datasets.mnist and tensorflow.examples.tutorials.mnist?


I am analysing this DCGAN. When I use input_data from tensorflow.examples.tutorials.mnist, as seen in line 144:

self.x_train = input_data.read_data_sets("mnist",\
        one_hot=True).train.images

I obtain reasonably good results: enter image description here Though when I use mnist from keras.datasets and the 144th line looks like this:

(xtr, ytr), (xte, yte) = mnist.load_data();
    self.x_train = xtr

I get horribly bad results: enter image description here I have checked manually a few images from both datasets and they are quite similar.

So what is the difference between keras.datasets.mnist and tensorflow.examples.tutorials.mnist? Why are the resulting images so different? What am I doing wrong with keras.datasets.mnist?


Solution

  • It is very likely that the images in tensorflow.examples.tutorials.mnist have been normalized to the range [0, 1] and therefore you obtain better results. Whereas, the values in MNIST dataset in Keras are in the range [0, 255] and you are expected to normalize them (if needed, of course). Try this:

    (xtr, ytr), (xte, yte) = mnist.load_data()
    xtr = xtr.astype('float32') / 255.0
    xte = xte.astype('float32') / 255.0