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

左心房为你撑大大i 提交于 2019-12-11 06:06:02

问题


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: 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: 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?


回答1:


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


来源:https://stackoverflow.com/questions/53986848/whats-the-difference-between-keras-datasets-mnist-and-tensorflow-examples-tutor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!