我正在使用tensorflow导入一些MNIST输入数据。我跟着这个教程... https://www.tensorflow.org/get_started/mnist/beginners使用matplotlib显示MNIST图像
我导入它们作为如此...
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
我希望能够从训练集显示任何图像。我知道图像的位置是mnist.train.images
,所以我尝试访问的第一个图像,并像这样显示它...
with tf.Session() as sess:
#access first image
first_image = mnist.train.images[0]
first_image = np.array(first_image, dtype='uint8')
pixels = first_image.reshape((28, 28))
plt.imshow(pixels, cmap='gray')
我一个试图将图像转换为28 28 numpy的阵列,因为我知道每个图像是28乘28像素。
然而,当我运行代码我得到的是以下...
显然,我做错了什么。当我打印矩阵时,一切似乎都很好,但我认为我错误地重塑了它。
的可能的复制的完整代码[TensorFlow - 从数据集MNIST显示图像](https://stackoverflow.com/questions/38308378/tensorflow-show-image -from-mnist-dataset) –