本文介绍了keras.datasets.mnist和tensorflow.examples.tutorials.mnist有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在分析此DCGAN .当我使用tensorflow.examples.tutorials.mnist中的input_data时,如第144行:

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

我获得了相当不错的成绩:虽然当我使用keras.datasets中的mnist并且第144行看起来像这样:

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.

那么keras.datasets.mnisttensorflow.examples.tutorials.mnist有什么区别?为什么生成的图像如此不同? keras.datasets.mnist我怎么了?

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?

推荐答案

tensorflow.examples.tutorials.mnist中的图像很可能已被归一化为[0,1]范围,因此可以获得更好的结果.而Keras中MNIST数据集中的值在[0,255]范围内,并且您需要对其进行归一化(当然,如果需要).试试这个:

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

这篇关于keras.datasets.mnist和tensorflow.examples.tutorials.mnist有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 21:28